lookee
Members-
Posts
28 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
lookee's Achievements
Member (2/5)
0
Reputation
-
I have this shopping cart almost running, but it doesn't display the actual names of the contents within the database. I've indicated below where I'm having problems ... What code do I insert to display the database contents of the related Ids? I have tried a variety of things, but none are working. Any help would be greatly appreciated. function connectToDb () -- specifics removed.... // Select the Database $db_select=mysql_select_db($db_name); if (!$db_select) { die ("Couldn't select the database: <br/>". mysql_eror()); } function isError () { if ( $this->connectError ) return true; $error=mysql_error ($this->dbConn); if ( empty ($error) ) return false; else return true; } /** * Returns an instance of MySQLResult to fetch rows with * @param $sql string the database query to run * @return MySQLResult * @access public */ function query($sql) { if (!$queryResource=mysql_query($sql,$this->dbConn)) trigger_error ('Query failed: '.mysql_error($this->dbConn). ' SQL: '.$sql); return new MySQLResult($this,$queryResource); } } /** * MySQLResult Data Fetching Class * @access public * @package SPLIB */ class MySQLResult { /** * Instance of MySQL providing database connection * @access private * @var MySQL */ var $mysql; /** * Query resource * @access private * @var resource */ var $query; /** * MySQLResult constructor * @param object mysql (instance of MySQL class) * @param resource query (MySQL query resource) * @access public */ function MySQLResult(& $mysql,$query) { $this->mysql=& $mysql; $this->query=$query; } /** * Returns the number of rows selected * @return int * @access public */ function size () { return mysql_num_rows($this->query); } /** * Returns the ID of the last row inserted * @return int * @access public */ function insertID () { return mysql_insert_id($this->mysql->dbConn); } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { return $this->mysql->isError(); } } /** * Fetches a row from the result * @return array * @access public */ function fetch () { if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) { return $row; } else if ( $this->size() > 0 ) { mysql_data_seek($this->query,0); return false; } else { return false; } } $result = mysql_query($sql); // $result = mysql_query($query); function showCart() { $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } NOT SURE WHAT TO PUT HERE TO SHOW CONTENTS.... $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM packages WHERE id = '.$id; $result = mysql_query($sql); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$size.' by '.$width.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } echo showCart(); ?> Thanks!
-
Okay, thanks... I now defined $result in the line above, and I call the function fetch several lines above, but I still get the error.. Fatal error: Call to a member function fetch() on a non-object Is the non-object $row, or is the non-object something in the database? My head hurts. Thanks for any help. <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>REVIEW QUANTITY</h1> <?php * Checks for MySQL errors * @return boolean * @access public */ function isError () { if ( $this->connectError ) return true; $error=mysql_error ($this->dbConn); if ( empty ($error) ) return false; else return true; } /** * Returns an instance of MySQLResult to fetch rows with * @param $sql string the database query to run * @return MySQLResult * @access public */ function query($sql) { if (!$queryResource=mysql_query($sql,$this->dbConn)) trigger_error ('Query failed: '.mysql_error($this->dbConn). ' SQL: '.$sql); return new MySQLResult($this,$queryResource); } } /** * MySQLResult Data Fetching Class * @access public * @package SPLIB */ class MySQLResult { /** * Instance of MySQL providing database connection * @access private * @var MySQL */ var $mysql; /** * Query resource * @access private * @var resource */ var $query; /** * MySQLResult constructor * @param object mysql (instance of MySQL class) * @param resource query (MySQL query resource) * @access public */ function MySQLResult(& $mysql,$query) { $this->mysql=& $mysql; $this->query=$query; } /** * Returns the number of rows selected * @return int * @access public */ function size () { return mysql_num_rows($this->query); } /** * Returns the ID of the last row inserted * @return int * @access public */ function insertID () { return mysql_insert_id($this->mysql->dbConn); } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { return $this->mysql->isError(); } } /** * Fetches a row from the result * @return array * @access public */ function fetch () { if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) { return $row; } else if ( $this->size() > 0 ) { mysql_data_seek($this->query,0); return false; } else { return false; } } // $result = mysql_query($query); function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM packages WHERE id = '.$id; $result = mysql_query($sql); PROBLEM LINE ---> $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.' by '.$author.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } echo showCart(); ?> [\code]
-
Below is my complete code (less the connection to the database) When I run the following code, I get the following error: Call to a member function fetch() on a non-object in line 138 If I comment out the PROBLEM LINES, the shopping cart partially displays onscreen, but the content of shopping cart passed from the previous .php screen is not passed in completion. What I need are the mysql commands or something to replace PROBLEM LINES that will access the information passed from the previous shopping cart page. Any help would be greatly appreciated. Thanks! // Select the Database $db_select=mysql_select_db($db_name); if (!$db_select) { die ("Couldn't select the database: <br/>". mysql_eror()); } // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Shopper Shopper</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shopper"> <h1>Deliva's Shopping Cart</h1> <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Review Quantityh1> <?php function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { PROBLEM LINE ----> $row = $result->fetch(); PROBLEM LINE ----> extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.' by '.$author.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } echo showCart(); ?>
-
For the following code, line 1 if (!$queryResource=mysql_query($sql,$this->dbConn)) line 2 trigger_error ('Query failed: '.mysql_error($this->dbConn). line 3 ' SQL: '.$sql); I receive Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in Line 1 Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource ine Line 2 Notice: Query failed: SQL: SELECT * FROM packages WHERE id = 2 in Line 3 After much research, I discovered that // SET PASSWORD FOR 'user'@'localhost' = OLD_PASSWORD('pass'); might fix the problem, but I keep getting the error Parse error: syntax error, unexpected T_STRING Any help would be greatly appreciated!
-
With the following code, I am receiving the following error SET PASSWORD FOR 'jumpodin_jmpdng1'@'localhost' = OLD_PASSWORD('dvv88'); Parse error: syntax error, unexpected T_STRING in
-
Thanks.... The crappy tutorial I read gave two quote marks... <?php echo "Hello World";
-
And when I try to echo it... echo "<div id="leaderboard_bridge"></div><script src="http://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script><script type="text/javascript">Mochi.addLeaderboardIntegration({partnerID: "x4455839574839567674"});</script>"; ?> The closing php tag doesn't turn red again... something is missing, and I can't figure out what... something in the embed code seems to be throwing off the syntax
-
I can't link it or href it because it has to be embedded in the actual file. The echo didn't show up inbetween the code tags....
-
I'm attempting to embed the following code into a .php file, but every time I do, I get a syntax error. <div id="leaderboard_bridge"></div><script src="http://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script><script type="text/javascript">Mochi.addLeaderboardIntegration({partnerID: "x34551194587393"});</script> The error I get is Parse error: syntax error, unexpected '<' in /home/jumpodin/public_html/components/com_puarcade/puarcade.php on line 170 Basically, I don't know how to integrate this bit of code into my pre-existing .php script. I can't remove the <. I tried putting a ; at the end, but that doesn't work either. Any help would be greatly apprecaited.
-
Solved... if (mysql_num_rows($result) > 0)
-
Everything works except the verification of whether a row is already in table. Basicially if 1 row exists, code should quit running and echo "already purchased" message. Code ---------------------------- // Select the Database $db_select=mysql_select_db($db_name); if (!$db_select) { die ("Couldn't select the database: <br/>". mysql_eror()); } // Assign the Query $query = "SELECT * FROM shoes WHERE username = '$username' AND size > 0"; <---------- If size greater than 0 already placed an order) // Execute the Query $result = mysql_query($query); if (!$result) { die ("Line 117 Could not query the database: <br />". mysql_error()); } if ($query == 1) <----- if 1 row exists - order for shoes already in database, so exit { die ("You already made a request!"); } mysql_query("INSERT INTO shoes VALUES('purchase_number','$username','$first_name','$last_name','$address','$city','$state','$zip','$email','$size','date') ") or die(mysql_error()); Header("Location: successful_purchase.php"); include 'close_db.php'; ?> Any help with my logic would greatly help!
-
[SOLVED] verifying data against one table and writing data to a new table
lookee replied to lookee's topic in MySQL Help
I have them in an include. Both tables are within the same database, so I figured the same connection information should work. -
How do I verify data obtained via an HTML form with one db table, and if everything matches, write data to a new table? Currently, I'm able to either validate form data in one table OR write data to ANOTHER TABLE, but when I merge all the code, I get a Warning: mysql_query() [function.mysql-query]: Access denied for user 'earlier'@'localhost' (using password: NO) in /home/earlier/public_html/now/request.php on line 93 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/earlier/public_html/now/request.php on line 93 Could not query the database: Access denied for user 'earlier'@'localhost' (using password: NO) My code: ------------ <?php session_start(); // Assign the Query $sql="SELECT * FROM shoe WHERE username='$username'"; //Execute the Query $result=mysql_query($sql); <-------------LINE 93 in Error Message if (!$result){ die ("Could not query the database: <br />". mysql_error()); //Saves Type Request to a MYSQL Database //Insert a row of information into the table "shoepay" / mysql_query("INSERT INTO shoepay VALUES('request_number','$username','$first_name','$last_name','$email','$user_id','$shoe_size','$paid_shoes','date') ") or die(mysql_error()); Header("Location: successful_payment.php"); } mysql_close(); include 'close_db.php'; ?> ---------------------------- It seems I'm opening one query but not finishing it then starting another, and I'm mixing up my "mysql_query" so that login information is getting crossed. Or something. Any help would be greatly appreciated.
-
Thanks! I just noticed the PHP tutorial by Mustafa on VTC.com was released 2002. I have requested my refund.
-
Solved... thanks!