raj
raj

Reputation: 129

data not getting fetched

I am using this code for fetching data from database , I am getting $data fetched properly but i am not getting data properly in this variable $seldata why is it so

<?php
    include_once("includes/connection.php");
    include_once("includes/session.php");
    //echo $_SESSION['uid'];
    $sql="SELECT * FROM employee WHERE eid = '{$_GET['id']}'";
    $result=mysql_query($sql);
    $data=mysql_fetch_array($result);
    echo "data".$data;
    $sel_valsql="select * FROM selected_candidate WHERE eid = '{$_GET['id']}'";
    $sresult=mysql_query($sel_valsql);
    $seldata=mysql_fetch_array($sresult);
    echo "seledata".$seldata;       
?>

Upvotes: 0

Views: 102

Answers (3)

Nirmal Ram
Nirmal Ram

Reputation: 48

<?php
include_once("includes/connection.php");
include_once("includes/session.php");
//echo $_SESSION['uid'];
$sql="SELECT * FROM employee WHERE eid = '".$_GET['id']."'";
$result=mysql_query($sql);
$data=mysql_fetch_array($result);
echo "data".$data;
$sel_valsql="select * FROM selected_candidate WHERE eid = '".$_GET['id']."'";
$sresult=mysql_query($sel_valsql);
$seldata=mysql_fetch_array($sresult);
echo "seledata".$seldata;       
?>

Note: mysql_fetch_array() returns an array of results so you need to do print_r($seldata) in order to view the results.

Upvotes: 1

J.K.A.
J.K.A.

Reputation: 7404

Remove the single quote form the where condition i.e.

$sql="SELECT * FROM employee WHERE eid = {$_GET['id']}";

or do like this:

$sql = "SELECT * FROM employee WHERE eid = '" . $_GET['id'] . "'";

Upvotes: 0

John Woo
John Woo

Reputation: 263933

try this,

$sql = "SELECT * FROM employee WHERE eid = '" . $_GET['id'] . "'";

As a sidenote, the query is vulnerable with SQL Injection if the value(s) came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.

Upvotes: 1

Related Questions