Help with database needed!

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
Chesh
Forum Newbie
Posts: 3
Joined: Wed Mar 04, 2009 6:18 am

Help with database needed!

Post by Chesh »

Hi everyone :o

I am trying to make a cd website thing for my uni course and i am trying to make the shopping cart page at present. However, i have come across a strange (to me anyway) problem.

I have the following code but when opening the page it doesnt display anything at all, not even the echo commands at the very beginning which i think is strange. What i am trying to accomplish with this page is to show all the details of a cd where the cd id in the stock table is the same as in the shopping cart, therefore showing the information of the cd in the shopping cart.

I am wondering if any of you could help :D
Thank you

Here is my code:

Code: Select all

<?php
 
echo "stage1";
$host = "localhost";
$user = "10241976";
$password = "*******";
$database = "10241976";
 
//connect to MySQL
$connect = mysql_connect($host, $user, $password ) 
              or die("Hey loser, check your server connection.");
 
//make sure we're using the right database
mysql_select_db($database);
 
echo "stage1";
 
// set up the SQL query
$query = "SELECT * FROM shoppingcart";
 
$query2 = "SELECT * FROM stocktable WHERE stocktable.disc_id = shoppingcart.disc_id";
 
// execute the query
$results = mysql_query($query)
                or die(mysql_error());
 
$results2 = mysql_query($query2)
                or die(mysql_error());
                
                echo "stage2";
 
// count the number of rows that are selected from the table
$numrow = mysql_num_rows($results);
?>
 
<html>
<head><title>Chris' Rainforest</title>
<link rel="stylesheet" type="text/css" href="master.css"/>
</head>
<body>
 
 
Welcome to Chris' Rainforest
 
Your cart
</br>
<table border="1" align = "center">
<tr id="list">  
    <td><b>Disc id</b>
    <td><b>Album Title</b>
    <td><b>quantity</b>
    <td><b>price</b>
 </tr>
 
<?php
$count = 0;
while ($count < $numrow) 
  {
    echo "<tr>";
    $row = mysql_fetch_array($results2);
    extract($row);
    // send the values to the browser as a row in a html table
    echo "<td>";
    echo "<p align='right'>".$disc_id."</a>";
    echo "</td>";
    echo "<td>";
    echo "<p align='right'>".$album."</a>";
    echo "</td>";
    echo "<td>";
    echo "<p align='right'>".$quantity."</a>";
    echo "</td>";
    echo "<td>";
    echo "<p align='right'>".$price."</a>";
    echo "</td>"l
    echo "<td>";
    echo "<a href='deletefromcart.php?disc_id=".$disc_id."'>Delete from cart</a>";
    echo "</tr>";
    echo "</tr id='list'>";
    $count = $count + 1;
  }
?>
</table>
 
</body>
</html>
 
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Help with database needed!

Post by susrisha »

Code: Select all

 
if(!mysql_select_db($database))
{
   echo mysql_error();
};
 
 
Chesh
Forum Newbie
Posts: 3
Joined: Wed Mar 04, 2009 6:18 am

Re: Help with database needed!

Post by Chesh »

im guessing that goes immediately after the database select,

if so, then it still doesnt display anything, just a blank page!
Chesh
Forum Newbie
Posts: 3
Joined: Wed Mar 04, 2009 6:18 am

Re: Help with database needed!

Post by Chesh »

Sorted it, if you look near the bottom there is a 'one' instead of a semi colon which was <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> everything up god knows how that got there?
Post Reply