Jump to content

[SOLVED] changing data in a db


S A N T A

Recommended Posts

ok so I'm working on a blog and im adding the edit button but for some reason when i click the "Update Entry!" button it goes to the right page and everything but it doesn't update it?

 

heres the code:

 

<?php

session_start();

require("config.php");

if(isset($_SESSION['USERNAME']) == FALSE) {
header("Location: " . $config_basedir);
}

$db = mysql_connect($dbhost, $dbuser);
mysql_select_db($dbdatabase, $db);

if(isset($_GET['id']) == TRUE) {
if(is_numeric($_GET['id']) == FALSE) {
$error = 1;
}



if($error == 1) {
header("Location: " . $config_basedir);
}
else {
$validentry = $_GET['id'];
}
}
else {
$validentry = 0;
}

if($_POST['submit']) {
$sql = "UPDATE entries SET cat_id = " . $_POST['cat'] . ", sebject = '" . $_POST['subject'] ."', body = '" . $_POST['body'] . "' WHERE id = " . $validentry . ";";
mysql_query($sql);

header("Location: " . $config_basedir . "/viewentry.php?id=" . $validentry);
}
else {

require("header.php");

$fillsql = "SELECT * FROM entries WHERE id = " . $validentry . ";";
$fillres = mysql_query($fillsql);
$fillrow = mysql_fetch_assoc($fillres);

?>

<h1>Update entry</h1>

<form action="<?php echo $SCRIPT_NAME . "?id=" . $validentry; ?>" method="post">

<table>
<tr>
<td>Category</td>
<td>
<select name="cat">
<?php
	$catsql = "SELECT *FROM categories;";
	$catres = mysql_query($catsql);
	while($catrow= mysql_fetch_assoc($catres)) {
		echo "<option value='" . $catrow['id'] . "'";

if($catrow['id'] == $fillrow['cat_id']) {
	echo " selected";
}

echo ">" . $catrow['cat'] . "</option>";
}
?>
</select>
</td>
</tr>

<tr>
<td>Subject</td>
<td><input type="text" name="subject" value="<?php echo $fillrow['subject']; ?>">
</td>
</tr>
<tr>
<td>Body</td>
<td><textarea name="body" rows="10" cols="50"><?php echo $fillrow['body']; ?></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Update Entry!"></td>
</tr>
</table>
</form>
<?php
}
require("footer.php");
?>

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/103294-solved-changing-data-in-a-db/
Share on other sites

always always always put the

 

or die ("Error in query " . mysql_error());

 

on the end of your query execution call, it points the way to so many silly little faults like this one (silly little faults incorporate spelling errors, wrong punctuation and the like)

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.