Jump to content

Recommended Posts

I dont know if you can find up what is happening with this code but lets try

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("manvisdatabse", $con);

$query  = mysql_query("select * from cart where CartID=$CartID");

$query1 = mysql_query ("SELECT SUM(TotalPrice) FROM Cart");

if(!qyery1)

echo "Query lesh";

 

echo "<table align=center><tr><td width='100' >Product Name</td><td width='80'>Price</td><td width='80'>Quantuty</td><td width='80'>Total Price</td><td width='80'></td></tr></table><br>";

 

while($row=mysql_fetch_array($query))

{

 

$CartID1=$row['CartID'];

$ProductID1=$row['ProductID'];

$ProductName1=$row['ProductName'];

$Price1= $row['Price'];

$Quantity1=$row['Quantity'];

$TotalPrice1=$row['TotalPrice'];

 

 

 

 

echo "<table align='center'><tr><td width='100'>$ProductName1</td><td width='80'>$Price1 $</td><td width='80'><input type='text' size=2 Value= $Quantity1 maxlength=5 name='Quantity'>";

echo "</td><td width='80'>$TotalPrice1 $</td><td width='80'><form action='show_cart.php' method='POST'>";

                           

                           

                              echo "<input type='hidden' size='5'  maxlength='5' name='ProductID' Value=$ProductID1>";

  echo "<input type='submit' value='Delete'></td></tr></table>";

  }

  echo "<br>";

echo "<table align=center><tr><td width='100' ></td><td width='80'></td><td width='80'></td><td width='80'></td><td width='80'> $query1</td></tr></table><br>";

  ?>

First off, try entering your query directly into phpMyAdmin to see if it behaves expectedly.

SELECT SUM(TotalPrice) FROM Cart

 

Once you're sure of that, you can check your PHP code for problems.  The first obvious one I can see is in your first code post:

$query1 = mysql_query ("SELECT SUM(TotalPrice) FROM Cart");
if(!qyery1)
echo "Query lesh";

You have mistyped the variable name.

 

In your second code post, you execute a query and save the result in $query, but echoing query isn't going to print the value from the DB.  You still have to call mysql_fetch_array; normally I would use mysql_fetch_assoc but since you didn't alias the column, mysql_fetch_array is easier IMO.

$query = mysql_query ("SELECT SUM(TotalPrice) FROM cart");   

if(!$query) // <-- YOU FORGOT THE $ IN YOUR CODE
{

echo "error";
}
else{
  $row = mysql_fetch_array($query);
  echo $row[0];
}

 

Basically you are being very sloppy.  You should be able to catch things like missing dollar signs and misspelled variables based on interpreter errors, or just carefully reading your code.  Also, even though they are optional when the body is a single line, you should always enclose your if and loop bodies in curly brackets.  Don't be lazy.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.