shoutdots Posted April 22, 2007 Share Posted April 22, 2007 Ok , the problem is i want to fetch values where id=$var['id'] <?php include("mysql_connect.php"); include("edit_remove.php"); $fetch="SELECT * FROM poll_setting WHERE id=$var[id]"; $query=mysql_query($fetch) or die (mysql_error()."<p>$query</p>"); $edit_poll=mysql_fetch_array($query) or die ("can't fetch database"); ?> it keeps giving me this : 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 where is the problem ?? Link to comment https://forums.phpfreaks.com/topic/48124-solved-how-to-fetch-where-idvarid/ Share on other sites More sharing options...
trq Posted April 22, 2007 Share Posted April 22, 2007 Where do you define $var. Also, the correct syntax would be either... $fetch = "SELECT * FROM poll_setting WHERE id = '{$var['id']}'"; or $fetch = "SELECT * FROM poll_setting WHERE id = '" . $var['id'] . "'"; Link to comment https://forums.phpfreaks.com/topic/48124-solved-how-to-fetch-where-idvarid/#findComment-235185 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 I've defined $var from ("edit_remove.php"), all i need to display form to be edit edit_remove.php page: <?php //include data connect file. include ("mysql_connect.php"); //select the fields from database $query="SELECT id, poll_name FROM poll_setting"; //make query here $result =mysql_query($query) or die (mysql_error()."<p>$query</p>"); // execute the query //make while string to fetch all data in the database while ($var=mysql_fetch_array($result)) { ; ?> <tr align="center"> <td bgcolor="#F5F5F5"><span class="style4"><? echo $var['id']; ?></span></td> <td bgcolor="#F5F5F5"><span class="style4"><? echo $var['poll_name']; ?></span></td> <td bgcolor="#F5F5F5"><a href="edit_poll.php?=<? echo $var['id'];?>">Edit Poll</a></td> <td bgcolor="#F5F5F5"> </td> </tr> <? }; ?> edit_poll.php <?php include("mysql_connect.php"); include("edit_remove.php"); $fetch = "SELECT * FROM poll_setting WHERE id = '$var['id']'"; $query=mysql_query($fetch) or die (mysql_error()."<p>$query</p>"); $edit_poll=mysql_fetch_array($query) or die ("can't fetch database"); ?> Link to comment https://forums.phpfreaks.com/topic/48124-solved-how-to-fetch-where-idvarid/#findComment-235188 Share on other sites More sharing options...
Barand Posted April 22, 2007 Share Posted April 22, 2007 The query string needs to be "?id=something" <?php //include data connect file. include ("mysql_connect.php"); //select the fields from database $query="SELECT id, poll_name FROM poll_setting"; //make query here $result =mysql_query($query) or die (mysql_error()."<p>$query</p>"); // execute the query //make while string to fetch all data in the database while ($var=mysql_fetch_array($result)) { echo <<<HTML <tr align="center"> <td bgcolor="#F5F5F5"><span class="style4">{$var['id']}</span></td> <td bgcolor="#F5F5F5"><span class="style4">{$var['poll_name']}</span></td> <td bgcolor="#F5F5F5"><a href="edit_poll.php?id={$var['id']}">Edit Poll</a></td> <td bgcolor="#F5F5F5"> </td> </tr> HTML; } ?> edit.php <?php //include data connect file. include ("mysql_connect.php"); // get the id from the query string $id = $_GET['id']; //select the fields from database for selected id $query="SELECT id, poll_name FROM poll_setting WHERE id = '$id' "; //make query here $result =mysql_query($query) or die (mysql_error()."<p>$query</p>"); // execute the query $row = mysql_fetch_assoc($result); // process record ?> Link to comment https://forums.phpfreaks.com/topic/48124-solved-how-to-fetch-where-idvarid/#findComment-235192 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 thank you very much, done Link to comment https://forums.phpfreaks.com/topic/48124-solved-how-to-fetch-where-idvarid/#findComment-235267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.