ayok Posted December 26, 2007 Share Posted December 26, 2007 Hi, Is it possible to update the whole rows on a table with UPDATE table SET? I would like to replace some data's in a table with some new data's. Thus, the old datas should be all removed and new datas are inserted. I've tried to delete all data's first and entry some new data's, but it doesn't work. I keep getting "Query was empty" error message. Here is my try: <?php include "../../connection/db.php"; ............ $delete=mysql_query("DELETE * FROM form"); $input=mysql_query($delete) or DIE(mysql_error()); ............ $input=mysql_query("INSERT INTO form(picked,label,codes) VALUES('$picked','$label','$codes')") or DIE(mysql_error()); if($input) { echo "success"; } else { echo "failed!"; } ?> Anyone help? Thank you, ayok Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/ Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Where do you assign data to these variables? $picked,$label,$codes Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/#findComment-423471 Share on other sites More sharing options...
ayok Posted December 26, 2007 Author Share Posted December 26, 2007 Where do you assign data to these variables? $picked,$label,$codes I made a form which send the value of those variables to be inserted to the table. I can insert those to the table without deleting the old data's first. But I need to delete the old first. Thanks ayok Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/#findComment-423490 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 The DELETE * FROM form should delete all rows in the table form. But you are asking two different things. Your subject is UPDATE whole table. That isn't what you are doing, per say. You are deleting all rows and inserting new rows. The error that you query is empty is coming from the INSERT because you are not sending anything over. You need to assign data to those variables from your FORM. Where are your $_POST variables? Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/#findComment-423525 Share on other sites More sharing options...
ayok Posted December 26, 2007 Author Share Posted December 26, 2007 Hi revraz, What I'm trying to achieve is that to have new datas on my table. There is a form with check boxes (name='pick')for sending the datas. Here is the whole update.php: <?php $id_temp = $_POST['id_temp']; $pick = $_POST['pick']; $label_temp = $_POST['label_temp']; $codes_temp = $_POST['codes_temp']; include "../../connection/db.php"; $delete=mysql_query("DELETE * FROM form"); $input=mysql_query($delete) or DIE(mysql_error()); foreach($pick as $id_temp){ $select=mysql_query("SELECT * FROM temp_form WHERE id_temp = '$id_temp'"); while ($data=mysql_fetch_array($select)) { $label=$data[label_temp]; $codes=$data[codes_temp]; $input=mysql_query("INSERT INTO form(picked,label,codes) VALUES('$id_temp','$label','$codes')") or DIE(mysql_error()); } } if($input) { header("location:../../form/form.php"); } else { echo "failled!"; } ?> If i don't use this codes <?php $delete=mysql_query("DELETE * FROM form"); $input=mysql_query($delete) or DIE(mysql_error()); ?> I can insert new datas after I delete the old datas manually from phpmyadmin. But with those codes i keep getting error message: Query was empty. Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/#findComment-423535 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 You are doing it twice $delete=mysql_query("DELETE * FROM form"); $input=mysql_query($delete) or DIE(mysql_error()); make this just one line $delete=mysql_query("DELETE * FROM form") or DIE(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/#findComment-423556 Share on other sites More sharing options...
ayok Posted December 26, 2007 Author Share Posted December 26, 2007 How can I be so stupid Thanks, ayok Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/#findComment-423561 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Easy to overlook when it's your own code, much easier to find when it's someone else's Quote Link to comment https://forums.phpfreaks.com/topic/83243-solved-update-whole-table/#findComment-423563 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.