/    Sign up×
Community /Pin to ProfileBookmark

Help with Editing content from MySQL Database

I have this code but whenever i enter an id of an entry to edit I get this error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/refresh/public_html/blog-edit.php on line 30

I know I am entering an ID that exists

[code=php]
<?
global $pageTitle;
$pageTitle=”ComplexFellow.com::Edit Entry”;
include(“header.php”);
?>
<div class=”content”>
<form action=”<?$_SERVER[‘PHP_SELF’];?>” method=”post”>
<div>
<?
$un = “”;
$pass = “”;
$db = “”;
$host = “”;
$sql = mysql_connect($host, $un, $pass) or die(mysql_error());
if($submit==””)
{
?>
<form action=”<?$_SERVER[‘PHP_SELF’];?>” method=”post”>
Enter ID of entry to edit
<br />
<input type=”text” name=”ID” /><br />
<input type =”submit” name=”submit” value=”submit” class=”submit” />
</form>
</div>
<?
}
elseif($submit !=””)
{
$ID=$_POST[‘ID’];
$query = “SELECT * FROM blog WHERE ID='”.$ID.”‘”;
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$id=$row[‘ID’];
$content=$row[‘content’];
$title=$row[‘title’];
?>
<div>
<form action=”<?$_SERVER[‘PHP_SELF’];?>” method=”post”>
<?
echo”<input type=’text’ name=’blogtitle’ value=$blogtitle />”;
echo”<textarea rows=’20’ cols=’50’ name=’blogcontent’>$content</textarea>”;
echo'<input type =”submit” name=”edit” value=”Edit!” class=”submit” /></form></div>’;
$query = “UPDATE `blog` SET `content` = ‘$blogcontent’ WHERE `ID` = ‘$id’ LIMIT 1”;

}
}
?>

<?include(“footer.php”);?>
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@solavarMay 13.2004 — Try using the $_POST['submit'] instead. If register_globals = "off", you can't just start using $submit without extracting it from the $_POST superglobal.

So your modified statements will look like this:

[code=php]
$sql = mysql_connect($host, $un, $pass) or die(mysql_error());
if(! $_POST['submit']) // instead of if($submit == "")
{
// etc

[/code]
Copy linkTweet thisAlerts:
@ConorauthorMay 13.2004 — same result. Im positive I have superglobals on as well.
Copy linkTweet thisAlerts:
@solavarMay 14.2004 — Strange problem Refresh5.

I'll have a closer look and see if I spot anything.
Copy linkTweet thisAlerts:
@ConorauthorMay 14.2004 — perhaps theres a problem with my query?
×

Success!

Help @Conor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...