Jump to content

Recommended Posts

In my MySQL Database, I have a pending_uploads table. It stores the following:

 

uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete

 

Now, I also have another table, called declined_uploads. In the declined_uploads table, it has the following aswell...

 

uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete

 

Now, the DEFAULT for the uploaddelete column in both tables are a value of 'no'

But, how would I transfer EVERY ROW with their uploaddelete value of 'yes', to transfer all the info to the declined_uploads table? Because the rows that I want transfered to the declined_uploads table have their uploaddelete value of 'yes'

 

I sort of have this BASE of the code...

 

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("my_db", $con);
mysql_query("INSERT INTO declined_uploads (FirstName, LastName, Age) 
VALUES ('Peter', 'Griffin', '35')");
mysql_close($con);
?>

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/43535-solved-delete-where-x-y/
Share on other sites

INSERT INTO declined_uploads (uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete)

SELECT uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete

FROM pending_uploads

WHERE uploaddelete='yes'

Remember to back up data before trying this, as I am not sure of the results:

 

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("my_db", $con);

$qu = mysql_query("SELECT uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete FROM pending_uploads WHERE uploaddelete = 'yes'") or DIE(mysql_error());

while ($row = mysql_fetch_array($qu)) {
       mysql_query("INSERT INTO declined_uploads (uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete) VALUES ('".$row['uploadname']."', '".$row['uploadauthor']."','".$row['uploadid']."','".$row['uploaddescription']."','".$row['uploaddelete']."')");

       mysql_query("DELETE FROM pending_uploads WHERE uploadname = '".$row['uploadname']."' AND uploadauthor='".$row['uploadauthor']."' AND uploadid='".$row['uploadid']."' AND uploaddescription = '".$row['uploaddescription']."' AND uploaddelete='".$row['uploaddelete']."' LIMIT 1");
}

mysql_close($con);
?>

 

See if that works.

Frost110, your code works for deleting, but it doesn't transfer any of the database information to the declined_uploads database :(

 

Do you, or anyone else have a solution to his code? Something is wrong with the declined_uploads part of it. No error is given.

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("my_db", $con);

$qu = mysql_query("SELECT uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete FROM pending_uploads WHERE uploaddelete = 'yes'") or DIE(mysql_error());

while ($row = mysql_fetch_array($qu)) {
       mysql_query("INSERT INTO declined_uploads (uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete) VALUES ('".$row['uploadname']."', '".$row['uploadauthor']."','".$row['uploadid']."','".$row['uploaddescription']."','".$row['uploaddelete']."')") or DIE(mysql_error());

       mysql_query("DELETE FROM pending_uploads WHERE uploadname = '".$row['uploadname']."' AND uploadauthor='".$row['uploadauthor']."' AND uploadid='".$row['uploadid']."' AND uploaddescription = '".$row['uploaddescription']."' AND uploaddelete='".$row['uploaddelete']."' LIMIT 1");
}

mysql_close($con);
?>

 

Try that. I most likely messed up the single and double quotes. Report what the mysql_error() is.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.