Tjobbe
June 12th, 2007, 18:10
I'm using a Web based form with php to update a mysql database, and on updating I get the following error message, even though the update works!
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/frantik1/public_html/sitecreative/clients/pl/cms/admin/edit_news_store.php on line 30
update ok
I'm using this page with the form;
<?php
include "../admin/dbconnect.php";
$id = $_GET['id'];
?>
<form action="edit_news_store.php?action=update&id=<?php echo $id ?>" method="POST">
<?php
if (!preg_match("#^\d+$#", $id)) {
// maybe die here with an error
}
$query= "SELECT * FROM news WHERE id = '$id'";
$r= mysql_query($query) OR die('Query error: ' .mysql_error());
if (mysql_num_rows($r) == 0) {
}
$row= mysql_fetch_assoc($r);
echo 'Title<br />
<input name="title" id="title" value="'.$row['title'].'" size="80" />';
echo "<br /><br />";
echo 'Short description<br />
<input name="source" id="source" value="'.$row['source'].'" size="80" />';
echo "<br /><br />";
echo 'Source<br />
<input name="shortdescr" id="shortdescr" value="'.$row['shortdescr'].'" size="80" />';
echo "<br /><br />";
echo 'Date<br />
<input name="date" id="date" value="'.$row['date'].'" size="80" />';
echo "<br /><br />";
echo 'Article<br />
<textarea name="content" cols="60" rows="20" id="content" style="margin:0; padding:0; border-top:2px solid #333333;">'.$row['content'].'</textarea>';
mysql_close();
?>
<br /><br />
<input type="submit" value="Update Article" />
</FORM>
which gets sent to this page:
<?php
include "dbconnect.php";
$id = $_GET['id'];
$title = $_POST['title'];
$content = $_POST['content'];
$query = "UPDATE news SET title='". $title ."', content = '". $content ."' WHERE id = '$id'";
$r= mysql_query($query) OR die('Query error: ' .mysql_error());
if (mysql_affected_rows($r) == 0) {
echo "update ok";
} else {
echo 'update succesful1!';
}
mysql_close();
?>
Any ideas on how I can get rid of that error message?
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/frantik1/public_html/sitecreative/clients/pl/cms/admin/edit_news_store.php on line 30
update ok
I'm using this page with the form;
<?php
include "../admin/dbconnect.php";
$id = $_GET['id'];
?>
<form action="edit_news_store.php?action=update&id=<?php echo $id ?>" method="POST">
<?php
if (!preg_match("#^\d+$#", $id)) {
// maybe die here with an error
}
$query= "SELECT * FROM news WHERE id = '$id'";
$r= mysql_query($query) OR die('Query error: ' .mysql_error());
if (mysql_num_rows($r) == 0) {
}
$row= mysql_fetch_assoc($r);
echo 'Title<br />
<input name="title" id="title" value="'.$row['title'].'" size="80" />';
echo "<br /><br />";
echo 'Short description<br />
<input name="source" id="source" value="'.$row['source'].'" size="80" />';
echo "<br /><br />";
echo 'Source<br />
<input name="shortdescr" id="shortdescr" value="'.$row['shortdescr'].'" size="80" />';
echo "<br /><br />";
echo 'Date<br />
<input name="date" id="date" value="'.$row['date'].'" size="80" />';
echo "<br /><br />";
echo 'Article<br />
<textarea name="content" cols="60" rows="20" id="content" style="margin:0; padding:0; border-top:2px solid #333333;">'.$row['content'].'</textarea>';
mysql_close();
?>
<br /><br />
<input type="submit" value="Update Article" />
</FORM>
which gets sent to this page:
<?php
include "dbconnect.php";
$id = $_GET['id'];
$title = $_POST['title'];
$content = $_POST['content'];
$query = "UPDATE news SET title='". $title ."', content = '". $content ."' WHERE id = '$id'";
$r= mysql_query($query) OR die('Query error: ' .mysql_error());
if (mysql_affected_rows($r) == 0) {
echo "update ok";
} else {
echo 'update succesful1!';
}
mysql_close();
?>
Any ideas on how I can get rid of that error message?