Help - Search - Members - Calendar
Full Version: [resolved] Updating Information
Codegrrl.com Forums > Script Help > Tutorial Help
Paint
I've edited the BAB coding to work with a website I am building to let people place information so that people that are looking for some kind of artwork done for a game, then they can look there. Now, I've done everything else right. I've got a form to add your information, and a page to where you can view it. I even got the pagination to work (after hours of tweaking) =P The only thing I can't get is the admin update page to work. Below is the code, maybe one of you guys or gals can find where I messed up at.

CODE

<?php
mysql_connect ('localhost', '****', '****');
mysql_select_db ('****');

if (isset($_POST['update'])) {
    $id = (int)$_POST['id'];

    $id = htmlspecialchars(strip_tags($_POST['id']));
    $name = htmlspecialchars(strip_tags($_POST['name']));
    $email = htmlspecialchars(strip_tags($_POST['email']));
    $site = htmlspecialchars(strip_tags($_POST['site']));
    $info = $_POST['info'];

    $info = nl2br($info);

    if (!get_magic_quotes_gpc()) {
        $title = addslashes($title);
        $info = addslashes($info);
    }

    $result = mysql_query("UPDATE fas_portrait SET name='$name', email='$email', site='$site', info='$info', WHERE id='$id'") or print ("Can't update info.<br />" . mysql_error());

}
if (!isset($_GET['id']) || empty($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Invalid info ID.");
}
else {
    $id = (int)$_GET['id'];
}

$result = mysql_query ("SELECT * FROM fas_portrait WHERE id='$id'") or print ("Can't select info.<br />" . $sql . "<br />" . mysql_error());

while ($row = mysql_fetch_array($result)) {
    $old_title = stripslashes($row['title']);
    $old_info = stripslashes($row['info']);
    $old_name = $row['name'];
    $old_email = $row['email'];
    $old_site = $row['site'];

    $old_title = str_replace('"','\'',$old_title);
    $old_info = str_replace('<br />', '', $old_info);

}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<p><input type="hidden" name="id" value="<?php echo $id; ?>" />


<strong><label for="name">Name:</label></strong> <input type="text" name="name" id="name" size="40" value="<?php echo $old_name; ?>" /></p>

<p><strong><label for="email">Email:</label></strong> <input type="text" name="email" id="email" value="<?php echo $old_email; ?>" size="40" /> </p>

<p><strong><label for="site">Website:</label></strong> <input type="text" name="site" id="site" value="<?php echo $old_site; ?>" size="40" /> </p>

<p><strong><label for="info">Information:</label></strong><br />
<textarea cols="80" rows="20" name="info" id="info"><?php echo $old_info; ?></textarea></p>

<p><input type="submit" name="update" id="update" value="Update"></p>

</form>

<?php

mysql_close();

?>


Now, the error I'm getting is this:

CODE
Can't update info.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='1'' at line 1Invalid info ID.


It's exactly like that. I finally got everything to show, but now I cannot edit it from the admin panel. Any help would be appreciated.
Amelie
Try changing this:

CODE
$result = mysql_query("UPDATE fas_portrait SET name='$name', email='$email', site='$site', info='$info', WHERE id='$id'"


To this:

CODE
$result = mysql_query("UPDATE fas_portrait SET name='$name', email='$email', site='$site', info='$info' WHERE id='$id'"


You have an extra comma before the WHERE part.
Paint
Thanks, Amelie! I didn't see that. Now I just need to figure out how to get the "Invalid info ID" error to go away and maybe make a redirect to go back to the admin panel. I can more than likely figure that out by grabbing more from another code.

Edit: I got the redirect to go back to the list.

Edit 2: Fixed everything. Now I don't get the error.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.