\n"; It should help you to debug. -- Toby A Inkster BSc (Hons) ARCS Contact Me ~ http://tobyinkster.co.uk/contact Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux * = I'm getting there! [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <2ba9d4-eft.ln1@ophelia.g5n.co.uk> [ref] => <1174519539.016220.279960@n76g2000hsh.googlegroups.com> [htmlstate] => on_nl2br [postusername] => Toby [ip] => usenet200703@to [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> PHP saying error in mysql syntax, but written my mysql query browser! - MySQL
Professional Web Applications Themes

PHP saying error in mysql syntax, but written my mysql query browser! - MySQL

Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>function.extract]: First argument should be an array in functions.inc.php on line 31 Notice: Undefined variable: price in functions.inc.php on line 36 Notice: Undefined variable: price in functions.inc.php on line 39 Notice: ...

  1. #1

    Default PHP saying error in mysql syntax, but written my mysql query browser!

    Hi,

    I have a basic db that I access with MySQL query browser. Everything
    seems fine to me but I am using this db as part of a php shopping
    basket and when I try to add an item I get:

    Notice: Query failed: You have an error in your SQL syntax; check the
    manual that corresponds to your MySQL server version for the right
    syntax to use near '>function.extract]: First argument should be an
    array in functions.inc.php on line 31
    Notice: Undefined variable: price in functions.inc.php on line 36
    Notice: Undefined variable: price in functions.inc.php on line 39
    Notice: Undefined variable: total in unctions.inc.php on line 39

    I'm assuming the last three are caused by this problem as price should
    be passed to the cart, and total is worked out using it. However
    although I know mySQL code it was the MySQL query browser that
    actually generated the code and I cannot see a way to view or debug
    the code.

    The db has one table in it which is made up of id, name, subname,
    desc, and price.

    The code in the php file that is being referred to is:

    <?php
    function writeShoppingCart() {
    $cart = $_SESSION['cart'];
    if (!$cart) {
    return '<p>You have no items in your shopping cart</p>';
    } else {
    // P 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>';
    }
    }

    function showCart() {
    global $db;
    $cart = $_SESSION['cart'];
    $output[] = "<form action='cart.php?action=update' method='post'
    id='cart'>";
    $output[] = "<table><tr><td>ID</td>";
    $output[] = "<td>Name</td>";
    $output[] = "<td>Price</td>";
    $output[] = "<td>Quan</td>";
    $output[] = "<td>Subtotal</td></tr>";
    if ($cart) {
    $items = explode(',',$cart);
    $contents = array();
    foreach ($items as $item) {$contents[$item] =
    (isset($contents[$item])) ? $contents[$item] + 1 : 1;}
    foreach ($contents as $id=>$qty) {
    $sql = 'SELECT * FROM acc WHERE id = '.$id;
    $result = $db->query($sql);
    $row = $result->fetch();
    extract($row);
    $output[] = "<tr><td>".$item['id']."</td>";
    $output[] = "<td>".$item['info']."</td>";
    $output[] = "<td>".number_format($item['price'],2)."</td>";
    $output[] = "<td>".$item['qty']."</td>";
    $output[] = "<td>&pound;".($price * $qty)."</td>";
    $output[] = "<td><form method=post><input
    type='hidden' name='id' value='".$item['id']."'/>";
    $output[] = "<input type='submit' name='remove' value='X'/></form></
    td></tr>";
    $total += $price * $qty;
    }
    $output[] = "<tr><td colspan=4>Sub total:</td><td>".$total."</td></
    tr>";
    $output[] = "<tr><td colspan=4>VAT:</td><td>".($total * 0.175)."</
    td></tr>";
    $output[] = "<tr><td colspan=4>Grand total:</td><td>".($total *
    1.175)."</td></tr>";
    $output[] = "<div><button type='submit'>Update cart</button></div>";
    $output[] = "</table></form>";
    } else {
    $output[] = "<tr><td colspan=5>- No items found in cart -</td></tr></
    table>";
    }
    return join('',$output);
    }
    ?>

    So I can't see any problems that would be causing this other than the
    db problem but can't find out what that is exactly!

    Any help appreciated
    Thanks, Flic

    Flic Guest

  2. #2

    Default Re: PHP saying error in mysql syntax, but written my mysql querybrowser!

    Flic wrote:
     

    Try adding this:

    print "<!--{$sql}-->\n";

    It should help you to debug.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

    * = I'm getting there!
    Toby Guest

  3. #3

    Default Re: PHP saying error in mysql syntax, but written my mysql querybrowser!

    Flic wrote: 

    Did your query succeed? You assume it did and never check for errors on
    the query. And even if it did succeed, did it return any rows? You're
    assuming it id.

    Neither are valid assumption.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

Similar Threads

  1. Error with MySql Query Browser
    By Alfred in forum MySQL
    Replies: 2
    Last Post: October 1st, 04:46 PM
  2. Replies: 0
    Last Post: January 29th, 02:03 PM
  3. mySQL syntax error
    By Wm in forum PHP Development
    Replies: 3
    Last Post: August 16th, 09:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139