View Full Version : Copying records??

09-21-2005, 10:36 PM
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,

$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,

09-21-2005, 10:53 PM
which field is the primary key field? whichever one it is, it cannot be repeated. mysql_error (http://www.php.net/mysql_error) probably would have told you that.

09-21-2005, 10:55 PM
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..