I'm very new to php. I am using php with a mysql database. I am trying to do a simple append query via php. I want to copy the data from one table into another - empty table that has the same structure, then display the new table data in a comma separated list. I'm not sure what I'm doing wrong, but I keep getting error message "unexpected T_String" on the line.. $query = ...
Can anyone tell me what I'm doing wrong with this? Thank you!
Here's my code:
<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
//Append the contents of tblOne into tblOnecopy
$result = mysql_query("Select * From 'tblOne');
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array($result)){
$query = mysql_query("INSERT INTO `tblOnecopy` VALUES ($row['Field1'],$row['Field2'],$row['Field3'],$row['Field4']);");
}
//Print out tblOnecopy data separated by commas
$result = mysql_query("Select * From 'tblOnecopy'");
$row = mysql_fetch_array( $result );
// Print out the contents of the table
while($row = mysql_fetch_array($result)){
echo $row['Field1'],",",$row['Field2'],",",$row['Field3'],",",$row['Field4'];
echo "<br />";
}
?>
Can anyone tell me what I'm doing wrong with this? Thank you!
Here's my code:
<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
//Append the contents of tblOne into tblOnecopy
$result = mysql_query("Select * From 'tblOne');
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array($result)){
$query = mysql_query("INSERT INTO `tblOnecopy` VALUES ($row['Field1'],$row['Field2'],$row['Field3'],$row['Field4']);");
}
//Print out tblOnecopy data separated by commas
$result = mysql_query("Select * From 'tblOnecopy'");
$row = mysql_fetch_array( $result );
// Print out the contents of the table
while($row = mysql_fetch_array($result)){
echo $row['Field1'],",",$row['Field2'],",",$row['Field3'],",",$row['Field4'];
echo "<br />";
}
?>