Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Copying records??

    Hi,
    I'm trying to copy records in mysql with php,

    what i've done is select the data I want from a table, and then insert it
    into the same table but with a different category id,. but this doesn't same to be working,

    PHP Code:
        $lid $_REQUEST['lid'];
        
    $cid $_REQUEST['cid'];
        
    $scid $_REQUEST['scid'];
        
    $ascid $_REQUEST['ascid'];
        
    $mascid $_REQUEST['mascid'];

            
    $result mysql_query("SELECT * FROM listings WHERE lid=$lid");
            while (
    $row mysql_fetch_assoc($result))
            {
    $lName         $row['Name'];
    $Description $row['Description'];
    $linkk         $row['link'];
    $keywords     $row['keywords'];
    $Country     $row['Country'];
    $StateProv     $row['StateProv'];
    $city         $row['city'];
    $contactemail$row['contactemail'];
    $paid         $row['paid'];

            }
        
    $sqlquery mysql_query("INSERT INTO listings (cid, scid, ascid, mascid, Name, Description, link, keywords, Country, StateProv, city, contactemail, paid, copy, copyid) VALUES ('$cid', '$scid', '$ascid', '$mascid', '$lName', '$Description', '$linkk', '$keywords', '$Country', '$StateProv', '$city', '$contactemail', '$paid', '1', '$lid')"); 
    this is to get copy to new categories in the same table, and I'm using the exact same insert state that I use to insert a new record from a form. so I know all the field names are correct,


    does any one have any idea what could be going on here? I've been playing with this code for over an hour now, and still at ground 0.

    thanks in advance for your time,
    -Ken

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    which field is the primary key field? whichever one it is, it cannot be repeated. mysql_error probably would have told you that.

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    yah, i wasn't trying to force the key id,,
    but i figured out what it was,,
    for some reason,, it wanted it to be more like,

    \"$Name\", \"$Description\"

    so it's working now,, but i couldn't understand why it would work the other from an html form, but not like that when pulling directly from the db..

    strange..

    -Ken


  •  

    Posting Permissions

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