954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

what is the problem in my php&html code?

i have created a html form page(1) and php page(2) to insert records into a database from the html form,
when i insert the records from the html form and press the submit button the records don't get into the database but a page open with the php code i have wrote,and if i opened the php page or refresh it an empty records get added to my database,here is my html and php code:
html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta name="author" content="asdasdas" />

	<title>informations</title>
</head>

<body>
<form action="upload.php" method="post" enctype="multipart/form-data" >
Full Name<input type="text" name="fullname" />
Father Name<input type="text" name="fname" />
Birth Where/When<input type="text" name="birth" />
<input type="submit" value="save" name="submit"  />
</form>


</body>
</html>

php code:

<?php

/**
 * @author 00092
 * @copyright 2011
 */
extract($_REQUEST);
$con = mysql_connect("localhost", "root", "pass");
if (!$con) {
    die('could not connect:' . mysql_error());
}
mysql_select_db("info", $con);

$sql = "insert into `reference` (`fullname`,`fname`,`birth`)
values ('$_post[fullname]','$_post[fname]','$_post[birth]')";
if (mysql_query($sql, $con)) {
    echo "Done";
} else {
     
}


mysql_close($con);

?>

note:each one in a different page,am using a localhost server ,i mean it's not online.

Kratos-s-
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

DO NOT USE THIS

extract($_REQUEST);


Also On line 15 on the Php code

the global $_POST cant not be written in lowercase $_post as it will be NULL and nothing will be inserted to your database

Amr87
Junior Poster in Training
67 posts since Feb 2011
Reputation Points: 12
Solved Threads: 13
 

Your php code should be like this:

<?php

/**
 * @author 00092
 * @copyright 2011
 */
$con = mysql_connect("localhost", "root", "pass");
if (!$con) {
    die('could not connect:' . mysql_error());
}
mysql_select_db("info", $con);

$sql = "insert into `reference` (`fullname`,`fname`,`birth`)
values ('$_post[fullname]','$_post[fname]','$_post[birth]')";
if (mysql_query($sql, $con)) {
    echo "Done";
} else {
     
}


mysql_close($con);

?>

Just remove the line no.7

rv1990
Junior Poster in Training
51 posts since Aug 2011
Reputation Points: 17
Solved Threads: 7
 

rv1990 : Why you are posting repeated solutions?
what`s new in your solutions?
Weird !!!!

Amr87
Junior Poster in Training
67 posts since Feb 2011
Reputation Points: 12
Solved Threads: 13
 

Cool down friend! There is no need in panicking, acting weird.

rv1990
Junior Poster in Training
51 posts since Aug 2011
Reputation Points: 17
Solved Threads: 7
 

remove the:
extract($_REQUEST);

and replace it with:
$fullname = $_REQUEST['fullname'];
$fname = $_REQUEST['fname'];
$birth = $_REQUEST['birth'];

and for your query:
$sql = "insert into `reference` (`fullname`,`fname`,`birth`)
values (".$fullname.",".$fname.",".$birth.")";

decade
Junior Poster in Training
62 posts since Jun 2011
Reputation Points: 12
Solved Threads: 14
 

Hi

use the below code and check for your refernce

if($_POST['submit']=='save')
$query="INSERT INTO reference(fullname,fname,birth)values('".$_POST['fullname']."','".$_POST['fname']."','".$_POST['birth']."')";
mysql_db_query($database,$query);
$change=mysql_insert_id();
rpv_sen
Junior Poster
178 posts since Mar 2011
Reputation Points: 18
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: