SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot cherie's Avatar
    Join Date
    Nov 2004
    Location
    Roxbury, NY
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hardcode ID into update function

    I am building a CMS for a client to be able to update pages.

    I have a bio table in the mysql database with 7 fields. As there is only one bio I have put in an id of 01 for the bio.

    When writing the update function I am attempting to hard code the id into the function as there is only one id.

    This is my update code

    Code PHP:
    <?php
    //Update database
    $query_updateBio = "UPDATE bio SET headline='".$_POST['headline']."', bio_body='".$_POST['bio_body']."', bio_byline='".$_POST['bio_byline']."', headline_long='".$_POST['headline_long']."', bio_body_long='".$_POST['bio_body_long']."', bio_long_byline='".$_POST['bio_long_byline']."' WHERE bio_id="['01'];
    $updateBio = mysql_query($query_updateBio);
     
    header("Location: ../index.php");
    ?>


    Am I going about the thought process of the ID the wrong way or do I have the ID coded into the update query incorrect?

    Any advice would be appreciated.
    Cherie
    foamyindustries.com
    Movies We Watch - we watch it and tell you what we think
    chickenflicker.com - everyone needs a chicken a day

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Probably both. For start:
    Code php:
    <?php
    //Update database
    $query_updateBio = "UPDATE bio SET 
    headline='".mysql_real_escape_string($_POST['headline'])."', 
    bio_body='".mysql_real_escape_string($_POST['bio_body'])."', 
    bio_byline='".mysql_real_escape_string($_POST['bio_byline'])."', 
    headline_long='".mysql_real_escape_string($_POST['headline_long'])."', 
    bio_body_long='".mysql_real_escape_string($_POST['bio_body_long'])."', 
    bio_long_byline='".mysql_real_escape_string($_POST['bio_long_byline'])."' 
    WHERE bio_id='01'";
     
    $updateBio = mysql_query($query_updateBio);
     
    header("Location: ../index.php");
    ?>

    But I tend insist you to drop the idea of hard coded id. Yes, there might be only one bio, but you can save different versions. Select the latest version to display and add any changes as a new record. That would make your code more flexible and your client happier -- they would be able to roll back any changes at any time!
    Saul


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
  •