Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    update database script doesn't work

    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

    PHP Code:
      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
    PHP Code:
    <?php

    require_once("Includes/db.php");


        
    /** 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');
            exit;
        } else if (
    $_POST['auth1ID'] != "") {
            
    auth1DB::getInstance()->update_auth1($_POST['auth1ID'], $_POST['auth1'], $_POST['bio']);
            
    header('Location: editAuth1List.php');
            exit;
        }
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>
        <body>
            <?php
            
    if ($_SERVER['REQUEST_METHOD'] == "POST")
                
    $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']; ?>" />

           <br/>
                <?php
                
    if ($auth1DescriptionIsEmpty)
                    echo 
    "Please enter description<br/>";
                
    ?>
                Bio: <br/>
                <br/>
               
               
                
                <input type="submit" name="saveauth1" value="Save Changes"/>

            </form>
        </body>
    </html>
    Last edited by turpentyne; 10-06-2011 at 11:25 PM.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    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']);
    Last edited by mlseim; 10-06-2011 at 11:28 PM.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts
    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.

  • #4
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    How about missing single quotes around "bio" ...

    I added them here ...

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

  • Users who have thanked mlseim for this post:

    turpentyne (10-07-2011)

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts
    hallelujah! That did it!

  • #6
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    whew! sometimes I can't see the forest, for the trees block my view.


  •  

    Posting Permissions

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