PHP Script errors- part 2

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
fanmap81
Forum Newbie
Posts: 2
Joined: Sun Jun 26, 2005 3:03 pm

PHP Script errors- part 2

Post by fanmap81 »

Now this is the 2nd part of my post, hope you guys are still with me. Now i shall continue with the error messages.

For my next file, i have an add.php which is basically supposed to be the pg that comes up after i hit the add to cart button, where i can view the purchase and confirm it, or I can go back to shopping. that file looks like this:

Code: Select all

<?php
session_id();
session_start();
$connect = mysql_connect(&quote;localhost&quote;, &quote;root&quote;, &quote;&quote;) or
     die (&quote;Hey loser, check your server connection.&quote;);
mysql_select_db (&quote;ffmm&quote;);
$qty =$_POSTї'qty'];
$prodnum = $_POSTї'prodnum'];
$sess =session_id();

$query = &quote;INSERT INTO carttemp (sess, quan, prodnum)
          VALUES ('$sess','$qty','$prodnum')&quote;;
$results = mysql_query($query)
     or die(mysql_error());

include(&quote;cart.php&quote;);
?>
when i run the code however in the browser, I get these errors:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /u327/fan22/add.php:1) in /u327/hostname/add.php on line 2

Warning: extract(): First argument should be an array in /u327/hostname/cart.php on line 47



The nex file i have is a checkout.php file. That looks like this:

Code: Select all

<?php
session_start();
//connect to the database - either include a connection variable file or
//type the following lines:
$connect = mysql_connect("host", "hostname", "") or
     die ("Hey loser, check your server connection.");
mysql_select_db ("my database");
//Let's make the variables easy to access in our queries
$membername = $_SESSION['user'];
$memberid=$_SESSION['userid'];
$email = $_SESSION['email'];
$total_price = $_SESSION['totalprice'];
$sessid = session_id();
$today = date("Y-m-d");
     $query3 = "INSERT INTO ordermain (orderdate, custnum, total,
               custname, custemail)
          VALUES (
          '$today',
          '$memberid',
          '$total_price',
          '$membername',
          '$email')";
     $insert2 = mysql_query($query3) or (mysql_error());
     $orderid = mysql_insert_id();

//3) Insert Info into orderdet
     //find the correct cart information being temporarily stored
     $query = "SELECT * from carttemp WHERE sess='$sessid'";
     $results = mysql_query($query)
          or (mysql_error());

     //put the data into the database one row at a time
     while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $query4 = "INSERT INTO orderdet (ordernum, qty, prodnum)
                    VALUES (
                    '$orderid',
                    '$quan',
                    '$prodnum')";
               $insert4 = mysql_query($query4)
                    or (mysql_error());
     }

//4)delete from temporary table
     $query="DELETE FROM carttemp WHERE sess='$sessid'";
     $delete = mysql_query($query);



//6)show them their order & give them an order number
?>
<HTML>
<HEAD>
<TITLE>Thank you for your order!</TITLE>
</HEAD>
<BODY>
<font face="Arial" size="2" color="#000066">Thank you for your order!<br><br>
Your order number is <?php echo $orderid; ?>. Please print this page or retain
this number for your records before you pay via paypal.<br></font>
<br>
<font face="Arial" size="2" color="#000066">
Here is a recap of your order:<br><br>
Order date: <?php echo $today; ?><br></font>


<table width="50%" border="0">
  <tr>
    <td>
      <p><font size="2" face="Arial">Bill to:<br>
        <?php echo $membername; ?><br>
        Email:<?php echo $email; ?><br>
        </font></p>
    </td>
  </tr>
</table>
<hr noshade width='250px' align='left'>
<table cellpadding="5">
     <tr>
      <?php
      $query = "SELECT * from orderdet WHERE ordernum = '$orderid'";
     $results = mysql_query($query)
          or die (mysql_query());
          while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM templates WHERE template_id = '$prodnum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
               echo "<td><font size='2' face='Arial'>";
               echo $quan;
               echo "</font></td>";
               echo "<td><font size='2' face='Arial'>";
               echo $template_sources;
               echo "</font></td>";
               echo "<td align='right'><font size='2' face='Arial'>$ ";
               echo $template_price;
               echo "</font></td>";
               echo "<td align='right'><font size='2' face='Arial'>$ ";
          //get extended price
               $extprice = number_format($template_price * $quan, 2);
               echo $extprice;
               echo "</font></td>";
               echo "</tr>";
			   $total=$extprice+$total;
	 }
	
?>
<tr>
<td colspan='3' align='right'><font size='2' face="Arial">
Your final total is:</font>
</td>
<td align='right'><font size='2' face="Arial"><b> $
     <?php echo number_format($total, 2);
	 session_unset();
	 ?></b></font>

</td>
</tr>
<br>
<tr>
<td align='right'>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@youremail.com">
<input type="hidden" name="item_name" value="Fantastic Fantasy Templates Purchase">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="<?php echo number_format($total, 2);?>">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form> 
</td>
</tr>
</table>
</BODY>
</HTML>
The output of that file looks like this:

Thank you for your order!
Your order number is 0. Please print this page or retain this number for your records before you pay via paypal.

Here is a recap of your order:
Order date: 2005-06-24
Bill to:

Email:
------------------------------------------------------------------------


Warning: Wrong parameter count for mysql_query() in /u327/hostname/checkout.php on line 82



Dont know whats up with that.

The next file up is a file called latest.php, which allows me to view the latest template added to the database. That code is as follows:

Code: Select all

<?PHP
require "conn.php";
$sql="SELECT * FROM templates WHERE template_status=1";
$result=mysql_query($sql);

while ($row=mysql_fetch_array($result)){
extract($row);
}
?>
<html>
<head>
<title>Latest Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<table width="187" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr> 
    <td width="183" height="21" valign="top" bgcolor="#006699"><div align="center"> 
        <h4><font color="#FFFFFF" size="2" face="Arial">Latest Template</font></h4>
      </div></td>
  </tr>
  <tr> 
    <td height="222" align="center" valign="middle"><img src="Admin/templates/<?php echo $template_image ?>" width="150" height="160" align="middle"><br> 
      <font face="Arial" size="2" color="#FFFFFF"><a href="viewtemplate.php?template=<?php echo $template_id; ?>">View Template</a></font> </td>
    </tr>
</table>
</body>
</html>
Here is the error message for that one:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /u327/hostname/latest.php on line 6


Thats all i have for the time being, if anything more is to come up, i will gladly post it. Thank you all for your help with my problems, it will be greatly appreciated. Look to hear from you soon
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

Hi,

1) What is in the session_id() function? It is sending data to the browser, and that is causing the error. Can you move it below the session_start();

2) Replace with mysql_error() :wink:

3) Are you sure there is a result returned via that query. It happens to me when no data is returned by the query. Try echoing out $result before mysql_fetch_array().

Hope this helps :D

Sphen001
Post Reply