not complete insert to mysql

A

Anonymous

Guest
hi
this is code of form to insert
<html>

Code:
<head>
  <title></title>
</head>

<body>
<form action="insert.php" method="post">
<p>name<input type="text" name="name">
<p>job<input type="text" name="job">
<p>age<input type="text" name="age">
<p><input type="submit" value="ok">
<input type="reset" value="return"></p>
</form>





</body>

</html>
and this code of insert inmysql
Code:
<?php

 $link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (mysql_select_db('sd')) {
echo "Database selecting successfully\n";
} else {
echo 'Error selecting database: ' . mysql_error() . "\n";
}
$text = "O'Brien";
$escaped = addslashes($text);
$result =  mysql_query("INSERT INTO form (id, name, job, age)
VALUES ('0', '$name', '$job', '$age')", $link);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}


?>
server give message it meaning that $name,$job,$age Notice: Undefined variable
help me urgent
 
The insert is most probably completed. You have notices turned on and its a good practive to do so..
The thing is that you are most probably trying to run the register_globals = on script. that BAD.

try using $_POST['name'] and simmilar.
 
use

Code:
 $result =  mysql_query("INSERT INTO form (id, name, job, age)
 VALUES ('0', '".$_POST['name']."', '".$_POST['job']."', '".$_POST['age']."')", $link);

instead of
Code:
 $result =  mysql_query("INSERT INTO form (id, name, job, age)
 VALUES ('0', '$name', '$job', '$age')", $link);

That should do the job... unless there is something else
 
Back
Top