dwex Posted January 21, 2011 Share Posted January 21, 2011 $sql = "select * from {$tab} WHERE {$tab}_id ='".$id."'"; This was the 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 'WHERE '_id' ='11/'' at line 1 Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/ Share on other sites More sharing options...
Valakai Posted January 21, 2011 Share Posted January 21, 2011 $sql = 'SELECT * FROM '.$tab.' WHERE '.$tab.'_id = \''.$id'\''; or $sql = "SELECT * FROM ".$tab." WHERE ".$tab."_id = '".$id."'"; both work. Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163018 Share on other sites More sharing options...
dwex Posted January 21, 2011 Author Share Posted January 21, 2011 thx for the reply. still the same error though :/ Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163023 Share on other sites More sharing options...
dwex Posted January 21, 2011 Author Share Posted January 21, 2011 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 'WHERE _id = ''' at line 1 Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163030 Share on other sites More sharing options...
Valakai Posted January 21, 2011 Share Posted January 21, 2011 What is the value of $tab and $id? From the looks of the first error, $tab doesn't have a value and $id would be 11/' and in the second $tab is still empty and $id is a single quote Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163031 Share on other sites More sharing options...
Pikachu2000 Posted January 21, 2011 Share Posted January 21, 2011 Echo $sql. It looks like $tab (and now possibly $id also) is undefined or empty. Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163034 Share on other sites More sharing options...
dwex Posted January 21, 2011 Author Share Posted January 21, 2011 Is there something wrong with the codes here? Edit button <form action='edititemadmin.php' method='get'> <input type='hidden' id='id' name='id' value=<?php echo $row["{$tab}_id"]?>/> <input type='hidden' id='table' name='table' value=<?php echo $tab;?>/> <br> <input type="submit" Value="Edit"/> </br> </form> Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163053 Share on other sites More sharing options...
Pikachu2000 Posted January 21, 2011 Share Posted January 21, 2011 Where/how are the values from the $_GET array assigned to the variables in the script? Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163055 Share on other sites More sharing options...
Valakai Posted January 21, 2011 Share Posted January 21, 2011 Well theres no quotes around the value= attributes in the input elements. Can you do an echo() or var_dump() on $tab and $id? Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163056 Share on other sites More sharing options...
dwex Posted January 21, 2011 Author Share Posted January 21, 2011 $tab = $_POST['table']; $HOST = 'localhost'; $USERNAME = 'root'; $PASSWORD = ''; $DB = 'pbstore'; $link = mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB) or die(mysqli_connect_error()); $sql = "SELECT {$tab}_id , {$tab}_name , {$tab}_price , {$tab}_description , {$tab}_image , {$tab}_stock , {$tab}_time FROM {$tab}"; $result = mysqli_query($link, $sql) or die(mysqli_error($link)); $tab is working as I'm able to display the things I want on the page. Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163057 Share on other sites More sharing options...
dwex Posted January 21, 2011 Author Share Posted January 21, 2011 oh mine , it works now. I think the missing quotes around value='<?php echo $tab;?>'/> was the problem. thanks for your help guys! Link to comment https://forums.phpfreaks.com/topic/225189-what-is-the-correct-syntax-for-this/#findComment-1163067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.