0

hello friend i have two table studentlogin and seconed studentinfo

i want that when student login i like to select rollno from student login table
in student login there is four field sloginid, rollno, username and password

now when rollno fetched succesfully from studentlogin table i like to fetch s_id from studentinfo where rollno will equal to studentlogin table, in studentinfo table here also rollno column.
and i used this query but it give error
Unknown column '0818cs091040' in 'where clause'

it is giving this erro
Unknown column '0818cs091040' in 'where clause'
here is code that i used

<?php 
session_start();

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("sfcs") or die(mysql_error());
          $loginid=$_SESSION['logid'];

          $sql="select rollno from studentlogin where sloginid=".$loginid;


          $query = mysql_query($sql) or die(mysql_error());

$num = mysql_num_rows($query);
if($num >0)
{

while($rows = mysql_fetch_object($query))
{

$rollno=$rows->rollno;
}

$sql="select s_id from studentinfo where roll_no=".$rollno or die(mysql_error());

$query = mysql_query($sql) or die(mysql_error());

$num = mysql_num_rows($query);
if($snum >0)
{

while($rows = mysql_fetch_object($query))
{
$sid=$rows->s_id;


}

}
}
          ?>

Edited by er.durgeshkumar: make change in this

5
Contributors
10
Replies
32
Views
4 Years
Discussion Span
Last Post by masterjiraya
0

Can we see your table structure, including data types? I'm not currently seeing anything to cause this. Also, your errors should indicate what line they are occurring on...

0

here is images of my database table for student information and student login

Attachments studentinfo.png 13.51 KB
0

$sql="select rollno from studentlogin where sloginid=".$loginid;

You dont have a column 'sloginid' in dbase shown, so you get above error.

0

Change $sql="select s_id from studentinfo where roll_no=".$rollno or die(mysql_error()); to

$sql="select s_id from studentinfo where roll_no='".$rollno."'";

roll_no is a VARCHAR field, so you may need quotes around the value. There's no reason for the or die() here, you're just assigning a value to $sql. See if that helps.

0

Same goes for $sql="select rollno from studentlogin where sloginid=".$loginid;

this query is ending at the second double quote, so you need to extend it

change to $sql="select rollno from studentlogin where sloginid='".$loginid."'";

or $sql="select rollno from studentlogin where sloginid='$loginid'"; will
do the same.

0

It is not advisable to use special security functions in your table structures unless you are fully aware of them.

0

this query is ending at the second double quote, so you need to extend it

That one should be fine, actually. The concatenation operator should tack the ID on to the end of the string, and since sloginid is an INT, it doesn't need quotes around the value.

0

how did you insert values to these certain tables. i can see that thief starts from the innsertion of these 2 tables

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.