Script problem

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
mogwairn
Forum Newbie
Posts: 3
Joined: Thu Jan 31, 2008 4:41 pm

Script problem

Post by mogwairn »

This script doesn't seem to be accessing the database for somereason, other scripts can so i don't think it's a database problem, so i was wondering if anyone could help spot my problem........or just rip the script to shreds (the majority is from a book so i take no credit)

Code: Select all

<?php
$empty = TRUE;
    if (isset($_SESSION['cart']))
        {
            foreach ($_SESSION['cart'] as $key => $value)
                {
                    if (isset($value))
                        {
                            $empty = FALSE;
                            break;
                        }
                }
        }
        
        
        
    if (!$empty)
        {
            
            include ('./mysql_connect.php');
            
            $q = "SELECT product_name FROM products WHERE product_name IN ("; 
            foreach ($_SESSION['cart'] as $product => $value) 
            {$query .= $product . ','; }
            $q = substr ($query, 0, -1) . ') ORDER BY product_name ASC'; 
            $result = mysql_query ($q) or die();
            
        
            
            echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
                <tr>
                        <td align="left" width="20%"><b>Gift</b></td>
                        <td align="left" width="15%"><b>Price</b></td>
                        <td align="left" width="35%"><b>Quantity</b></td>
                </tr
            <form action="cart.php" method="post"> ';
            
            $total = 0;
            while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
                {
                    echo 
                    "<tr>
                        <td align=\"left\">{$row['product_name']}</td>
                        <td align=\"right\">\£{$_SESSION['cart'][$row['product_name']]['price']}</td>
                        <td align=\"center\">\£{$_SESSION['cart'][$row['product_name']]['quantity']}</td>
                    </tr>\n";
                }
                
            mysql_free_result($result);
            mysql_close();
            
            echo '
                </table>
                    <div align="center">
                        <input type="submit" name="submit" value="update cart" />
                        <input type="hideen" name-"submitted" value="TRUE" />
                    </form>';
        }
        else
        {
            echo ' Cart is empty';
        }
?>
            
            
                
            
                       
thanks in advance for any abuse/help given
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Script problem

Post by Christopher »

I would guess it is in here:

Code: Select all

            include ('./mysql_connect.php');
Have you set the database server, username and password correctly? Do the database server and user exist?
(#10850)
mogwairn
Forum Newbie
Posts: 3
Joined: Thu Jan 31, 2008 4:41 pm

Re: Script problem

Post by mogwairn »

everyother script that uses that include and database work perfectly fine
It is also definately dying after this

Code: Select all

           $q = "SELECT product_name FROM products WHERE product_name IN ("; 
            foreach ($_SESSION['cart'] as $product => $value) 
            {$query .= $product . ','; }
            $q = substr ($query, 0, -1) . ') ORDER BY product_name ASC'; 
            $result = mysql_query ($q) [color=#0000FF]or die()[/color];
which means my query is not working right?
mogwairn
Forum Newbie
Posts: 3
Joined: Thu Jan 31, 2008 4:41 pm

Re: Script problem

Post by mogwairn »

anyone?
Post Reply