Jump to content

Recommended Posts

So im attempting to take someone's free cart script and integrate it into my site. It is a very simple cart program including mysql.class.php, global.inc.php and functions.inc.php

So I phased out their example database and re-wrote the script so that when you push the "add to cart" on my shopping page it passes the item id to the cart.php the author wrote.

however when I press "add to cart" this is what I get:

[code]
Notice: Query failed: Unknown column 'x051' in 'where clause' SQL: SELECT itemPrice FROM products WHERE itemId = x051 in /home/content/t/e/t/tetunity/html/shell/data/inc/mysql.class.php on line 109

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/t/e/t/tetunity/html/shell/data/inc/mysql.class.php on line 151

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/t/e/t/tetunity/html/shell/data/inc/mysql.class.php on line 167

Warning: extract(): First argument should be an array in /home/content/t/e/t/tetunity/html/shell/data/inc/functions.inc.php on line 29
[/code]

here are the lines the error is reffering to:
mysql.class.php on line 109

[code]
/**
    * Returns an instance of MySQLResult to fetch rows with
    * @param $sql string the database query to run
    * @return MySQLResult
    * @access public
    */
106  function query($sql) {
107          if (!$queryResource=mysql_query($sql,$this->dbConn))
108              trigger_error ('Query failed: '.mysql_error($this->dbConn).
108                              ' SQL: '.$sql);
109          return new MySQLResult($this,$queryResource);
[/code]

mysql.class.php on line 151
[code]
/**
    * Fetches a row from the result
    * @return array
    * @access public
    */
150      function fetch () {
151          if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) {
152              return $row;
153          } else if ( $this->size() > 0 ) {
154              mysql_data_seek($this->query,0);
155 ..........script continues with some return false commands.....
[/code]

mysql.class.php on line 167
[code]
/**
    * Returns the number of rows selected
    * @return int
    * @access public
    */
166      function size () {
167          return mysql_num_rows($this->query);
168........
[/code]

functions.inc.php on line 29
[code]
29    extract($row);
[/code]

I have a feeling extremely simple is something simple is going right over my head here.
But I don't know what it is. it may have something to do with the fact that the script was written for a database with different keys in the mysql database. however in all the files I don't really see any reference to the old key names.

any tips or suggestions will be greatly appreaciated.

Link to comment
https://forums.phpfreaks.com/topic/31309-solved-integrating-a-cart/
Share on other sites

OK, you'll be able to get rid of the first three errors by changing the sql query.  Look at the first error:

[quote]

Notice: Query failed: Unknown column 'x051' in 'where clause' SQL: SELECT itemPrice FROM products WHERE itemId = x051

[/quote]

This can be corrected by adding single quotes to the query [color=blue]SELECT itemPrice FROM products WHERE itemId = [color=red]'[/color]x051[color=red]'[/color][/color]

This will also remove the second two errors as they're only occurring because the query is failing.

Regards
Huggie
[quote]



This can be corrected by adding single quotes to the query [color=blue]SELECT itemPrice FROM products WHERE itemId = [color=red]'[/color]x051[color=red]'[/color][/color]

[/quote]

Absolutly right. I tested that in myphpadmin and the '  '  does make the query pass without that error.

I think my problem lies here:
[code]
$sql = 'SELECT * FROM products WHERE itemId = '.$id.'';
[code]
the query is already written within single quotes.

more suggestions welcomed. thz so far huggie

More suggestions welcomed.
[/code][/code]
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.