SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Location
    UK
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Edit file resets database fields to nothing when submitting updates

    I have recently finished creating a content management system for a website. It works perfectly apart form one thing: one of the fields in the database keeps reseting to nothing whenever I use the edit file I created to update the database.

    The cms I have made consists of:
    • a page with the list of group members
    • an add member page
    • an edit member page
    • and a delete member page.


    Inserting the information with the add member page isn't a problem. All the information goes into the right places, etc. However, if I try to update the information with my edit member page, one of the fields is always reset to blank. Basically by clicking the submit form button, it updates all the other field and resets this one field to nothing. In fact the only way I can re-input the information is to go into myPHPAdmin and do it from there. Not ideal!

    I had thought that trying to set the field to NOT_NULL might do it but I'm unsure as how to do it without having to creating the table all over again (if it is even possible). Would that work?

    Here's the code for the troublesome page anyway. The field that keeps reseting is called oocname.

    PHP Code:
    <?php

    // connect to mysql server and database
    include 'db.inc.php';

    if (!
    get_magic_quotes_gpc()) {
        
    $_GET array_map('addslashes'$_GET);
        
    $_POST array_map('addslashes'$_POST);
        
    $_COOKIE array_map('addslashes'$_COOKIE);
        
    $_REQUEST array_map('addslashes'$_REQUEST);
    }

    // the author's details have been updated.
    if (isset($_POST['name'])) {
    $name $_POST['name'];                                            
    $oocname $_POST['oocname'];
    $position=$_POST['position'];
    $skills=$_POST['skills'];
    $bio=$_POST['bio'];
    $ordoid=$_POST['ordoid'];        
    $id $_POST['id'];

    // Convert Windows (\r\n to Unix (\n)
    $bio ereg_replace("\r\n""\n"$bio);
    // Convert Macintosh (\r) to Unix (\n)
    $bio ereg_replace("\r""\n"$bio);
    // Handle Paragraphs
    $bio ereg_replace("\n\n"'</p><p>'$bio);
    // Handle Line Breaks
    $bio ereg_replace("\n"'<br />'$bio);

    $sql "UPDATE member SET 
            name='
    $name', 
            oocname='
    $oocname', 
            position='
    $position',
            skills='
    $skills',
            bio='
    $bio',
            ordoid='
    $ordoid'
            WHERE id='
    $id'";

    if (@
    mysql_query($sql)) {
    echo 
    '<p>Member details updated.</p>';
    } else {
    echo 
    '<p>Error updating member details: ' mysql_error() . '</p>';
    }
    } else {
    $id $_GET['id'];
    $member = @mysql_query("SELECT name, oocname, position, skills, bio, ordoid FROM member WHERE id='$id'");
    if (!
    $member) {
    exit(
    '<p>Error fetching member details: ' mysql_error() . '</p>');
    }


    $member mysql_fetch_array($member);

    $name $member['name'];                                        
    $oocname $member['oocname'];
    $position=$member['position'];
    $skills=$member['skills'];
    $bio=$member['bio'];
    $ordoid=$member['ordoid'];        

    // Convert special characters for safe use
    // as HTML attributes
    $name htmlspecialchars($name);
    $oocname htmlspecialchars($oocname);
    $position htmlspecialchars($position);
    $skills htmlspecialchars($skills);
    $bio htmlspecialchars($bio);
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <p>Edit the member:<br />
    <label>Name: <input type="text" name="name" value="<?php echo $name?>" /></label><br />
    <label>OOC Name: <input type="text" name="email" value="<?php echo $oocname?>" /></label><br />
    <label>Position: <input type="text" name="position" value="<?php echo $position?>" /></label><br />
    <label>Order: <select name="ordoid" size="1">
    <option value="1">Militas</option>
    <option value="2">Spiritas</option>  
    <option value="3">Clericus</option> 
    </select></label><br />
    <label>Skills: <input type="text" name="skills" value="<?php echo $skills?>" /></label><br />
    Biography:<br />
    <textarea name="bio" cols="45" rows="5"><?php echo $bio?></textarea><br />
    <input type="hidden" name="id" value="<?php echo $id?>" />
    <input type="submit" value="SUBMIT" />
    </form></p>

    <?php
    }
    ?>
    Meep.
    Cynical Matrix - dumping ground for a self-confessed geek

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The input for oocname is named "email".
    Last edited by Dan Grossman; May 14, 2007 at 14:45.

  3. #3
    SitePoint Member
    Join Date
    Feb 2007
    Location
    UK
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I didn't spot that. It's always the little things, isn't it?
    Meep.
    Cynical Matrix - dumping ground for a self-confessed geek


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •