simple coding help please!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Klavier
Forum Newbie
Posts: 7
Joined: Fri Jun 27, 2003 5:47 pm
Location: NJ

simple coding help please!

Post 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]
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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 ;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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)
Last edited by John Cartwright on Tue Apr 19, 2005 9:17 pm, edited 1 time in total.
Klavier
Forum Newbie
Posts: 7
Joined: Fri Jun 27, 2003 5:47 pm
Location: NJ

Post 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 :(
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Klavier
Forum Newbie
Posts: 7
Joined: Fri Jun 27, 2003 5:47 pm
Location: NJ

Post 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();
}
}

?>
Klavier
Forum Newbie
Posts: 7
Joined: Fri Jun 27, 2003 5:47 pm
Location: NJ

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply