Forums

PHP

This topic is locked

Php script problem

Posted 07 Jan 2010 15:36:13
1
has voted
07 Jan 2010 15:36:13 Imtiaz Ahmed Ratul posted:
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.

Replies

Replied 31 May 2010 21:42:28
31 May 2010 21:42:28 John Pels*** replied:
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
Replied 25 Oct 2010 09:34:14
25 Oct 2010 09:34:14 guru murthy replied:
Hi,

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

Gurumurthy

Reply to this topic