I am doing a sample project.In that when i am edititng the records i am getting this error . Can anyony resolve me?
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'australia,companyname='asdf' WHERE id='4'' at line 1
It looks like there is an error in your SQL syntax near australia,companyname='asdf' WHERE id='4'. Probably because of the missing quote.
Here is my code...
<?php
function renderForm($id,$fname,$name,$currentdesignation,$currentemployer,$email,$telephone,$comments,$education,$experience,$currentlocation,$companyname)
{
?>
//check if the form has been submitted.If it has,process the form and save it into teh database
if(isset($_POST['submit']))
{
//confirm that the 'id' value is a valid integer before getting the form data
if(is_numeric($_POST['id']))
{
//get form data,making sure it is valid
$id=$_POST['id'];
$fname=mysql_real_escape_string(htmlspecialchars($_POST['fname']));
$name=mysql_real_escape_string(htmlspecialchars($_POST['name']));
$currentdesignation=mysql_real_escape_string(htmlspecialchars($_POST['currentdesignation']));
$currentemployer=mysql_real_escape_string(htmlspecialchars($_POST['currentemployer']));
$telephone=mysql_real_escape_string(htmlspecialchars($_POST['telephone']));
$email=mysql_real_escape_string(htmlspecialchars($_POST['email']));
$comments=mysql_real_escape_string(htmlspecialchars($_POST['comments']));
$education=mysql_real_escape_string(htmlspecialchars($_POST['education']));
$experience=mysql_real_escape_string(htmlspecialchars($_POST['experience']));
$currentlocation=mysql_real_escape_string(htmlspecialchars($_POST['currentlocation']));
$companyname=mysql_real_escape_string(htmlspecialchars($_POST['companyname']));
//check that fields are filled in
if($fname==""||$name==""||$currentdesignation==""||$currentemployer==""||$email==""||$telephone==""||$comments==""||$education==""||$experience==""||$currentlocation==""||$companyname=="")
{
//generate error message
$error='ERROR:Please fill in all required fields!';
//error display form
renderForm($id,$fname,$name,$currentdesignation,$currentemployer,$email,$telephone,$comments,$education,$experience,$currentlocation,$companyname);
}
else
{
//save the data to the database
$result=mysql_query("UPDATE han.form SET fname='$fname',name='$name',currentdesignation='$currentdesignation',currentemployer='$currentemployer',email='$email',telephone='$telephone',comments='$comments',education='$education',experience='$experience,currentlocation='$currentlocation,companyname='$companyname' WHERE id='$id'") or die(mysql_error());
//once saved,redirect back to the view page
header("Location:view.php");
}
}
else
{
//if the 'id' isnt valid,display an error
echo 'Error!';
}
}
else
$id=$_GET['id'];
$result=mysql_query("SELECT * FROM han.form WHERE id='$id'") or die(mysql_error());
$row=mysql_fetch_array($result);
//check that the 'id' matches up with a row in the database
if($row)
{
//get data from db
$fname=$row['fname'];
$name=$row['name'];
$currentdesignation=$row['currentdesignation'];
$currentemployer=$row['currentemployer'];
$email=$row['email'];
$telephone=$row['telephone'];
$comments=$row['comments'];
$education=$row['education'];
$experience=$row['experience'];
$currentlocation=$row['currentlocation'];
$companyname=$row['companyname'];
//show form
renderForm($id,$fname,$name,$currentdesignation,$currentemployer,$email,$telephone,$comments,$education,$experience,$currentlocation,$companyname);
}
else
//if no match,display result
{
echo 'No result!';
}
}
else
// if the 'id' in the URL isnt valid,or if there is no 'id' value,display an error
{
echo 'Error!';
}
}
?>
You're missing a closing quote after $experience AND after $currentlocation.
Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail I'd rather be a comma, then a full stop. User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning
Bookmarks