Read and write to same table
Posted: Wed Jul 05, 2006 2:40 am
Hi,
I have got the following code that is supposed to take each record from the table, split up the dd/mm/yyyy date into three variables and add a username, then add these back to the same table:
It alsways comes up with these errors:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\server\Apache2\htdocs\tops\dateup.php on line 32
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\server\Apache2\htdocs\tops\dateup.php on line 79
I'm not sure what these mean or whatcouldbewrong with the code. Any ideas?
Thanks,
Tom
I have got the following code that is supposed to take each record from the table, split up the dd/mm/yyyy date into three variables and add a username, then add these back to the same table:
Code: Select all
<html>
<head>
<basefont face="Arial">
</head>
<body>
<?php
// set database server access variables:
$host = "localhost";
$user = "****";
$pass = "******";
$db = "tops";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM sighting1";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
while(list($number, $date, $location) = mysql_fetch_row($result)) {
list($day, $month, $year) = split('[/.-]', $date);
$sluser = "tom91";
//................................................................................................//
// open connection
$connection1 = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "INSERT INTO sighting1 (number, date_seen, location, day, month, year, user) VALUES ('$number', '$date', '$location', '$day', '$month', '$year', '$sluser')";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// print message with ID of inserted record
echo "New record inserted with ID ".mysql_insert_id();
// close connection
mysql_close($connection);
}
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
</body>
</html>Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\server\Apache2\htdocs\tops\dateup.php on line 32
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\server\Apache2\htdocs\tops\dateup.php on line 79
I'm not sure what these mean or whatcouldbewrong with the code. Any ideas?
Thanks,
Tom