Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    11

    Unanswered: Can't insert data with php??

    I have a table "request" in my database that I want to input data into via a form.
    For some reason no matter what I do I can't get any data into the table. I'm definitely connected to the database because I can output data from it, but I can't put anything in.
    My fields are:

    request_id,
    room_preference,
    module_code,
    semester,
    week,
    weekday,
    timeslot,
    lecture_type,
    park,
    number_students,
    number_rooms,
    additional_requests

    In my php I've got:

    $sql = "INSERT INTO request (
    request_id,
    room_preference,
    module_code,
    semester,
    week,
    weekday,
    timeslot,
    lecture_type,
    park,
    number_students,
    number_rooms,
    additional_requests) VALUES".implode(',', $AllPeriodsArray);

    mysql_query($sql);


    Which comes out as something like this:

    INSERT INTO request ( request_id, room_preference, module_code, semester, week, weekday, timeslot, lecture_type, park, number_students, number_rooms, additional_requests)
    VALUES( NULL, smb014, 12COA101, 1, 3, Monday, 3, Lecture, E, 25-50, 1, Blu ray player )




    I've gone so far as to generate php code from phpMyAdmin and making my $sql variable that exact code, and it still won't work.
    Any ideas?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote string/text values.
    Eg
    VALUES (null, 'smb014'.....
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Best thing to do when having problems like this is to print off the statement and then attempt to run it against the database. Once you have identified the problem then it is easy to make those program changes in PHP.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  4. #4
    Join Date
    May 2012
    Posts
    11
    I found out what the problem was.
    I was getting a syntax error because the way I was creating my array so I had no apostrophes around my values when inputting them into the fields

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •