www.webdeveloper.com
Results 1 to 3 of 3

Thread: trying to update

  1. #1
    Join Date
    Apr 2013
    Location
    gastonia NC
    Posts
    92

    trying to update

    Hello all, I have this one record database file used to hold several last used values, I've confirmed validity of the record. I don't get an error so ....? Will someone take look at this feeble attempt and advise?
    thanks in advance!
    :
    PHP Code:
    <?php 
    // error_reporting(0);
    error_reporting(E_ALL E_NOTICE); 
    mysql_connect("localhost","root",""); 
    mysql_select_db("numbersdb") or die( "Unable to select database"); 
    if(!empty(
    $_POST["submit"])) 

     
    $taxrate $_POST['taxrate']; 
     
    $query="SELECT * FROM numbdata Where id='$id'"
     
    $result=mysql_query($query); 
     if(
    mysql_num_rows($result)) 
     {  
    }else{echo 
    "No listing for taxrate $taxrate .<br />Select another? .<br />";} 

    if(!empty(
    $_POST["update"])) 

    $sql "UPDATE numbdata SET 
    taxrate = '" 
    .mysql_real_escape_string($_POST['taxrate']) . "', 
    WHERE taxrate='"
    .$_POST['taxrate']."'"
    mysql_query($sql) or die(mysql_error());
     echo 
    "Record for taxrate ".$_POST["taxrate"]." has been updated"
     } 
    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    868
    Perhaps it is because you grab the 'taxrate' input value but do a query on whatever the value of $id is? Should that be perhaps '$taxrate'?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,604
    See comments...
    PHP Code:
    <?php
    // error_reporting(0);
    // get rid of "^ E_NOTICE" for now, might get useful info <---------<<<<<<<
    error_reporting(E_ALL E_NOTICE);
    mysql_connect("localhost""root""");
    mysql_select_db("numbersdb") or die("Unable to select database");
    if (!empty(
    $_POST["submit"])) 
    {
        
    $taxrate $_POST['taxrate'];
        
    // where is $id set?  <---------------<<<<<<<<<<<<<<<<<<<<<
        
    $query "SELECT * FROM numbdata Where id='$id'"
        
    $result mysql_query($query);
        if (
    mysql_num_rows($result)) 
        {
        }
        else
        {
            echo 
    "No listing for taxrate $taxrate .<br />Select another? .<br />";
        }
    }
    if (!empty(
    $_POST["update"])) 
    {
        
    // why set taxrate to value where taxrate already equals value?  <---<<<<<
        
    $sql "UPDATE numbdata SET
    taxrate = '" 
    mysql_real_escape_string($_POST['taxrate']) . "',
    WHERE taxrate='" 
    $_POST['taxrate'] . "'";
        
    mysql_query($sql) or die(mysql_error());
        
    // query can succeed yet not update anything if no match for WHERE
        // might want to check mysql_affected_rows() to see if anything
        // was actually updated   <-----------------------<<<<<<<<<
        
    echo "Record for taxrate " $_POST["taxrate"] . " has been updated";
    }
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles