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;


}

}
}
          ?>

Recommended Answers

All 10 Replies

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...

omg, are you using special security functions on your table structures. it will be a big headache.

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

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

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

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.

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.

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.