Jump to content

[SOLVED] Repopulating data


joeysarsenal

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/72770-solved-repopulating-data/
Share on other sites

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

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

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.

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', '','', '', '')";

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', '', ''), " ;

 

<?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>");	
}
?>

haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ;D

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

 

 

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.