0
<?php 
session_start();
$con=mysql_connect("localhost","root","samy");
mysql_select_db("project");
if($con)
{
    echo "Connected Successfully "; 
}
else
{
    echo "Error" . $sql . "<br>" . mysql_connect_error();
}
$name=$_SESSION['name'];
echo $name;
$sql1 = mysql_query("select cust_id from registered_user where name ='.$name.' ");
$r = mysql_num_rows($sql1);      
echo $r;
$row1 = mysql_fetch_array($sql1);
$cid = $row1['cust_id'];
echo $cid;
?>

Since num_rows is returning zero therefore $cid is also not printing. Don't know what's the error;

1 Answer 1

1

You should remove the dot(.).

$sql1 = mysql_query("select cust_id from registered_user where name ='$name'");
                                                                     ^     ^

Also suggest to add error reporting like this

$sql1 = mysql_query("select cust_id from registered_user where name ='$name'") 
        or die(mysql_error());
Sign up to request clarification or add additional context in comments.

2 Comments

That, or keep the dots but add quotes name ='".$name."'
This though $r = mysql_num_rows($sql1); echo $r; may throw an error when OP adds error reporting. Is not using mysql_num_rows() correctly. I think that will throw a "convert to string" error, if I do recall. If OP wants to check if there is a row, then would need to use something like if(mysql_num_rows($sql1) > 0){...}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.