0

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" /><br />
Father Name<input type="text" name="fname" /><br />
Birth Where/When<input type="text" name="birth" /><br />
<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.

5
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by rpv_sen
1

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

Edited by Amr87: n/a

0

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

0

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

0

remove the:
extract($_REQUEST);

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

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

0

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();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.