Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Is my code correct

Featured Replies

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

  • 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 :D

 

 

Thanks but still gives me the same error

SELECT * FROM items WHERE item_id='$itemid'

  • 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

Cannot say something definitely without seeing the code.

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.