Hi,
I have a small PHP script which tries to retrieve some records from a MySql database (under SuSe Linux Server 8); the problem is when I pass a variable (via a browser or using the Lynx) which should be used by the SQL query, I do not get any results or errors as well.
e.g, the following query does not work:
select * from info where name='$firstname';
while this one works:
select * from info where name = 'Agilo';
Here is the script which I am using:
<?php
/* Connecting, selecting database */
$link = mysql_connect("127.0.0.1:/var/lib/mysql/mysql.sock", "username", "password")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("test") or die("Could not select database");
/* Performing SQL query */
$query = " SELECT * FROM dbtinfo WHERE firstname = '$name' ";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* Printing results in HTML */
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>
-----------------------
I use the following:
$lynx
could you please, help me to figure out why this script does not work.
Thanks in advance,
Agilo
I have a small PHP script which tries to retrieve some records from a MySql database (under SuSe Linux Server 8); the problem is when I pass a variable (via a browser or using the Lynx) which should be used by the SQL query, I do not get any results or errors as well.
e.g, the following query does not work:
select * from info where name='$firstname';
while this one works:
select * from info where name = 'Agilo';
Here is the script which I am using:
<?php
/* Connecting, selecting database */
$link = mysql_connect("127.0.0.1:/var/lib/mysql/mysql.sock", "username", "password")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("test") or die("Could not select database");
/* Performing SQL query */
$query = " SELECT * FROM dbtinfo WHERE firstname = '$name' ";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* Printing results in HTML */
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>
-----------------------
I use the following:
$lynx
could you please, help me to figure out why this script does not work.
Thanks in advance,
Agilo