This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » PHP » Php script problem
Reply

Php script problem

Imtiaz Ahmed Ratul
Member



Since: 07 Jan 2010
Posts: 1
Posted 07 Jan 2010 15:36:13

Hello everyone,

I have a php script. Here it is:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
error_reporting(0);
//Database Information

$dbhost = "localhost";
$dbname = "badbook";
$dbuser = "root";
$dbpass = "";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$batch = $_POST['batch'];
$city = $_POST['city'];
$org = $_POST['org'];
$username = $_POST['username'];
$password = md5($_POST['password']);


// lets check to see if the username already exists

$checkuser = mysql_query("SELECT username FROM badbook WHERE username='$username'";

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
unset($username);
include 'registration.html';
exit();
}

// lf no errors present with the username
// use a query to insert the data into the database.

$query = "INSERT INTO badbook (name, email, phone, batch, city, org, username, password)
VALUES('$name', '$email', '$phone', '$batch', '$city', '$org', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "You have successfully Registered";


?>
</body>
</html>




The problem is, when I press the submit button in the other html page, this php page doesn't load; instead, it shows an error message. I get this message when I don't have internet connection, however, it is showing now with a local server running. The data entered gets in the mysql database, but the page returns this.

The reason why I'm using error_reporting(0); is because otherwise, when i reload the page with the warning it shows :
Notice: Undefined Index: "variablename" in ../../..php in line 22

Please help me with this.

Thanks


THE SCREEN WRITINGS:
Connection closed by the remote server

You tried to access the address localhost/www.badbook.com/registration.php, which is currently unavailable. Please make sure that the Web address (URL) is correctly spelled and punctuated, then try reloading the page.
Make sure your Internet connection is active and check whether other applications that rely on the same connection are working.

Hello everyone,

I have a php script. Here it is:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
error_reporting(0);
//Database Information

$dbhost = "localhost";
$dbname = "badbook";
$dbuser = "root";
$dbpass = "";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$batch = $_POST['batch'];
$city = $_POST['city'];
$org = $_POST['org'];
$username = $_POST['username'];
$password = md5($_POST['password']);


// lets check to see if the username already exists

$checkuser = mysql_query("SELECT username FROM badbook WHERE username='$username'";

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
unset($username);
include 'registration.html';
exit();
}

// lf no errors present with the username
// use a query to insert the data into the database.

$query = "INSERT INTO badbook (name, email, phone, batch, city, org, username, password)
VALUES('$name', '$email', '$phone', '$batch', '$city', '$org', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "You have successfully Registered";


?>
</body>
</html>




The problem is, when I press the submit button in the other html page, this php page doesn't load; instead, it shows an error message. I get this message when I don't have internet connection, however, it is showing now with a local server running. The data entered gets in the mysql database, but the page returns this.

The reason why I'm using error_reporting(0); is because otherwise, when i reload the page with the warning it shows :
Notice: Undefined Index: "variablename" in ../../..php in line 22

Please help me with this.

Thanks


THE SCREEN WRITINGS:
Connection closed by the remote server

You tried to access the address localhost/www.badbook.com/registration.php, which is currently unavailable. Please make sure that the Web address (URL) is correctly spelled and punctuated, then try reloading the page.
Make sure your Internet connection is active and check whether other applications that rely on the same connection are working.
John Pels***
Member



Since: 28 Jan 2003
Posts: 3
Replied 31 May 2010 21:42:28
I am guessing your unconventional use of the include is the culprit. You might try this.

include($_SERVER['DOCUMENT_ROOT']."/registration.html";



Edited by - John Mr. on 31 May 2010  21:44:35
guru murthy
Member



Since: 25 Oct 2010
Posts: 1
Replied 25 Oct 2010 09:34:14
Hi,

You better to use isset(), then you wont get this type of errors.

Gurumurthy

Reply to this topic

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency