1

I am having these errors (I have checked around the line 5, and can't find any white line, and the sql on line. I have checked the spellings and syntax, they're alright.)

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/reachea2/public_html/orderpplac.php on line 53

Warning: Cannot modify header information - headers already sent by (output started at /home/reachea2/public_html/orderpplac.php:53) in /home/reachea2/public_html/include/functions.php on line 5

Code:

<?php
require_once("include/session.php");
require_once("include/dataconnect.php"); 
require_once("include/functions.php");
if (isset($_POST['submit1'])) {
    if(array_key_exists('item', $_POST)){
        // $items = $_POST['item'];
        //foreach($_POST['item'] as $item){
            //echo $item['Pquantity'] . ", ";
            //echo $item['Pidno'] . ", ";
        // }
        //Loop through $_POST items, updating the database for each item
        foreach ($_POST['item'] as $item) { 
            $Pquantity = intval($item['Pquantity']);
            $Pidno = ($item['Pidno']); 
            //echo $Pquantity . ", ";
            //echo $Pidno . ", ";
            $queryreg = mysql_query("
                UPDATE repplac
                SET Pquantity = {$Pquantity}
                WHERE Pidno = '{$Pidno}'
                AND Uname = '{$_SESSION['username']}'
            ") or die(mysql_error());  
        }
    }
}
else if (isset($_POST['submit2'])) {
    //Get Email Address
    $emails = mysql_query("SELECT reusers.email FROM reusers INNER JOIN repplac ON reusers.username = repplac.Uname AND reusers.username = '{$_SESSION['username']}'")or die(mysql_error());
    //$emails = mysql_query("SELECT reusers.email FROM reusers INNER JOIN repplac ON reusers.username = repplac.Uname AND reusers.username = '".$_SESSION['username']."'")or die(mysql_error());
    $results = (mysql_fetch_assoc($emails)) or die(mysql_error());
    $email= $results['email'];
    //echo "$email";
    //die();
    if(mysql_num_rows($emails) == 0){
        exit("No email addresses found for user '{$_SESSION['username']}'");
    }
    $email = mysql_result($emails, 0);

    //Get list to email user
    $body = "<html><body><table border='1'>
    <tr>
        <th>Shop Name</th>
        <th>Product Name</th>
        <th>Size</th>
        <th>Color Name</th>
        <th>Quantity</th>
    </tr>";
    $pplresult = mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}')");   
    while($row = mysql_fetch_assoc($pplresult)){ 
        $body .= "<tr>
                <td>" . $row['Sname'] ."</td>
                <td>" . $row['Pname'] ."</td>
                <td>" . $row['Psize'] ."</td>
                <td>" . $row['Pcolour'] ."</td>
                <td>" . $row['Pquantity'] ."</td>
            </tr>";
    }

    $body .="</table></body></html>";
    //Send email
    $to = $email; 
    $subject = "YOUR ORDER LIST FROM REACHEASY"; 
    $headers = "From: donotreply@rapsody.co.uk\r\n";  
    $headers  .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    mail($to,$subject,$body,$headers);
    //Transfer records to wishlist 
    $transfer = mysql_query("INSERT INTO wishlist (SELECT  * FROM repplac WHERE Uname = '{$_SESSION['username']}')")or die(mysql_error());
    // Delete temporary records if the above query was successful:
    if($transfer !== false){
        $deletetable = mysql_query("DELETE FROM repplac WHERE Uname = '{$_SESSION['username']}'");
    }
}
redirect_to('youraccount.php'); 
?> body
RAS
  • 8,100
  • 16
  • 64
  • 86
lostty84
  • 79
  • 8
  • Disable Error reporting (log them instead), then the warning will go away (and you're not sending output any longer as the output is the first warning). See http://php.net/manual/en/book.errorfunc.php - Note that you still need to review the error log and fix your application. – hakre Feb 13 '12 at 14:12
  • @hakre: I understand disabling notices, but warnings are too important do disable them. Its always better to solve problem than hide it – Tomasz Banasiak Aug 17 '13 at 15:47
  • @TomaszBanasiak: Where did I wrote to disable those? And where did I wrote that notices and strict errors aren't important? – hakre Aug 17 '13 at 16:12

4 Answers4

3

The second warning is shown because the first warning is shown. When the first warning is shown it creates output to the browser which makes the server create headers and then you cannot modify session anymore.

Fix the first mysql warning at line 53 in orderpplac.php and the rest would fix itself.

Milan Babuškov
  • 59,775
  • 49
  • 126
  • 179
0

Make sure the files:

"include/session.php"
"include/dataconnect.php"
"include/functions.php"

don't have any trailing whitespaces.

There must be no output before sending the headers.

Look for whitespaces or new lines after the closing ?>, or, better yet, don't close the <?php tags in those files.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
0

There's a lot similar questions here.

If you send something to the browser, eg. using echo or print commands (also if any notice or warning is displayed) you cant modify header information.

Try to disable error reporting ( add error_reporting(0) in the top of your file) or try with output buffering, read more about ob_start, ob_end_clean etc.

Tomasz Banasiak
  • 1,540
  • 2
  • 13
  • 19
0

There is no session_start(), it should be first after <?php

If you have session_start() inside session.php that you are including try to remove ?> from the end of each included file

Milan Halada
  • 1,943
  • 18
  • 28