Page 1 of 1

simple coding help please!

Posted: Tue Apr 19, 2005 7:37 pm
by Klavier
hey for some reason im not getting anything from this... just blank (source from browser= <html><body></body></html>) :/
i was working through this tutorial, but this page didn't come out right. im running through this tutorial http://www.devarticles.com/c/a/MySQL/Bu ... d-MySQL/1/
and im having an enormous amount of trouble.. i have a basic understanding of php and mysql. i have created the database and tables and have inserted the data. as i got to the "products" page which is shown below, i understand most if not all of it, but can't seam to get it to work.. then on the "cart" page which should allow users to add and remove the items from the cart... im totally lost. i can't seam to throw it all together to make a working model :( can anyone help ? thanks in advance

Code: Select all

<?php

include("db.php");

$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from items order by itemName asc");
?>

<html>
<body>
<table>

<?php
while($row = mysql_fetch_array($result))
{
?>


<tr>
<td width="30%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo $row["itemPrice"]; ?>
</font>
</td>
<td width="50%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemDesc"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a>
</font>
</td>
</tr>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<tr>
<td width="100%" colspan="4">
<font face="verdana" size="1" color="black">
<a href="cart.php">Your Shopping Cart >></a>
</font>
</td>
</tr>
</table>
</body>
</html>
Jcart | Please use

Code: Select all

tags around your code.  Read [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Apr 19, 2005 8:41 pm
by malcolmboston
feyd will only tell you this anyway......use the code tags around your code

most people wont even read it in that form

Jcart | Hey, I say it too ;)

Posted: Tue Apr 19, 2005 8:50 pm
by John Cartwright
change

Code: Select all

$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from items order by itemName asc");
to

Code: Select all

$cxn = ConnectToDb($dbServer, $dbUser, $dbPass, $dbName) or die(mysql_error());
$result = mysql_query("select * from items order by itemName asc") or die(mysql_error());;
You should get in the habbit of adding or die(myql_error()) because it will give you useful information as to what is going wrong.

You should also avoid the use of @ at this time, because it supresses errors. Consider it a bandaid approach at this point, as it is better to simply solve the root of the problem then hiding it. (cough cough line 6)

Posted: Tue Apr 19, 2005 8:56 pm
by Klavier
hi thank you
well jcart, i added the "or die" to my lines and im still getting nothing at all, so i am assuming it is connecting properly to the database, as i had entered data before in the same fashion. so im not quite sure why this isn't working.. are my opening html, body, and table tags in the correct place?

sorry about the tags :(

Posted: Tue Apr 19, 2005 9:00 pm
by John Cartwright
I don't see anything particularly wrong, except your poor html writting (:roll:). Please show us exactly what is shown in the source.

Posted: Tue Apr 19, 2005 9:12 pm
by Klavier
here is the included file with the first code which i have already posted, which is the entired code for that page. here is the db.php

Code: Select all

<?php

$dbServer = "localhost";
$dbUser = "jcala";
$dbPass = "";
$dbName = "cart";

function ConnectToDb($server, $user, $pass, $database)
{


$s = @mysql_connect($server, $user, $pass);
$d = @mysql_select_db($database, $s);

if(!$s || !$d)
return false;
else
return true;
}

function GetCartId()
{

if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{

session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}

?>

Posted: Tue Apr 19, 2005 10:58 pm
by Klavier
ok maybe i haven't asked this right.. in my first post, all i am trying to do with create a table to show the data from the database in, using a loop. and i haven't done it correctly. so show would i be able to show myslq data in a table using php/html? thanks

Posted: Wed Apr 20, 2005 12:23 am
by feyd
if you aren't getting a blank version of your table row(s) then you very likely are getting zero rows from mysql, or you are dying somewhere, but aren't displaying the errors.

Check what is returned from mysql_num_rows(), as well as checking your error logs on the (web) server.