Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unable to retrieve records from a MySql DB through PHP 4

Status
Not open for further replies.

agilo

Programmer
Joined
Feb 4, 2004
Messages
73
Location
TR
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
 
a couple of points:

$link = mysql_connect("127.0.0.1:/var/lib/mysql/mysql.sock", "username", "password")
or die("Could not connect : " . mysql_error());

----------------------------------------------------
$link = mysql_connect("localhost", "username", "password")
or die("Could not connect : " . mysql_error());

should be sufficient.
-----------------------------------------------------

echo "Connected successfully";
mysql_select_db("test") or die("Could not select database");

/* Performing SQL query */
$query = " SELECT * FROM dbtinfo WHERE firstname = '$name' ";

how did you get the variable to this page ? POST or GET ?

this variable should be referenced by $_POST[name] or $_GET[name].



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
PHP doesn't create the variables by magic anymore you have to, as KarveR points out use $_POST or $_GET. Which one use use depends on the method attribute on the <form> verb in the calling page.
 
Thank you Guys, strange I had this script running berfore inder Suse 7.3 without declaring the variable via _GET or _POST and it was running. Now after I changed the server I get this problem..

Agilo
 
This is normally down to a change in version of PHP > 4.15 if i remember correctly, whereby register_globals isdefaulted to off or 0 in the php.ini, this was done as security measure and meant that the use of $_POSt or $_GET was then required.


HTH, Karv

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top