SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, why can I not make this here:

    $result = mysql_query("INSERT INTO ticket_e SET " .
    "vorf_te='$vorv_te', " .
    "vorf_fa='$vorv_fa'");
    $lastid=mysql_insert_id();

    $result2 = mysql_query ("UPDATE event SET " .
    "loc_id='$lastid', " .
    "WHERE ev_id=$ev_id");

    event and loc have a n/1 relation. I will let the user input the dates step by step. First of all the event, next the loc. So I get the event_id in the first step with mysql_insert_id();
    go to step 2 and that is what you see above.
    But anyway he isn't interested in the second part in any way, I can change what I want.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He, he - I don't understand your problem/question. I follow the code you have posted - but what is the question?

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first part of the skript works fine, (..insert into..)
    but the second part of the skript (...update...) has no effect.
    So my question is: How can I make the skrip to do both, first insert in the table ticket_e, get the id and put this id in the table event ??
    Thanx

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, nothing obvious seems wrong with your code. Is there any other code in between what you have posted here ?

    Instead of

    $lastid=mysql_insert_id();

    try

    $lastid=mysql_insert_id($result);

    Also, "loc_id='$lastid', " you don't need that comma - but this shouldn't cause any probem.

    Perhaps you should insert some code for debugging purposes to narrow down the problem.

    $result = mysql_query("INSERT INTO ticket_e SET " .
    "vorf_te='$vorv_te', " .
    "vorf_fa='$vorv_fa'");
    $lastid=mysql_insert_id();
    echo "lastid : $lastid \n";
    echo "ev_id : $ev_id \n";

    $result2 = mysql_query ("UPDATE event SET " .
    "loc_id='$lastid', " .
    "WHERE ev_id=$ev_id");
    echo "Affected rows : " . mysql_affected_rows();

    See if that gives any clues

  5. #5
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, the problem was the comma in "loc_id='$lastid', "
    It works fine without. That's what I hate about PHP, I spent nearly all the time finding commas, thanx, alex

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sid just as a follow up and in case anyone is wondering the mysql_insert_id() takes the link id as an arg not the query id so it takes whatever you assigned to the mysql_connect statement or the only one on the page if you leave it blank.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •