Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-26-2004, 07:56 AM   #1
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Rep: Reputation: 18
php mysql variable arguments in query.


I have a small mysql db containing some contact information. It works fine and I can add new records to it using a html/php frontend page.
But when I try to retrieve specific records using the 'name' field, I get some strange results:

This is some of the code in the target (from the form) script:

case "shuser":
$query = "select * from contact where surname = '$p1'";
$result = mysql_query($query, $link);
if (!$result) {
die('Error while showing contact: ' . mysql_error());
echo "<html><head><title>contact info: $p1</title></head><body>";
echo "<table width=\"90%\" border=\"1\" align=\"center\"><tr><td>name</td><td>surname</td><td>phone</td><td>mobile</td><
while($row = mysql_fetch_array($result)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td></tr>";
echo "</table><br/><br/><div align=\"center\"><a href=\"contactDB.php\">return to the homepage</a></div></body></html>";

This query: $query = "select * from contact where surname = '$p1'"; looks ok to me but not to my pc. I can execute it but it don't show anything in the table. I have to use '$p1' because I get an error if I omit the '
In mysql itself, I can execute the query without any problem but then I don't use any variables. Even when I change the variable for a fixed value, I get no results.
Any ideas?



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
php mcrypt cookie - mysql query lemack Linux - Security 3 02-09-2005 09:21 AM
php/,mysql problem: can't query JJX Linux - General 4 01-06-2005 05:10 PM
php: Why Can't I Query Mysql DB?? flamesrock Programming 7 11-16-2004 12:36 AM
How to pass mysql query to a variable? chynna_v Programming 4 09-03-2004 05:09 AM
PHP MySQL Query Question vi0lat0r Programming 1 07-15-2004 05:02 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration