I have a select list that contains strings fetched from my database, multiple strings contain spaces and are causing error, at first PHP was not reading the space. I fixed that using quotations but the error is still there.
This is my php code in one file:
$AllDepartements = $db->getAllDepartements();
echo "<select name='Major' style='width: 270px'><option value=''>Select Major</option>";
While ($row = mysql_fetch_array($AllDepartements))
{
$Major = $row['DName'];
print "<option value='".$Major."'>$Major</option>";
}
print "</select><br>";
and this is the add function call:
else if($tag =='add'){
$SSN = $_POST['SSN'];
$Class = $_POST['Class'];
$Major = $_POST['Major'];
$Minor = $_POST['Minor'];
if($db->addStudent($SSN,$Class,$Major,$Minor))
header('Location:' . $form . '.php?tag=list');
else
echo mysql_error();
//echo "ERROR!";
}
and finally the function itself:
public function addStudent($SSN,$Class,$Major,$Minor) {
if($result = mysql_query(" INSERT INTO student (SSN,Class,Major,Minor) VALUES ('$SSN','$Class',$Major,$Minor ")) {
return true ;
}
else
return false;
}
The error I receive is:
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 '' at line 1