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.

Recommended Answers

All 6 Replies

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

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 : Why you are posting repeated solutions?
what`s new in your solutions?
Weird !!!!

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

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.")";

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.