July 20, 201016 yr Hi just after a little help as I'm no coder This is my code <?php $db = new Database(); $db->openDatabase(); $result = $db->readFromDatabase("SELECT * FROM items WHERE item_id=$itemid"); $numRecords = $db->numRecords(); $db->closeDatabase(); foreach($result as $record){ $itemname = $record['item_name']; $itemdescription = $record['item_description']; $itemimage = $record['item_image']; $itemprice = $record['item_price']; }?> This is my error Database: Read From Database - MySQL Error: 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 '' at line 1 Could anyone please help Thanks
July 21, 201016 yr Author Try this: $result = $db->readFromDatabase("SELECT * FROM items WHERE item_id={$itemid}"); I think the error occurred because you didn't enclose your variable in curly braces and thus SQL couldn't understand it. But I'm just a beginner here Thanks but still gives me the same error
July 21, 201016 yr Author SELECT * FROM items WHERE item_id='$itemid' @Lev thanks that worked, but for some reason my items are showing with no product name or description Thanks Again
July 21, 201016 yr Author Thanks managed to sort it, changed itemid to item_id, but now got an error with this code <?php if($_POST['delete'] == "Delete"){ $db = new Database(); $db->openDatabase(); $table = "main_menu"; $where = "menu_id=" . $HTTP_POST_VARS['frmCatid']; $db->deleteRecord($table,$where); $db->closeDatabase(); echo "<p>Record Deleted...<a href=" . "categories.php" . ">click here</a> to go back to the category list or select an action from the manu on the right</p>"; } else{ $db = new Database(); $db->openDatabase(); $result = $db->readFromDatabase("SELECT * FROM main_menu WHERE menu_id='$catid'"); $db->closeDatabase(); ?> <?php foreach($result as $record){ $record['menu_title']; $record['menu_id']; }?>
Create an account or sign in to comment