+ Post New Thread
Results 1 to 6 of 6
Coding Thread, php problems in Coding and Web Development; Hi I am having a problem with this insert statement have I written it correctly please thanks in advance. All ...
  1. #1

    Join Date
    Jul 2008
    Location
    Seaton Canoe
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Cool php problems

    Hi I am having a problem with this insert statement have I written it correctly please thanks in advance. All errors pointed out will be fantastic !!!



    PHP Code:
    if (isset($_POST['Add'])){ 
     
    $hardwareid mysql_real_escape_string($_POST['hardwareid']); 
    $departmentid mysql_real_escape_string($_POST['departmentid']); 
    $roomid mysql_real_escape_string($_POST['roomid']); //insert
    $equiptmenttype mysql_real_escape_string($_POST['equiptmenttype']); 
    $serialnumber mysql_real_escape_string($_POST['serialnumber']); 
    $suppilername mysql_real_escape_string($_POST['suppilername']);  
    $price mysql_real_escape_string($_POST['price']); 
    $present mysql_real_escape_string($_POST['present']); 

    $query5 ="INSERT INTO hardware 
    VALUES('','
    $departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"


    mysql_query("INSERT INTO hardware 
    VALUES("",'
    $departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"



  2. #2
    penfold_99's Avatar
    Join Date
    Feb 2008
    Location
    East Sussex
    Posts
    985
    Thank Post
    58
    Thanked 165 Times in 117 Posts
    Rep Power
    68
    Try adding the "." in to the queary then you will construct the string correctly

    $query5 ="INSERT INTO hardware
    VALUES('',' . $departmentid .',' .$roomid .',' . $equiptmenttype . ',' . $serialnumber . ',' . $suppilername .',' . $price .',' .$present')";

  3. #3
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118
    PHP Code:
    $query5 ="INSERT INTO hardware ('dept_id', 'room_id', 'equiptype', ... etc... , 'present') 
    VALUES('','
    $departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"

    mysql_query($query5) or die(mysql_error()); 
    That's the bit you're going to be having problems with...

    I've setup the code as an example as you haven't listed the tables column headers/labels so you need to edit the
    PHP Code:
    ('dept_id''room_id''equiptype', ... etc... , 'present'
    bit accordingly...

    It'll also provide you with an error as to why it didn't like it which is good debugging practice.



    The suggestion re: the dots, etc... isn't necessary as you're using double quotes to enclose the $query5 string.. You would need to if you were using single quotes.
    Last edited by contink; 23rd July 2008 at 03:55 PM.

  4. #4

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,683
    Thank Post
    1,268
    Thanked 789 Times in 686 Posts
    Rep Power
    237
    Quote Originally Posted by freakyleaks View Post
    Hi I am having a problem with this insert statement
    You'll have to tell us what the problem you are having is. Do you get a PHP syntax error, or an SQL syntax error? Does the data go in to the database, just in the wrong way or a way you weren't expecting?

    [QUOTE]$query5 ="INSERT INTO hardware
    VALUES('','$departmentid','$roomid','$equiptmentty pe','$serialnumber','$suppilername', '$price', '$present')";

    mysql_query("INSERT INTO hardware
    VALUES("",'$departmentid','$roomid','$equiptmentty pe','$serialnumber','$suppilername', '$price', '$present')";[/QUOTE

    You construct the query string twice? Probably you meant to do something like:

    $query5 = ...
    print $query5; # For debugging purposes - does the SQL query string look like you expected?
    mysql_query($query5);

    --
    David Hicks

  5. #5

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,157
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Not sure what you're doing here, but if the data could already exist then this will either end up with duplicate records (bad :-() or just fail.

    What I always do is try to delete the record based on key field and then do an insert.

  6. #6
    PEO
    PEO is offline
    PEO's Avatar
    Join Date
    Oct 2007
    Posts
    2,096
    Thank Post
    457
    Thanked 152 Times in 96 Posts
    Rep Power
    72
    comon chris, lets see it up and running

SHARE:
+ Post New Thread

Similar Threads

  1. PHP on IIS 6
    By Ryan in forum Windows
    Replies: 1
    Last Post: 27th May 2008, 01:32 PM
  2. PHP Help!
    By Cravon in forum Coding
    Replies: 2
    Last Post: 20th November 2007, 05:05 PM
  3. CMS - PHP problems
    By wesleyw in forum How do you do....it?
    Replies: 6
    Last Post: 12th July 2007, 09:22 AM
  4. Help with PHP
    By Gatt in forum Web Development
    Replies: 1
    Last Post: 14th November 2006, 09:01 PM
  5. php help
    By beeswax in forum Windows
    Replies: 33
    Last Post: 14th October 2005, 04:51 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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