-3

There is error in line 6.This the profile.php file can any one please help me

<?php
require_once('../connect.php');

$id = $_GET['id']; //getting the param

$row = mysql_fetch_array(mysql_query("SELECT * FROM student WHERE roll_no =" . $id));
//echo $id;
echo "<div class='profile'><h4>Student Profile</h4><h5>Name: </h5><p>" . $row['name'] . "</p>";
echo "<h5>Roll no: </h5><p>" . $row['roll_no'] . "</p>";
echo "<h5>Program: </h5><p>" . $row['program'] . "</p>";
echo "<h5>Branch: </h5><p>" . $row['branch'] . "</p>";       
echo "<h5>Agg. marks: </h5><p>" . $row['agg_marks'] . "</p>";
echo "<h5>Phone no. </h5><p>" . $row['phone'] ."</p>";
echo "<img src='imgsize.php?w=100&h=100&img=ajax/img_student/" . $row['roll_no'] ."." . $row['imgext'] . "'" . "width =100 height = 100 /></div>";

?>

  • Please don't use any mysq_* functions as they are deprecated. Consider using [PDO](http://be1.php.net/pdo) or [MySQLi](http://php.net/manual/en/book.mysqli.php) – DarkBee Sep 30 '13 at 10:31
  • 1
    You’ve probably created an invalid query (e.g., `$_GET['id']` is empty). Just print the resulting query and you’ll see it. Furthermore, your script is vulnerable to SQL injections. – Gumbo Sep 30 '13 at 10:31
  • Can you please tell me with the code i am the beginner in php – user2830750 Sep 30 '13 at 10:36

2 Answers2

0

you have syntax errors at some lines and here is the corrected answer. Think you are a beginner as i'm.

<?php
require_once('../connect.php');

$id = $_GET['id']; //getting the param

$row = mysql_fetch_array(mysql_query("SELECT * FROM student WHERE roll_no ='". $id."'     
"));
//echo $id;
echo "<div class='profile'><h4>Student Profile</h4><h5>Name: </h5><p>" . $row['name'] .     
"</p>";
echo "<h5>Roll no: </h5><p>" . $row['roll_no'] . "</p>";
echo "<h5>Program: </h5><p>" . $row['program'] . "</p>";
echo "<h5>Branch: </h5><p>" . $row['branch'] . "</p>";       
echo "<h5>Agg. marks: </h5><p>" . $row['agg_marks'] . "</p>";
echo "<h5>Phone no. </h5><p>" . $row['phone'] ."</p>";
echo "<img src='imgsize.php?w=100&h=100&img=ajax/img_student/" . $row['roll_no'] ."." .    
$row['imgext'] . "'" . "width =100 height = 100 /></div>";

?>
belekka
  • 81
  • 2
  • 13
0

Change your code:

$sql="SELECT * FROM student WHERE roll_no =" . $id;
$result =mysql_query($sql);

while($row =mysql_fetch_array($result))
{
    print_r($row);
}

instead of

$row = mysql_fetch_array(mysql_query("SELECT * FROM student WHERE roll_no =" . $id));
Guru
  • 633
  • 1
  • 4
  • 12