0

This Error keep show up everytime i use insert query code in my php programs

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 '-student(stud-id,stud-fname,stud-mname, stud-lname,stud-gender,stud-status,stud' at line 1

example code:

<?php
require_once "formvalidator.php";
$show_form=true;
if(isset($_POST['submit1']))
{
require("connectiondetail.php");

$connection = mysql_connect(SERVER,USER,PASS);
if(!$connection){
    die("Database connection failed: ". mysql_error());
}
$db_select = mysql_select_db(DB_NAME,$connection);
if(!$db_select){
    die("Database selection failed: ". mysql_error());
}

$Sfname = $_POST['stud-fname'];
$Smname = $_POST['stud-Mname'];
$Slname = $_POST['stud-Lname'];
$Sgender = $_POST['stud-gender'];
$Sstatus = $_POST['stud-status'];
$SBmon = $_POST['stud-Bmon'];
$SBday = $_POST['stud-Bday'];
$SByear = $_POST['stud-Byear'];
$Sdob = $Bmon . " " . $Bday . " " . $Byear;
$Saddress = $_POST['stud-address'];
$Scontact = $_POST['stud-contactNo'];
$Semail = $_POST['stud-email'];
$Scourse = $_POST['stud-course'];
$Syear = $_POST['SY'];

$validator = new FormValidator();

$validator->addValidation("stud-fname","req","Please fill up First Name!");
$validator->addvalidation("stud-Mname","req","Please fill up Middle Name!");
$validator->addvalidation("stud-Lname","req","Please fill up Last Name!");
if($Sgender == "0"){
    $validator->addvalidation("stud-gender","req","Please choose a Gender!");
}
if($Sstatus == "0"){
$validator->addvalidation("stud-status","req","Please choos a Status!");
}
if($Smon == "0"){
$validator->addvalidation("stud-Bmon","req","Please Choose a Birth Month!");
}
if($Sday == "0"){
$validator->addvalidation("stud-Bday","req","Please Choose a Birth Day");
}
if($Syear == "0"){
$validator->addvalidation("stud-Byear","req","Please Choose a Birth Year");
}
$validator->addvalidation("stud-address","req","Please fill up Address!");
$validator->addvalidation("stud-contactNo","req","Please fill up Contact Number!");
$validator->addvalidation("stud-email","req","Please fill up Email Address!");

if($validator->ValidateForm())
    {
        echo "<h2>Validation Success!</h2>";
        $show_form=false;
        if($Sgender == "0"){
    ?> <a href="ZF/Enrollment.php"></a> <?php
    echo "Please Choose a Gender!";
}
else {
if($Sstatus == "0"){
    echo "Please Choose a Status!";
}
else {
if($SBday == "0"){
    echo "Please fill in complete DOB";
}
else{
if($SBmon == "0"){
    echo "Please fill in complete DOB";
}
else{
if($Syear == "0"){
    echo "Please fill in complete DOB";
}
else {
if($Scourse == "0"){
    echo "Please Choose a Course!";
}
else {
$query = ("INSERT INTO info-student(stud-id,stud-fname,stud-mname,
stud-lname,stud-gender,stud-status,stud-DOB,stud-address,stud-contact,
stud-email,stud-course,stud-year) VALUES('','$Sfname', '$Smname', '$Slname', 
'$Sgender', '$Sstatus', '$Sdob', '$Saddress', '$Scontact', '$Semail', 
'$Scourse', '$Syear')");

mysql_query($query) or die(mysql_error());

mysql_close($connection);
echo "New MySQL user added";
}
}
}
}
}
}
}

    }
    else
    {
        echo "<B>Validation Errors:</B>";

        $error_hash = $validator->GetErrors();
        foreach($error_hash as $inpname => $inp_err)
        {
          echo "<p>$inpname : $inp_err</p>\n";
        }
    }

?>

Please i need some help any if anyone care.. i need help badly T_T

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by stone2191
0

If I remember correctly using a minus(-) to seperate column words will work perfect in mySql itself or phpmyAdmin , but when you use that in your code, "Welcome to problems" for me the solution was to use an underscore(_).

or try single quoting column names.

and if you stud-id fields uses auto increment , then its better to try the keyword DEFAULT for its value(at least thats what I do).

I hope this helps


cheers

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.