Question

Locked

What is wrong in my code

By IvoYanev ·
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

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

missing dollar

by john.a.wills In reply to What is wrong in my code

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

Collapse -

this is not the problem

by IvoYanev In reply to missing dollar

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.

Collapse -

It's the quotes

by Tony Hopkinson In reply to What is wrong in my code

echo $companyID

Some info.

http://php.net/manual/en/language.variables.variable.php

Collapse -

thank you

by IvoYanev In reply to It's the quotes
Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums