Jump to content

Recommended Posts

<?php
function update_content_form($id){
        $id = mysql_real_escape_string($id);
        $sql = "SELECT * FROM cms_content WHERE id='" . $id . "'";
        $res = mysql_query($sql) or die(mysql_error());
        $row = mysql_fetch_assoc($res);
?>
<form method="POST" action="index.php">
<input type="hidden" name="update" value="true" />
<input type="hidden" name="id" value="<?php $row['id'] ?>" />
<div>
<label for="title">Title:</label>
<input type="text" name="title" id="title" value="<?php $row['title'] ?>" />
</div>
<div>
<label for="body">Body:</label>
<textarea name="body" id="body" rows="8" cols="40"><?php $row['body'] ?></textarea>
</div>
<input type="submit" name="submit" value="Edit" />
</form>
<?php
    }
}

?>

 

What I'm trying to do is edit a post. Yet when I go to the update-content section, there's nothing there. I'm guessing my SQL query sucks.

Link to comment
https://forums.phpfreaks.com/topic/200447-god-damned-mistakes/
Share on other sites

Make sure you call the function and pass the ID correctly.

I notice you have two closing tags. 1 is closing.. absolutely nothing.

 

<?php
function update_content_form($id){
$id = mysql_real_escape_string($id);
$res = mysql_query("SELECT * FROM cms_content WHERE id='$id'") or die(mysql_error());
$row = mysql_fetch_assoc($res);

return '<form method="POST" action="index.php">
	<input type="hidden" name="update" value="true" />
	<input type="hidden" name="id" value="' . $row['id'] . '" />

	<div>
		<label for="title">Title:</label>
		<input type="text" name="title" id="title" value="' . $row['title'] . '" />
	</div>

	<div>
		<label for="body">Body:</label>
		<textarea name="body" id="body" rows="8" cols="40">' . $row['body'] . '</textarea>
	</div>

	<input type="submit" name="submit" value="Edit" />
</form>';
}

$id = $_GET['id']; //Get the ID from the URL
echo update_content_form($id);
?> 

Link to comment
https://forums.phpfreaks.com/topic/200447-god-damned-mistakes/#findComment-1051897
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.