Can someone help me with this?

salukigirl

New Member
Messages
78
Reaction score
0
Points
0
Ok, long story short I'v having trouble with my output. It output's well.... nothing....


This is the pet store page. It creates the animal the user wants. When it is done it is to store the bought pet at the owner's home page. But for some reason it doesn't show up.....
Am I like missing a huge chunk of code? or???
Here are the scripts I built...
PHP:
<?php
include ('connect.php');
?>

<form name="form1" method="post" action="petstore.php">
Registered Name:
<br>
<input name="petname" type="text"
Rabbit Breed:
<select breed="petbreed"
<option value="American Chinchilla">American Chinchilla</option>
<option value"American Fuzzy Lop">American Fuzzy Lop</option>
<option value"American Sable">American Sable</option>
<option value"Belgian Hare">Belgian Hare</option>
<option value"Brittania Petite">Brittania Petite</option>
<option value"Californian">Californian</option>
<option value"Champagne D'Argent"> Champagne D'Argent </option>
<option value"Checkered Giant">Checkered Giant</option>
<option value"Cinnamon">Cinnamon</option>
<option value"Creme D'Argent">Creme D'Argent</option>
<option value"Dutch">Dutch</option>
<option value"Dwarf Hotot">Dwarf Hotot</option>
<option value"English Angora">English Angora</option>
<option value"English Spot">English Spot</option>
<option value"Flemish Giant">Flemish Giant</option>
<option value"Florida White ">Florida White </option>
<option value"Giant Angora">Giant Angora</option>
<option value"Giant Chinchilla ">Giant Chinchilla </option>
<option value"French Angora">French Angora</option>
<option value"Harlequin">Harlequin</option>
<option value"Havana">Havana</option>
<option value"Himalayan">Himalayan</option>
<option value"Holland Lop">Holland Lop</option>
<option value"Hotot">Hotot</option>
<option value"Mini Rex">Mini Rex</option>
<option value"Rex">Rex</option>
<option value"Satin Angora">Satin Angora</option>
<option value"Standard Chinchilla ">Standard Chinchilla </option>
<br>
pet gender:
<select name"petgender">
<option value"male">Male</option>
<option value"female">Female</option>
<br>
Pet Color:
<select name"petcolor">
<option value"white">White</option>
<option value"black">Black</option>
<option value"gray">Gray</option>
<br>
</select>
<input type="submit" name="submit" value="But It!">
</form>

<?php
$petname = trim($_POST['petname']);
$petbreed = trim($_POST['petbreed']);
$petgender = trim($_POST['petgender']);
$petcolor = trim($_POST['petcolor']);
?>

<?php
$ownerid =$_SESSION['id']
?>

