Question Locked

What is wrong in my code

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

I am trying to collect data from MySQL and to assign the result to a PHP variable for further processing, but no assigment is made - the variable is empty:( here is the code

$name = $_GET['companyName'];

$index = $_GET['indName'];

$db_name = "clients";

$connection = mysql_connect("localhost", "user", "pass") or die("Could not connect.");

mysql_select_db($db_name,$connection);

$query = "Select companyID from company where name= '".$name."' and indexNAME= '".$index."'";

// I check the query and it's OK - return the correct value

$result = mysql_query($query, $connection) or die ("Could not execute query");

while ($row = mysql_fetch_array($result));

{
echo "$row[0] gragra";
$companyID = $row[0];
}

echo "$companyID blabla ";

the output is gragra blabla

Can someone explain me what I am doing wrong.

Thanks

5 replies

by john.a.wills

$query = "Select companyID from company where name= '".$name."' and indexNAME= '".index."'";
I think you need a $ before index. I do not know that that is the whole problem.

by ivoyanev

no this is a type mistake, because I test the query without variables.

Anything else you see?

After seeing other post may be it's necessary to say that the returnet value is one sigle number.

This discussion is closed to new replies.