joeysarsenal Posted October 11, 2007 Share Posted October 11, 2007 at the moment i have this <?php /* Populate The products Table ** Use an Include file to open the database */ include( "connect.inc" ); $sql = "INSERT INTO tbl_product VALUES " . "(0, 11, 'Abu Garcia Cardinal CSW172 Fishing Reel', 'A fishing rod !!!!!!!!!', '63.95', '1000', '36d29b9445468ee556caa70d0e7f43b7','36d29b9445468ee556caa70d0e7f43b7', '', ''), " . "(0, 16, 'Abu Garcia Cardinal CSW173 Fishing Reel', 'A fis4hing rod !!!!!!!!!', '62.95', '1000', '','', '', '')"; if(mysql_query($sql)){ echo("<p>Product table successfully populated!</p>"); } else{ print("<p>Error adding to Product table: " . mysql_error() . "</p>"); } ?> and im trying to get it so when i go to populate the data it erases whats in there and puts new info in. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/ Share on other sites More sharing options...
thedarkwinter Posted October 11, 2007 Share Posted October 11, 2007 its time to look beyond INSERT and forward to UPDATE <?php mysql_query("UPDATE tbl_product SET field1='xxx',field2='xxx' WHERE rowid=$xyz"); i cant help anymore than that without knowing something about what you are updating (field names etc.) hope that helps tho, tdw Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-367078 Share on other sites More sharing options...
joeysarsenal Posted October 12, 2007 Author Share Posted October 12, 2007 all i want it to do is. That when i click populate it deletes all the information that is in the table and fills in what i have in code. Like i have a table with name type cost arsenal soccer $50 but in my code ive changed to info to become arsenal soccer-club $50. Cause if i repopulate the data it just duplicates and i dont really want that Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-367597 Share on other sites More sharing options...
joeysarsenal Posted October 12, 2007 Author Share Posted October 12, 2007 i can supply table if u wish, althought its on my laptop. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-367703 Share on other sites More sharing options...
thedarkwinter Posted October 12, 2007 Share Posted October 12, 2007 If you are deleting everything in the table then "DELETE FROM mytable" will delete everything... And then do your insert Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-367747 Share on other sites More sharing options...
fenway Posted October 12, 2007 Share Posted October 12, 2007 all i want it to do is. That when i click populate it deletes all the information that is in the table and fills in what i have in code. Like i have a table with name type cost arsenal soccer $50 but in my code ive changed to info to become arsenal soccer-club $50. Cause if i repopulate the data it just duplicates and i dont really want that Thanks in advance That's the update indicated earlier. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-367835 Share on other sites More sharing options...
joeysarsenal Posted October 12, 2007 Author Share Posted October 12, 2007 how do i incoperate that into the acutall code, do i remove the insert? Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-367852 Share on other sites More sharing options...
fenway Posted October 12, 2007 Share Posted October 12, 2007 how do i incoperate that into the acutall code, do i remove the insert? You have to "mark" each field that relates to the original record so that you can "gather" it again. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-367906 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 i tried to just delete it, but ended up getting t-string error $sql = DELETE * FROM tbl_product; //drop all data , then insert $sql = "INSERT INTO tbl_product VALUES " . "(0, 11, 'Abu Garcia Cardinal CSW172 Fishing Reel', 'A fishing rod !!!!!!!!!', '63.95', '1000', '36d29b9445468ee556caa70d0e7f43b7','36d29b9445468ee556caa70d0e7f43b7', '', ''), " . "(0, 16, 'Abu Garcia Cardinal CSW173 Fishing Reel', 'A fis4hing rod !!!!!!!!!', '62.95', '1000', '','', '', '')"; Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368261 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 i guess your insert is invalid you can only insert one value per statement $sql = "INSERT INTO tbl_product VALUES " . "(0, 11, 'Abu Garcia Cardinal CSW172 Fishing Reel', 'A fishing rod !!!!!!!!!', '63.95', '1000', '36d29b9445468ee556caa70d0e7f43b7','36d29b9445468ee556caa70d0e7f43b7', '', ''), " ; Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368266 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 i think the error is coming from my delete * from table Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\MYSQL\Products\Product_Detail.php on line 20 line 20 = $sql = DELETE * FROM tbl_product; thanks for the quick reply Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368269 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 $sql ="DELETE * FROM tbl_product"; no " Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368273 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 i get no error on command but when i go to populate the data into the table it just adds on to what ever was there. Im stuck. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368275 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 <?php /* Populate The products Table ** Use an Include file to open the database */ include( "connect.inc" ); $sql = "INSERT INTO tbl_product VALUES (0, 11, 'Abu Garcia Cardinal CSW172 Fishing Reel', 'A fishing rod !!!!!!!!!', '63.95', '1000', '36d29b9445468ee556caa70d0e7f43b7','36d29b9445468ee556caa70d0e7f43b7', '', '')"; // adding this is invalid"(0, 16, 'Abu Garcia Cardinal CSW173 Fishing Reel', 'A fis4hing rod !!!!!!!!!', '62.95', '1000', '','', '', '')"; //put this on another insert statement //replace your delete with this //$sql ="DELETE * FROM tbl_product"; <--- you should put here a condition or it wioll delt all records if(mysql_query($sql)){ echo("<p>Product table successfully populated!</p>"); } else{ print("<p>Error adding to Product table: " . mysql_error() . "</p>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368276 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 teng, it works fine if i populate many. And yes i want it to delete everything in the table. so that the table empty then filled with the new information. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368278 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 wait im confuze with what really want to do can you explain it again and give few info about it Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368285 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 lol sorry if ive confused you. i do that alot :S ok all i want it to do is delete everything thats inside the table before it inserts. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368288 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa i tried to just delete it, but ended up getting t-string error $sql = "DELETE * FROM tbl_product"; //drop all data , then insert $sql = "INSERT INTO tbl_product VALUES " . "(0, 11, 'Abu Garcia Cardinal CSW172 Fishing Reel', 'A fishing rod !!!!!!!!!', '63.95', '1000', '36d29b9445468ee556caa70d0e7f43b7','36d29b9445468ee556caa70d0e7f43b7', '', ''), " . "(0, 16, 'Abu Garcia Cardinal CSW173 Fishing Reel', 'A fis4hing rod !!!!!!!!!', '62.95', '1000', '','', '', '')"; then that is almost right you only missed " on your delete try that now Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368290 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 Its just puts data over what was already there. Its not deleteing everything if anything. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368297 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 nah try $sql = "DELETE * FROM tbl_product"; //drop all data , then insert mysql_query($sql ); $sql = "INSERT INTO tbl_product VALUES " . "(0, 11, 'Abu Garcia Cardinal CSW172 Fishing Reel', 'A fishing rod !!!!!!!!!', '63.95', '1000', '36d29b9445468ee556caa70d0e7f43b7','36d29b9445468ee556caa70d0e7f43b7', '', ''), " . "(0, 16, 'Abu Garcia Cardinal CSW173 Fishing Reel', 'A fis4hing rod !!!!!!!!!', '62.95', '1000', '','', '', '')"; mysql_query($sql); maybe you ddont use mysql_query or if you did you put them together that over right the above query try that now Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368302 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 <?php /* Populate The Staff Table ** Use an Include file to open the database */ include( "connect.inc" ); */$sql = "DELETE * FROM tbl_product"; //drop all data , then insert mysql_query($sql ); $sql = "INSERT INTO tbl_product VALUES " . "(0, 11, 'Abu Garcia Cardinal CSW172 Fishing Reel', 'A fishing rod !!!!!!!!!', '63.95', '1000', '36d29b9445468ee556caa70d0e7f43b7','36d29b9445468ee556caa70d0e7f43b7', '', ''), " . "(0, 16, 'Abu Garcia Cardinal CSW173 Fishing Reel', 'A fis4hing rod !!!!!!!!!', '62.95', '1000', '','', '', '')"; mysql_query($sql); if(mysql_query($sql)){ echo("<p>Product table successfully populated!</p>"); } else{ print("<p>Error adding to Product table: " . mysql_error() . "</p>"); } ?> still same problem even if i do that. Its just adding on the to table its not deleting anything Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368306 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 try to remove the * on your delete statement hmm not an issue but try Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368310 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 Hmm without the star. It deletes most but its not working to stratch when i go to populate there are till 2 products in the table. Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368314 Share on other sites More sharing options...
joeysarsenal Posted October 13, 2007 Author Share Posted October 13, 2007 teng i took out the * from my delete statement from my old code and it worked like a charm thanks for all ur help *Solved* Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368318 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 you should tell me that deleting is your prob it should not take this long lol Quote Link to comment https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/#findComment-368336 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.