Page 1 of 2
Quick easy error, php xperts help!
Posted: Thu Jun 19, 2003 2:33 pm
by I3lade
Please help me fix this quick error:
Code: Select all
<?
session_start();
if($havepet==1){
?>
You already have a pet, you cannot create another!
<?
}else{
printf("<?
mysql_connect("localhost","bladegames", "****");
mysql_select_db("bladegames");
session_start();
$id=$row->userid;
session_register("$userid");
if($submit=="Create my pet")
{
mysql_query("UPDATE bb1_user_table SET petname = '$petname', pet = '$pet', pic = '$pic', hp = '10', maxhp = '10', str = '7', def = '5', speed = '8', lv = '1', intl = '6'
WHERE userid = '$user_id'");
}
You have choosen Belron!
Belron is a Crocodile-like ZeoPet. Enter/View some information below about your pet:
<form method=post action="Belron.php">
</head>
<b>
<br>
Pet Name
<br>
</b>
<input type=text size=15 name="petname">
<br>
<b>
<br>
Pet Type
<br>
</b>
<select name="pic">
<option value="Belron.bmp">Belron</option>
</select>
<br>
<b>
<br>
Pet Color
<br>
</b>
<select name="pet">
<option value="Belron">Green</option>
</select>
<br>
<input type=submit name=submit value="Create my pet">
<input type=reset name=reset value="Clear">
<br><br>
</form>
<br><br>
<hr>
<font color="red" size=3><center><u>Belron's Stats</u></center></font><br>
<font color="black">Level:<font color="green">1<br>
<font color="black">Hp:<font color="green">10<br>
<font color="black">Strength:<font color="green">7<br>
<font color="black">Defense:<font color="green">5<br>
<font color="black">Speed:<font color="green">8<br>
");
}
?>
I think it's the printf("<? but don't know how to fix it , if you could paste the code with the correction in it, thanks.
Posted: Thu Jun 19, 2003 2:50 pm
by I3lade
Please help, thanks.
Posted: Thu Jun 19, 2003 3:26 pm
by daven
This should work fine. A few notes:
1. If you are going to be outputting a lot of HTML, it is usually easier to exit/re-enter php instead of doing an echo/print.
2. If you are going to be printing a lot, check out the heredoc syntax for strings (in the manual somewhere)
3. You cannot print mysql commands or PHP commands if you expect them to work.
Code: Select all
<?
print "mysql_connect()"; // this just outputs the string "mysql_connect()" to the browser
mysql_connect(); // this will actually run
?>
4. Make sure you are using the proper session/form variables for the version of php you are using. PHP >4.1.0 uses superglobals, such as $_SESSION[] and $_POST[]. Side note: I strongly suggest using the $_POST[] or $HTTP_POST_VARS[] when accessing post form variables
5. session_start() must be at the top of your script, or it will not work
6. I suggest learning how to use cascading style sheets (CSS) for your HTML. It makes your code much better and also permits easier modification in the future.
7. If register_globals is off in php.ini, you cannot use session_register. You will have to use $_SESSION[] or $HTTP_SESSION_VARS[] (depending upon your PHP version
Enjoy
Code: Select all
<?session_start();
if($havepet==1){
echo "You already have a pet, you cannot create another!";
}else{
mysql_connect("localhost","bladegames", "****");
mysql_select_db("bladegames");
$id=$row->userid;
// if you are using PHP >4.1, do not use session_register. Do a $_SESSION['userid']=$userid
// If you are using PHP<4.1, use session_register('userid'). The var name, not the $var itself
session_register("userid");
if($submit=="Create my pet")
{
mysql_query("UPDATE bb1_user_table SET petname = '$petname', pet = '$pet', pic = '$pic', hp = '10', maxhp = '10', str = '7', def = '5', speed = '8', lv = '1', intl = '6' WHERE userid = '".$user_id."'"); // variables inside single quotes do not get evaluated. '$var' will not work. You need to concatenate the strings.
}
?>
You have choosen Belron!
Belron is a Crocodile-like ZeoPet. Enter/View some information below about your pet:
<form method=post action="Belron.php">
<b><br>Pet Name<br></b>
<input type=text size=15 name="petname">
<br><b>
<br>Pet Type<br></b>
<select name="pic">
<option value="Belron.bmp">Belron</option>
</select>
<br><b>
<br> Pet Color<br></b>
<select name="pet">
<option value="Belron">Green</option>
</select>
<br>
<input type="submit" name="submit" value="Create my pet">
<input type="reset" name="reset" value="Clear">
<br><br>
</form>
<br><br>
<hr>
<font color="red" size=3><center><u>Belron's Stats</u></center></font><br>
<font color="black">Level:</font><font color="green">1</font><br>
<font color="black">Hp:</font><font color="green">10</font><br>
<font color="black">Strength:</font><font color="green">7</font><br>
<font color="black">Defense:</font><font color="green">5</font><br>
<font color="black">Speed:</font><font color="green">8</font><br>
}
Posted: Thu Jun 19, 2003 3:49 pm
by I3lade
so it was the printf? Now im getting a error on line 24 which is You have choosen belron! whats wrong with that? Or on line 54 if i put in what you told me...
Posted: Thu Jun 19, 2003 3:54 pm
by I3lade
Parse error: parse error in /data/members/free/tripod/uk/z/e/o/zeopets/htdocs/pages/pets/Belron.php on line 54
You said it should work fine, but its not.
Posted: Thu Jun 19, 2003 3:55 pm
by negblo
try putting your ?> right before the "You have chosen Belron" instead of at the bottom of the page... reason being that starting with the "you have chosen" part is all html for the rest of the page....
Welkies
negblo

Posted: Thu Jun 19, 2003 3:57 pm
by negblo
PS
you need to remove the } symbol at the bottom as well...
welkies
Posted: Thu Jun 19, 2003 4:35 pm
by I3lade
Still got an error...
Posted: Thu Jun 19, 2003 4:36 pm
by I3lade
ok so i have :
even if i take out the } it still dosnt work
Code: Select all
<?session_start();
if($havepet==1){
echo "You already have a pet, you cannot create another!";
}else{
mysql_connect("localhost","bladegames", "****");
mysql_select_db("bladegames");
$id=$row->userid;
// if you are using PHP >4.1, do not use session_register. Do a $_SESSIONї'userid']=$userid
// If you are using PHP<4.1, use session_register('userid'). The var name, not the $var itself
session_register("userid");
if($submit=="Create my pet")
{
mysql_query("UPDATE bb1_user_table SET petname = '$petname', pet = '$pet', pic = '$pic', hp = '10', maxhp = '10', str = '7', def = '5', speed = '8', lv = '1', intl = '6' WHERE userid = '".$user_id."'"); // variables inside single quotes do not get evaluated. '$var' will not work. You need to concatenate the strings.
}
?>
You have choosen Belron!
Belron is a Crocodile-like ZeoPet. Enter/View some information below about your pet:
<form method=post action="Belron.php">
<b><br>Pet Name<br></b>
<input type=text size=15 name="petname">
<br><b>
<br>Pet Type<br></b>
<select name="pic">
<option value="Belron.bmp">Belron</option>
</select>
<br><b>
<br> Pet Color<br></b>
<select name="pet">
<option value="Belron">Green</option>
</select>
<br>
<input type="submit" name="submit" value="Create my pet">
<input type="reset" name="reset" value="Clear">
<br><br>
</form>
<br><br>
<hr>
<font color="red" size=3><center><u>Belron's Stats</u></center></font><br>
<font color="black">Level:</font><font color="green">1</font><br>
<font color="black">Hp:</font><font color="green">10</font><br>
<font color="black">Strength:</font><font color="green">7</font><br>
<font color="black">Defense:</font><font color="green">5</font><br>
<font color="black">Speed:</font><font color="green">8</font><br>
}
Posted: Thu Jun 19, 2003 5:00 pm
by negblo
okay try this then.... just copy and paste
Code: Select all
<?
session_start();
if($havepet==1){
echo "You already have a pet, you cannot create another!";
}else{
mysql_connect("localhost","bladegames", "****");
mysql_select_db("bladegames");
$id=$row->userid;
// if you are using PHP >4.1, do not use session_register. Do a $_SESSIONї'userid']=$userid
// If you are using PHP<4.1, use session_register('userid'). The var name, not the $var itself
session_register("userid");
if($submit=="Create my pet") {
mysql_query("UPDATE bb1_user_table SET petname = '$petname', pet = '$pet', pic = '$pic', hp = '10', maxhp = '10', str = '7', def = '5', speed = '8', lv = '1', intl = '6' WHERE userid= '".$user_id."'");
// variables inside single quotes do not get evaluated. '$var' will not work. You need to concatenate the strings.
}
} //13lade you never closed the first IF statement
?>
You have choosen Belron!
Belron is a Crocodile-like ZeoPet. Enter/View some information below about your pet:
<form method=post action="Belron.php">
<b><br>Pet Name<br></b>
<input type=text size=15 name="petname">
<br>
<b><br>Pet Type<br></b>
<select name="pic">
<option value="Belron.bmp">Belron</option>
</select>
<br><b>
<br> Pet Color<br></b>
<select name="pet">
<option value="Belron">Green</option>
</select>
<br>
<input type="submit" name="submit" value="Create my pet">
<input type="reset" name="reset" value="Clear">
<br>
<br>
</form>
<br>
<br>
<hr>
<font color="red" size=3>
<center>
<u>Belron's Stats</u>
</center>
</font>
</hr> <!-- 13lade you never closed your header either -->
<br>
<font color="black">Level:</font><font color="green">1</font><br>
<font color="black">Hp:</font><font color="green">10</font><br>
<font color="black">Strength:</font><font color="green">7</font><br>
<font color="black">Defense:</font><font color="green">5</font><br>
<font color="black">Speed:</font><font color="green">8</font><br>
That should get you where you need to go... take a look at where i made comments for you so you can see the areas that needed to be fixed
Posted: Thu Jun 19, 2003 6:03 pm
by volka
</hr> <!-- 13lade you never closed your header either -->
<hr /> (horizontal rule) is a tag without contents, same as <br />.
Closing it is very well, but not <hr>...</hr>, just <hr />
e.g.
Code: Select all
</form>
<br /><br />
<hr />
<font color="red" size=3>
<center>
<u>Belron's Stats</u>
</center>
</font>
Posted: Thu Jun 19, 2003 6:49 pm
by negblo
doooh!!!
im an idiot.. i wasnt paying attention... glanced at it real quick and my brain processed it as an <h1>
my bad... did the rest of work????
Posted: Sun Jun 22, 2003 10:58 am
by I3lade
Yes, but now havpet is set to 1 for me and it shows the }else{ whats wrong now? Maby the feild havepet isnt suppsoed to be int? I don't know help please!
Posted: Sun Jun 22, 2003 11:17 am
by I3lade
If you could help me fix this i would appreciate it

Thanks ahead of time
Posted: Sun Jun 22, 2003 11:35 am
by cactus
Sorry, could you refresh this thread and post your current error messages, I've lost the plot on this one
Regards,
[Edit: Where are you setting $havepet ?]