I have been fooling around all day with this script, it is supposed to update records. Can anyone see what is causing problems? The data is text strings that may have spaces and punctuation in them. Maybe use addslashes() on the variables to be updated?
I did not include the connection script, it does connect OK.
There is a mysql syntax error in the line with $update1.
I could not find an icon for "tearing one's hair out".
I did not include the connection script, it does connect OK.
There is a mysql syntax error in the line with $update1.
I could not find an icon for "tearing one's hair out".
Code:
echo "Before Update<p>\n";
// $edit_line is a variable holding the name of a city passed from previous page
$query = "SELECT * FROM ycdest WHERE name='$edit_line'";
$result = mysql_query($query) or die("Query failed");
// this section prints out records from the database prior to updating.
while($row = mysql_fetch_row($result))
{
print "<table>\n";
print "<tr><td>$row[0]</td></tr>\n";
print "<tr><td>$row[1]</td></tr>\n";
print "<tr><td>$row[2]</td></tr>\n";
print "<tr><td>$row[3]</td></tr>\n";
print "<tr><td>$row[4]</td></tr>\n";
print "<tr><td>$row[5]</td></tr>\n";
print "</table>\n";
}
// this section prints out variables sent from previous page via GET
echo "Edit Line: " . $edit_line . "<P>\n";
echo "Name: " . $name . "<P>\n";
echo "Copy Text: " . $text . "<P>\n";
echo "Description: " . $desc . "<P>\n";
echo "Keywords: " . $key . "<P>\n";
echo "Region: " . $region . "<P>\n";
// this section is a previous attempt to update and is commented out
//$update1 = mysql_query("UPDATE ycdest SET text='$text' WHERE name='$edit_line'");
//$update2 = mysql_query("UPDATE ycdest SET desc='$desc' WHERE name='$edit_line'");
//$update3 = mysql_query("UPDATE ycdest SET key='$key' WHERE name='$edit_line'");
//$update4 = mysql_query("UPDATE ycdest SET region='$region' WHERE name='$edit_line'");
//$update5 = mysql_query("UPDATE ycdest SET name='$name' WHERE name='$edit_line'");
//the most recent attempt to update, getting syntax error at line with $update1
$update5 = "UPDATE ycdest SET text = '$text' WHERE name = '$edit_line'";
$result5 = mysql_query($update) or die(sql_error());
$update1 = "UPDATE ycdest SET desc = '$desc' WHERE name = '$edit_line'";
$result1 = mysql_query($update1) or die(sql_error());
$update2 = "UPDATE ycdest SET key = '$key' WHERE name = '$edit_line'";
$result2 = mysql_query($update2) or die(sql_error());
$update3 = "UPDATE ycdest SET region = '$region' WHERE name = '$edit_line'";
$result3 = mysql_query($update3) or die(sql_error());
$update4 = "UPDATE ycdest SET name = '$name' WHERE name = '$edit_line'";
$result4 = mysql_query($update4) or die(sql_error());
// this section shows the database records after the update to confirm if it worked
echo "After Update<p>\n";
$query = "SELECT * FROM ycdest WHERE name='$name'";
$result = mysql_query($query) or die("Query failed");
while($row = mysql_fetch_row($result))
{
print "<table>\n";
print "<tr><td>$row[0]</td></tr>\n";
print "<tr><td>$row[1]</td></tr>\n";
print "<tr><td>$row[2]</td></tr>\n";
print "<tr><td>$row[3]</td></tr>\n";
print "<tr><td>$row[4]</td></tr>\n";
print "<tr><td>$row[5]</td></tr>\n";
print "</table>\n";
}