php@mysql problem, using MySQL reserved words

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bb nicole
    New Member
    • Jan 2007
    • 127

    php@mysql problem, using MySQL reserved words

    Below is my php code which i need to save the jobseeker resume in database. But does not function and show the message: Column count doesn't match value count at row 1 after i add a field name resume_ID as a primary key in phpMyadmin. i dont know what is the error i done. Thanks.

    do_resume.php
    [PHP]<?php
    include_once("d atabase.php");


    class user {


    function linkid ()
    {
    $db = new db();
    $link_id = $db->dbconnect();

    return $link_id;
    } // end function linkid

    function add_user($arr)
    {


    $link_id = $this->linkid();


    $fullName = $arr['fullName'];
    $nric = $arr['nric'];
    $gender = $arr['gender'];
    $day = $arr['day'];
    $month = $arr['month'];
    $year = $arr['year'];
    $maritalStatus = $arr['maritalStatus'];
    $nationality = $arr['nationality'];
    $emailAdd = $arr['emailAdd'];
    $contactNum = $arr['contactNum'];
    $contactAdd = $arr['contactAdd'];
    $languages1 = $arr['languages1'];
    $languages2 = $arr['languages2'];
    $education = $arr['education'];
    $workExp = $arr['workExp'];
    $curricularAct = $arr['curricularAct'];
    $skills = $arr['skills'];
    $references = $arr['references'];


    if($fullName==" "){
    $message="Opps. . You forgot enter your Full Name!<br>";
    include("resume .php");
    }


    else


    if($nric==""){
    $message="Opps. . You forgot enter your NRIC!<br>";
    include("resume .php");
    }


    else


    if($gender=="") {
    $message="Pleas e select your Gender!<br>";
    include("resume .php");
    }


    else


    if($maritalStat us==""){
    $message="Pleas e select your Marital Status!<br>";
    include("resume .php");
    }


    else


    if($nationality ==""){
    $message="Opss. . You forgot enter your Nationality!<br >";
    include("resume .php");
    }


    else


    if($emailAdd==" "){
    $message="Opps. . You forgot enter your Email Address!<br>";
    include("resume .php");
    }


    else


    if($contactNum= =""){
    $message="Opps. . You forgot enter your Contact Number!<br>";
    include("resume .php");
    }


    else


    if($contactAdd= =""){
    $message="Opps. . You forgot enter your Contact Address!<br>";
    include("resume .php");
    }


    else


    if($languages1= =""){
    $message="Pleas e select your Languages(oral) !<br>";
    include("resume .php");
    }


    else


    if($languages2= =""){
    $message="Pleas e select your Languages(writt en)!<br>";
    include("resume .php");
    }


    else


    if($education== ""){
    $message="You need to fill in your Education Level!<br>";
    include("resume .php");
    }


    else


    if($workExp=="" ){
    $message="You need to fill in your Work Experiences!<br >";
    include("resume .php");
    }


    else


    if($references= =""){
    $message="You need to fill in your References!<br> ";
    include("resume .php");
    }

    else

    {


    $myquery = "INSERT INTO resume
    VALUES ( '$fullName', '$nric', '$gender', '$day', '$month', '$year', '$maritalStatus ', '$nationality', '$emailAdd', '$contactNum', '$contactAdd', '$languages1', '$languages2', '$education', '$workExp', '$curricularAct ', '$skills', '$references' )";

    $result = mysql_query($my query,$link_id) or die(mysql_error ());

    include_once("r esume_success.p hp");


    }
    }
    }



    ?>[/PHP]

    do_resume_Pre.p hp
    [PHP]<?php
    include_once("d o_resume.php");


    $act = $_REQUEST['act'];


    if ($act == 'adduser') {

    $arr = $_REQUEST;
    $usr = new user();
    $usr->add_user($arr) ;


    exit();
    }


    ?>[/PHP]


    database.php

    [PHP]<?php
    class db {

    var $sqlserver = "localhost" ;
    var $sqldatabase = "ums e-job portal";
    var $sqluser = "root";
    var $sqlpass = "";
    var $link_id;

    function dbconnect () {
    $link_id = mysql_connect($ this->sqlserver, $this->sqluser, $this->sqlpass);
    $dbh = mysql_select_db ($this->sqldatabase) ;

    return $this->link_id = $link_id;
    }
    }

    ?>[/PHP]


    resume_success. php
    [PHP]<?php
    include("index. php");
    ?>[/PHP]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You don;'t have to show all code in this case. The MySQL message simply means that you have not specified the exact number of table columns in the INSERT statement.

    Since you use the VALUES attribute you must specify all values for all columns. When you don't want to use that, it is better to define the columns names first, like
    Code:
    INSERT INTO tablename (col1, col2 ,.... coln) VALUES(val1, val2, .... valn);
    Ronald :cool:

    Comment

    • bb nicole
      New Member
      • Jan 2007
      • 127

      #3
      Originally posted by ronverdonk
      You don;'t have to show all code in this case. The MySQL message simply means that you have not specified the exact number of table columns in the INSERT statement.

      Since you use the VALUES attribute you must specify all values for all columns. When you don't want to use that, it is better to define the columns names first, like
      Code:
      INSERT INTO tablename (col1, col2 ,.... coln) VALUES(val1, val2, .... valn);
      Ronald :cool:


      Thanks, but when i do like that, as php code shown below:
      [PHP]
      $myquery = "INSERT INTO resume ( fullName, nric, gender, day, month, year, maritalStatus, nationality, emailAdd, contactNum, contactAdd, languages1, languages2, education, workExp, curricularAct, skills, references )
      VALUES ( '$fullName', '$nric', '$gender', '$day', '$month', '$year', '$maritalStatus ', '$nationality', '$emailAdd', '$contactNum', '$contactAdd', '$languages1', '$languages2', '$education', '$workExp', '$curricularAct ', '$skills', '$references' )"; [/PHP]



      it will shown message like this: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 'references ) VALUES ( 'bb', '881028-11-5555', 'Female', '27',


      i have try many way, but din't success, i have no idea.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Show all your table columns with their data types. You can use the command
        Code:
        DESCRIBE tablename;
        to get that information. Then show it here.

        Ronald :cool:

        Comment

        • bb nicole
          New Member
          • Jan 2007
          • 127

          #5
          Originally posted by ronverdonk
          Show all your table columns with their data types. You can use the command
          Code:
          DESCRIBE tablename;
          to get that information. Then show it here.

          Ronald :cool:

          This is my table and datatype:
          Tablename: resume

          resume_ID int(10) PRI NULL auto_increment
          fullName varchar(30)
          nric varchar(14)
          gender varchar(20)
          day int(2) 0
          month varchar(20)
          year year(4) 0000
          maritalStatus varchar(20)
          nationality varchar(30)
          emailAdd varchar(50)
          contactNum varchar(11)
          contactAdd varchar(100)
          languages1 varchar(10)
          languages2 varchar(10)
          education blob
          workExp blob
          curricularAct blob
          skills blob
          references blob


          Thanks..

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Hold on a second! Did you specify the query exactly as you showed it, i.e. split over 2 lines without closing quotes and concatenating them? Then that is the error.

            Ronald :cool:

            Comment

            • bb nicole
              New Member
              • Jan 2007
              • 127

              #7
              Originally posted by bb nicole
              This is my table and datatype:
              Tablename: resume

              resume_ID int(10) PRI NULL auto_increment
              fullName varchar(30)
              nric varchar(14)
              gender varchar(20)
              day int(2) 0
              month varchar(20)
              year year(4) 0000
              maritalStatus varchar(20)
              nationality varchar(30)
              emailAdd varchar(50)
              contactNum varchar(11)
              contactAdd varchar(100)
              languages1 varchar(10)
              languages2 varchar(10)
              education blob
              workExp blob
              curricularAct blob
              skills blob
              references blob


              Thanks..
              What is the problem with my php code?? or it is problem of mysql??
              i don't know what to do.. Need to delete the Resume table and create new one??

              Comment

              • bb nicole
                New Member
                • Jan 2007
                • 127

                #8
                i don't really understand, you means in the php code or mysql, so what should i do now?? Thanks..

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  Originally posted by bb nicole
                  i don't really understand, you means in the php code or mysql, so what should i do now?? Thanks..
                  You most probably split your query over 2 lines without concatenating them. This is how you must define the query in PHP.
                  [php]$myquery = "INSERT INTO resume ( fullName, nric, gender, day, month, year, maritalStatus, nationality, emailAdd, contactNum, contactAdd, languages1, languages2, education, workExp, curricularAct, skills, references ) ".
                  " VALUES ( '$fullName', '$nric', '$gender', '$day', '$month', '$year', '$maritalStatus ', '$nationality', '$emailAdd', '$contactNum', '$contactAdd', '$languages1', '$languages2', '$education', '$workExp', '$curricularAct ', '$skills', '$references' )";
                  [/php]Ronald :cool:

                  Comment

                  • bb nicole
                    New Member
                    • Jan 2007
                    • 127

                    #10
                    if i code like this:
                    [PHP]$myquery = "INSERT INTO resume ( fullName, nric, gender, day, month, year, maritalStatus, nationality, emailAdd, contactNum, contactAdd, languages1, languages2, education, workExp, curricularAct, skills, references )"
                    "VALUES ( '$fullName', '$nric', '$gender', '$day', '$month', '$year', '$maritalStatus ', '$nationality', '$emailAdd', '$contactNum', '$contactAdd', '$languages1', '$languages2', '$education', '$workExp', '$curricularAct ', '$skills', '$references' )"; [/PHP]

                    then, will show the message:
                    Parse error: parse error, unexpected '"' in C:\Apache2\Apac he2\htdocs\do_r esume.php on line 162

                    Fatal error: Cannot instantiate non-existent class: user in C:\Apache2\Apac he2\htdocs\do_r esumePre.php on line 11


                    do_resumePre.ph p
                    [PHP]<?php
                    include_once("d o_resume.php");


                    $act = $_REQUEST['act'];


                    if ($act == 'adduser') {

                    $arr = $_REQUEST;
                    $usr = new user();
                    $usr->add_user($arr) ;


                    exit();
                    }


                    ?>[/PHP]


                    i don't know what is the error, i have done my registration form, it is not problem, the resume above is edit the code from my registration form, should be no problem.. i really don't know..

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      You made the same error again! You did NOT copy the code statement exactly as I showed you previously. You cannot construct the MySQL statement like you did. You must concatenate the strings when you use a multi-line construct.

                      So copy the statement I show you here and use that. I shortened the strings on each line so you can see what I am doing.

                      [php]$myquery = "INSERT INTO resume ( fullName, nric, gender, day, ".
                      " month, year, maritalStatus, nationality, emailAdd, contactNum, ".
                      " contactAdd, languages1, languages2, education, workExp, ".
                      " curricularAct, skills, references ) ".
                      " VALUES ( '$fullName', '$nric', '$gender', '$day', '$month', '$year', ".
                      " '$maritalStatus ', '$nationality', '$emailAdd', '$contactNum', ".
                      " '$contactAdd', '$languages1', '$languages2', '$education', ".
                      " '$workExp', '$curricularAct ', '$skills', '$references' )"; [/php]
                      Ronald :cool:

                      Comment

                      • bb nicole
                        New Member
                        • Jan 2007
                        • 127

                        #12
                        sorry, it can not work.. i have copy the code from you as below:
                        [PHP]$myquery = "INSERT INTO resume ( fullName, nric, gender, day, ".
                        " month, year, maritalStatus, nationality, emailAdd, contactNum, ".
                        " contactAdd, languages1, languages2, education, workExp, ".
                        " curricularAct, skills, references ) ".
                        " VALUES ( '$fullName', '$nric', '$gender', '$day', '$month', '$year', ".
                        " '$maritalStatus ', '$nationality', '$emailAdd', '$contactNum', ".
                        " '$contactAdd', '$languages1', '$languages2', '$education', ".
                        " '$workExp', '$curricularAct ', '$skills', '$references' )";[/PHP]

                        but the message as below shown:
                        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 'references ) VALUES ( 'tan mei ling', '880505-10-5432', 'Femal

                        Comment

                        • ronverdonk
                          Recognized Expert Specialist
                          • Jul 2006
                          • 4259

                          #13
                          Well, I am baffled. I tried it and it gave me the same error. Untill I took some columns off from he end. And when the column count was 16, I did not get the error any longer. I have no clue as to why this is happening.

                          I promise, I will look into it tomorrow. Maybe a bug in MySQL, I have no idea yet.

                          Ronald :cool:

                          Comment

                          • bb nicole
                            New Member
                            • Jan 2007
                            • 127

                            #14
                            thanks a lot.. i really no idea on it, i check the code again and again, but i can not find the error.. thanks..

                            Comment

                            • ronverdonk
                              Recognized Expert Specialist
                              • Jul 2006
                              • 4259

                              #15
                              I found it! It appears that references is a reserved word! (see also this link MySQL reserved words).

                              The only way to get this bypassed is either to change the column name or enclose the column name references within so-called 'back ticks', as follows:
                              Code:
                              `references`
                              .
                              So your select statement becomes[php]$myquery = "INSERT INTO resume ( fullName, nric, gender, day, ".
                              " month, year, maritalStatus, nationality, emailAdd, contactNum, ".
                              " contactAdd, languages1, languages2, education, workExp, ".
                              " curricularAct, skills, `references` ) ".
                              " VALUES ( '$fullName', '$nric', '$gender', '$day', '$month', ".
                              " '$year', '$maritalStatus ', '$nationality', '$emailAdd', ".
                              " '$contactNum', '$contactAdd', '$languages1', '$languages2', ".
                              " '$education', '$workExp', '$curricularAct ', '$skills', ".
                              " '$references' )"; [/php]
                              Ronald :cool:

                              Comment

                              Working...