View Full Version : update database script doesn't work

10-06-2011, 11:36 PM
I'm completely stumped and going cross-eyed. I'm trying to add a second field for "bio" to edit in this script, but it doesn't work. It pulls the information from the database fine. but when I submit the changes, it only takes numeric entries... and puts " 0nbsp; " at the end of it. I want text. The other field above it works just fine. If I submit without making changes, it clears the text and leaves just the "0nbsp"

script one is the function on the included php

public function update_auth1($auth1ID, $description, $bio) {
$description = $this->real_escape_string($description);
if ($bio==''){
$this->query("UPDATE auth1es SET description = '" . $description . "',
bio = NULL WHERE id = " . $auth1ID);
} else
$this->query("UPDATE auth1es SET description = '" . $description .
"', bio = " . $bio
. " WHERE id = " . $auth1ID);

Here's the script on the page where I'm viewing and trying to edit info



/** Checks whether the element with the "auth1" key in the $_POST array is empty,
* which means that no description was entered.
*/ else if ($_POST['auth1'] == "") {
$auth1DescriptionIsEmpty = true;
/** The "auth1" key in the $_POST array is NOT empty, so a description is entered.
* Adds the auth1 description and the bio to the database via auth1DB.insert_auth1
*/ else if ($_POST['auth1ID'] == "") {
auth1DB::getInstance()->insert_auth1($authorID, $_POST['auth1'], $_POST['bio']);
header('Location: editAuth1List.php');
} else if ($_POST['auth1ID'] != "") {
auth1DB::getInstance()->update_auth1($_POST['auth1ID'], $_POST['auth1'], $_POST['bio']);
header('Location: editAuth1List.php');
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
$auth1 = array("id" => $_POST['auth1ID'],
"description" => $_POST['auth1'],
"bio" => $_POST['dueDate']);
else if (array_key_exists("auth1ID", $_GET)) {
$auth1 = mysqli_fetch_array(auth1DB::getInstance()->get_auth1_by_auth1_id($_GET['auth1ID']));
} else
$auth1 = array("id" => "", "description" => "", "bio" => "");
<form name="editauth1" action="editAuth1.php" method="POST">
<input type="hidden" name="auth1ID" value="<?php echo $auth1['id']; ?>" />
Author: <input type="text" name="auth1" value="<?php echo $auth1['description']; ?>" /><br>
<input type="text" name="bio" value="<?php echo $auth1['bio']; ?>" />

if ($auth1DescriptionIsEmpty)
echo "Please enter description<br/>";
Bio: <br/>

<input type="submit" name="saveauth1" value="Save Changes"/>


10-07-2011, 12:26 AM
In your MySQL database, what is the column type? it should be VARCHAR.
You probably set it to INT (integer).

You can change it if you get into your MySQL admin via your webhost control panel.

EDIT ...

What is this? "bio" => $_POST['dueDate']);

Should it be:
"bio" => $_POST['bio']);

10-07-2011, 12:36 AM
I checked the mysql and it's a varchar field. I've entered varchar data into it through mysql, so I knew that part was fine.

I caught the 'duedate' text, and fixed it, but still nothing.

10-07-2011, 12:47 AM
How about missing single quotes around "bio" ...

I added them here ...

$this->query("UPDATE auth1es SET description = '" . $description .
"', bio = '" . $bio
. "' WHERE id = " . $auth1ID);

10-07-2011, 01:25 AM
hallelujah! That did it!

10-07-2011, 01:39 AM
whew! sometimes I can't see the forest, for the trees block my view.