Jump to content

God damned mistakes


Noskiw

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.