<?php
$pet =@mysql_query("INSERT INTO pets (ownerid, petname, petbreed, petgender, petcolor) 
VALUES ('$ownerid', '$petname', '$petbreed', '$petgender', '$petcolor')") or die ("error:".mysql_error())
?>

This is the Home page. I want it to display the animal the user just bought.
PHP:
<?php
include('connect.php'); 
?>

<?php
$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE ownerid=".$_SESSION['id']."";
$result = mysql_query ($query)
or die ("couldn't execute query.");
?>

<?php
while ($pet= mysql_fetch_object ($result))
{
?>



<?php
echo
"
Registered Name: $petname
<br>
Breed: $petbreed
<br>
Gender: $petgender
<br>
Color: $petcolor
<br><br>
";
?>
<?php
}
?>
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
PHP:
<input name="petname" type="text">
Rabbit Breed:
<select breed="petbreed">
 

salukigirl

New Member
Messages
78
Reaction score
0
Points
0
Thanks... that helped but. it still doesn't show the name, breed, gender, and color of the rabbit you bought...
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Echo out your query. Chances are its not inserting properly.
 

toofani

New Member
Messages
33
Reaction score
0
Points
0
I have the echo in there. Did I do it wrong? Is it in the right place?
i guess check this:
<?php
include('connect.php');
?>

<?php
$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE ownerid=".$_SESSION['id']."";
$result = mysql_query ($query)
or die ("couldn't execute query.");
?>

<?php
while ($pet= mysql_fetch_object ($result))
{
?>



<?php
echo
<br>
Registered Name: $petname
<br>
Breed: $petbreed
<br>
Gender: $petgender
<br>
Color: $petcolor
<br><br>



is this the output you want?
Registered Name: $petname
Breed: $petbreed
Gender: $petgender
Color: $petcolor
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
I meant echo
PHP:
"INSERT INTO pets (ownerid, petname, petbreed, petgender, petcolor) 
VALUES ('$ownerid', '$petname', '$petbreed', '$petgender', '$petcolor')"
out
 

conker87

New Member
Messages
65
Reaction score
0
Points
0
You're not suppling the values to the variables.

PHP:
<?php
include('connect.php'); 

$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE ownerid=".$_SESSION['id'];
$result = mysql_query ($query) or die ("couldn't execute query.");

while ($pet= mysql_fetch_object ($result))
{

echo "Registered Name: ". $pet['petname'] ."
<br>
Breed: ". $pet['petbreed'] ."
<br>
Gender: ". $pet['petgender'] ."
<br>
Color: ". $pet['petcolor'] ."
<br><br>";

}
?>

Cleaned up slightly too.
 
Last edited:

salukigirl

New Member
Messages
78
Reaction score
0
Points
0
You're not suppling the values to the variables.

PHP:
<?php
include('connect.php'); 

$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE ownerid=".$_SESSION['id'];
$result = mysql_query ($query) or die ("couldn't execute query.");

while ($pet= mysql_fetch_object ($result))
{

echo "Registered Name: ". $pet['petname'] ."
<br>
Breed: ". $pet['petbreed'] ."
<br>
Gender: ". $pet['petgender'] ."
<br>
Color: ". $pet['petcolor'] ."
<br><br>";

}
?>
Cleaned up slightly too.

That's what I was thinking! -smacks self and feels stupid. I didn't save that info into the varibles.
Thanks so much! :drool:
Edit:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/star/public_html/bunnygame/home.php on line 10

? =(
 
Last edited:

conker87

New Member
Messages
65
Reaction score
0
Points
0
What is line 10?

Oh wait, I've never used fetch object. Try this:

Edit: Try this newer one, here's me trying to make an echo look cleaner -.-

PHP:
<?php
include('connect.php'); 

$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE ownerid=".$_SESSION['id'];
$result = mysql_query ($query) or die ("couldn't execute query.");

while ($pet= mysql_fetch_array($result))
{ ?>
Registered Name: <?=$pet['petname']; ?><br>
Breed: <?=$pet['petbreed']; ?><br>
Gender: <?=$pet['petgender']; ?><br>
Color: <?=$pet['petcolor']; ?><br><br>";
<? } ?>
 
Last edited:

vlucan

New Member
Messages
13
Reaction score
0
Points
0
I think the Problem is in fetching the data argument i would like you to try this:
PHP:
<?php
$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE
ownerid=\".$_SESSION['id']\"";
$result = mysql_query ($query)
or die ("couldn't execute query.");
$r_number = mysql_num_rows($result);
for($i = 0;$i <= $r_number-1;$i++)
{
    list($name[$i],$breed[$i],$gender[$i],$color[$i]) = mysql_fetch_row($result);
}
echo $_SESSION["id"]."<br>";
//and now the printing part ;)
for($i = 0;$i <= $r_number-1;$i++)
{
    echo"
    <br>
    Registered Name: $name[$i]
    <br>
    Breed: $breed[$i]
    <br>
    Gender: $gender[$i]
    <br>
    Color: $color[$i]
    <br><br>";
}
?>
 

salukigirl

New Member
Messages
78
Reaction score
0
Points
0
What is line 10?

Oh wait, I've never used fetch object. Try this:

Edit: Try this newer one, here's me trying to make an echo look cleaner -.-

PHP:
<?php
include('connect.php'); 

$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE ownerid=".$_SESSION['id'];
$result = mysql_query ($query) or die ("couldn't execute query.");

while ($pet= mysql_fetch_array($result))
{ ?>
Registered Name: <?=$pet['petname']; ?><br>
Breed: <?=$pet['petbreed']; ?><br>
Gender: <?=$pet['petgender']; ?><br>
Color: <?=$pet['petcolor']; ?><br><br>";
<? } ?>

That sorta worked but it only shows the name of the rabbit. not the breed, gender or color...
Edit:
I think the Problem is in fetching the data argument i would like you to try this:
PHP:
<?php
$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE
ownerid=\".$_SESSION['id']\"";
$result = mysql_query ($query)
or die ("couldn't execute query.");
$r_number = mysql_num_rows($result);
for($i = 0;$i <= $r_number-1;$i++)
{
    list($name[$i],$breed[$i],$gender[$i],$color[$i]) = mysql_fetch_row($result);
}
echo $_SESSION["id"]."<br>";
//and now the printing part ;)
for($i = 0;$i <= $r_number-1;$i++)
{
    echo"
    <br>
    Registered Name: $name[$i]
    <br>
    Breed: $breed[$i]
    <br>
    Gender: $gender[$i]
    <br>
    Color: $color[$i]
    <br><br>";
}
?>

I tried that and got this error
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/star/public_html/bunnygame/home.php on line 3
 
Last edited:

conker87

New Member
Messages
65
Reaction score
0
Points
0
Just change the names inside of the $pet[''] with the column names in your table.
 

salukigirl

New Member
Messages
78
Reaction score
0
Points
0
I did.

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/star/public_html/bunnygame/home.php on line 2

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/star/public_html/bunnygame/home.php on line 2
 

conker87

New Member
Messages
65
Reaction score
0
Points
0
I see the problem:
PHP:
$query="SELECT petname, petbreed, petgender, petcolor FROM pets WHERE ownerid=".$_SESSION['id'];
 

salukigirl

New Member
Messages
78
Reaction score
0
Points
0
Thanks. But now it doesn't show the info of breed etc.

but the registered name:
breed: etc is there. But nothing after it......
 
Top