Hello Everyone,
I have an insert.php that could not insert data from php form into my mysql database.
Can anyone point out my mis-takes out or what i should correct from my insert command. The code is here below:
…
// Connect to server and select database.
mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);
mysql_select_db(“$db_name”)or die(“cannot select DB”);
// Get values from form
$option1=$_POST[‘I like orange’];
$option2=$_POST[‘I like apple’];
$option3=$_POST[‘I like banana’];
$sd=$_POST[‘strongly disagree’];
$d=$_POST[‘disagree’];
$nad=$_POST['$neither agree or disagree '];
$a=$_POST[‘agree’];
$sa=$_POST[‘strongly agree’];
$evd=$_POST[‘never’];
$sql=“insert into $Questions (Question_NO, Question) values (‘$I like orange’, ‘$I like apple’, ‘$Ilike banana’)”;
$sql2=“insert into $AnswerKeys(AnswerKey_ID, AnswerKey) values (‘$strongly disagree’, ‘$disagree’, ‘$neither agree or disagree’, ‘$agree’, ‘$strongly agree’, ‘$never’)”;
$result=mysql_query($sql);
$result=mysql_query($sql2);
// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “<BR>”;
echo “<a href=‘index.php’>Back to main page</a>”;
}
else {
echo “ERROR”;
}
// close connection
mysql_close();
?>
[ /]