Jump to content

[SOLVED] how to fetch where id=$var['id'] ??


shoutdots

Recommended Posts

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

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");

  ?>

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.