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 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2005
    Location
    TN
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wrong values being inserted?

    I have this script that is supossed to change the pet image to $image and the growth to '2' but for some reason it sets the image to '0' and doesn't do anything to the growth. I have rewriten the script 3 times and I just can't see what is wrong. Please tell me what I'm missing. Thanks in advance!

    PHP Code:
    <?
    //connection information
    $db_name "DBNAME";
    $connection mysql_connect('SERVER''NAME''PASS') or die($connection);
    $db mysql_select_db($db_name$connection) or die("Couldn't select Database1.");
    $connection2 $connection;

    //sets the growday

    $growday date("M d Y");

    //selects pets that are ready to grow

    $pet_sql "SELECT * FROM starbits WHERE growday = '$growday' AND growth = '1'";
        
    $pet_result mysql_query($pet_sql);
        
    if (
    mysql_num_rows($pet_result)) {
    while (
    $pet mysql_fetch_array($pet_result)) {

    //set some variables so table can be updated

    $petID $pet['monopetID'];
    $petimage $pet['image'];

    //set $image value

    if ($petimage == 'baby_chari') {
    $petimage "chari";
    }
    if (
    $petimage == 'baby_flif') {
    $petimage "flif";
    }
    if (
    $petimage == 'baby_fool') {
    $petimage "fool";
    }
    if (
    $petimage == 'baby_kakineko') {
    $petimage "kakineko";
    }
    if (
    $petimage == 'baby_kijuu') {
    $petimage "kijuu";
    }
    if (
    $petimage == 'baby_swimo') {
    $petimage "swimo";
    }
    if (
    $petimage == 'baby_ghostling') {
    $petimage "ghostling";
    }
    if (
    $petimage == 'baby_tsuki') {
    $petimage "tsuki";
    }

    //start updating

    $grow_sql "UPDATE starbits SET image = '$petimage' AND growth = '2' WHERE monopetID = '$petID'";
        
    $grow_result mysql_query($grow_sql) or die("Error:" .mysql_error());
        
    echo 
    "Script Ran.";
    }
    }
    //to make sure I didnt leave out any } or anything,
    // and to double check the date
    echo "<p>$growday";
    ?>

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your SQL is incorrect.

    Fixed:
    PHP Code:
    $grow_sql "UPDATE starbits SET image = '$petimage', growth = '2' WHERE monopetID = '$petID'"
    You just have to comma separate the columns you're updating. AND doesn't work properly.
    "$question = ( to() ) ? be() : ~be();"

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    everything looks fine to me (clean writing, you could use a switch and a function though for the if statements), all i can say is trying echo out $petimage to see what it is pulling from the database

    ^^
    edit:
    Yep, he found it

  • #4
    New Coder
    Join Date
    Jul 2005
    Location
    TN
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, let me see if that works.

  • #5
    New Coder
    Join Date
    Jul 2005
    Location
    TN
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When I use the comma in my sql, a blank page shows up.

  • #6
    New Coder
    Join Date
    Jul 2005
    Location
    TN
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh wait, nevermind! Thanks so much! ^-^

  • #7
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    For your renaming,
    PHP Code:
    $petImage=str_replace('baby_','',$petImage); 
    Looks like it might work? (unless there are some 'babies' that you don't want replaced I suppose...)


  •  

    Posting Permissions

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