Results 1 to 4 of 4

Thread: Problem with Mysql query

  1. #1
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Problem with Mysql query

    Hi I am after some help with mysql, I am new to this so please be gentle . I have created a form on our website that sends an email to our database and then to an email account which is working fine, I am trying to date stamp on submit which is working but its creating a new line in the database and not including the enquiry, what I think I have done is created two query that are working separately and not together. I have included the queries below; please can someone show me how to join these two queries together please.

    Thanks


    $query = "INSERT INTO pitman (id, f_name, postcode, tel, mobile, email, course) VALUES ('', '$f_name', '$postcode', '$tel', '$mobile', '$email' , '$course')";

    $query = "INSERT INTO `pitman` (`pdate`) VALUES (NOW())";

  2. #2
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    if they are both inserting values into the same table why not just do it all in one shot?

    Code:
    $query = "INSERT INTO pitman(id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('$f_Name', '$postcode', '$tel', '$mobile', '$email', '$course',NOW())";
    Also I am just curious, for your id field are you setting it to auto_increment or are you inserting the id in each INSERT query?

    I hope this helps...

  3. The Following User Says Thank You to Moshambi For This Useful Post:

    ace2721 (10-13-2008)

  4. #3
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    Whether it is incrementing or not the query still needs to be changed... either one of these would work for auto increment:

    Code:
    $query = "INSERT INTO pitman(id, f_name, postcode, tel, mobile, email, course, pdate) VALUES (null, '$f_Name', '$postcode', '$tel', '$mobile', '$email', '$course',NOW())";
    Code:
    $query = "INSERT INTO pitman(f_name, postcode, tel, mobile, email, course, pdate) VALUES ('$f_Name', '$postcode', '$tel', '$mobile', '$email', '$course',NOW())";

    If you are keeping track on your own you need something liek this:
    Code:
    $query = "INSERT INTO pitman(id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('$id', '$f_Name', '$postcode', '$tel', '$mobile', '$email', '$course',NOW())";

  5. The Following User Says Thank You to motormichael12 For This Useful Post:

    ace2721 (10-13-2008)

  6. #4
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default thanks

    Hi guys thanks so much for your help it worked a treat

Bookmarks

Posting Permissions

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