Forum Moderators: coopster

Message Too Old, No Replies

echoing variables into HTML

Need guidance please, variable trouble.

         

PickleHead

9:18 am on May 30, 2007 (gmt 0)

10+ Year Member


So I'm playing with a very retarded list of products 1-9, and have the
following list.php page snippet excluding html header/footers/table tags:

<?
error_reporting(E_ALL ¦ E_NOTICE);

include('connect.php');
$sql="SELECT * FROM PRODUCT";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{ echo"<tr>";
echo "<td>".$row['prodtitle']."</td>";
echo "<td>".$row['proddescription']."</td>";
echo "<td>$".$row['prodcost'].".00</td><td>";

?>
<form action='cart.php' method='post'>
<input type='hidden' name='add2cart' value='<? $row['pid']?>'>
<input type='submit' name='addButton' value='Add to Cart'>
</form>
</td>
</tr>
<?
}
?>

The pid is correctly in the db and is being retrieved, however I do not know how to get the variable outside of a php block.
The example output i get is:

<tr><td>Product1</td><td>Amazing product1!</td><td>$20.00</td><td> <form action='cart.php' method='post'>
<input type='hidden' name='add2cart' value=''>
<input type='submit' name='addButton' value='Add to Cart'>

Note the hidden input type value is empty...ARGH!
I'm doing this to add an 'add2cart' button to each row of the table.
But I cannot seem to embed the html within the php block due to some
issues with quotations that I cannot resolve, or its something else;
I'm uncertain. I get no mysql_error() but just a blank page.
Can anyone assist me here?

dreamcatcher

9:26 am on May 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi PickleHead,

You need to echo the value of the id in the form to show its value:

<? echo $row['pid']?>

Not really sure about your comment 'issues with quotations'. Can you elaborate?

dc

PickleHead

9:45 am on May 30, 2007 (gmt 0)

10+ Year Member



Nice, that did it...always the obvious.

On the other issue with quotes(I assume)...heres the example:

Now that I look at it, I've been up for 27 hours, it was total gibberish! What you helped me with already solves all my problems, except sleep! Thanks again!

[edited by: PickleHead at 10:06 am (utc) on May 30, 2007]

PickleHead

9:46 am on May 30, 2007 (gmt 0)

10+ Year Member



Gotta run, but thank you for the help; I can dive deeper now!

dreamcatcher

12:45 pm on May 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hehe, ok, no problem.

dc

eelixduppy

12:49 pm on May 30, 2007 (gmt 0)



PickleHead, you might want to take a look at the strings [php.net] and the basic syntax [php.net] documentation for some further reading.

And Welcome to WebmasterWorld! :)