View Full Version : Wrong values being inserted?

01-03-2006, 09:09 PM
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!

//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";

Velox Letum
01-03-2006, 09:16 PM
Your SQL is incorrect.


$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.

01-03-2006, 09:17 PM
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

Yep, he found it

01-03-2006, 09:19 PM
Thanks, let me see if that works.

01-03-2006, 09:22 PM
When I use the comma in my sql, a blank page shows up.

01-03-2006, 09:30 PM
Oh wait, nevermind! Thanks so much! ^-^

01-03-2006, 11:12 PM
For your renaming,


Looks like it might work? (unless there are some 'babies' that you don't want replaced I suppose...)