php and mysql retrieve data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eeau1973
Forum Commoner
Posts: 27
Joined: Sat Aug 19, 2006 4:49 pm

php and mysql retrieve data

Post by eeau1973 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi folks ..

I´m trying to build a php script that retrieve data from a mysql database, but the issue is that i get no result when submit a field that later showme that information related ....

here is my script until now ...

file lookfor.php

[syntax="html"]<form action=findok.php method=GET>
    Please input id to look for 
    <input name=idkey type=text id="idkey" 
    <input name="submit" type=submit id="submit" value="look for it ! ...">
    </font> </p>
</form>
here´s findok.php[/syntax]

Code: Select all

<?php 
mysql_connect (localhost, user, passwd);
mysql_select_db (database_name);
if ($idkey == "")
{$idkey  = '';}

$result = mysql_query ("SELECT * FROM table_name 
WHERE idkey LIKE '$idkey'");
if ($row = mysql_fetch_array($result)) {
do {
echo ("Id Key: "); print $row["Id Key"]; print ("<p>");
echo ("Show field2 : ");  print $row["field2"]; 
echo (" Show field 3 "); print $row["field3"]; 
echo ("  Show field 4 ");  print $row["field4"]; print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "there is no info avaliable, please review the idkey...";}
?>

I have 2 weeking working on this issue with no results :cry:

Any idea ? .. Why i´m not getting the information that match the criteria that the user is looking for ?

thanks in advance ...

greetings


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

Please use the correct syntax highlighters..

your Id Key column name below, does not match the one in your query. ie. idkey NOT Id Key

Code: Select all

echo ("Id Key: "); print $row["Id Key"]; print ("<p>");
and..

Code: Select all

$result = mysql_query ("SELECT * FROM table_name
WHERE idkey LIKE '$idkey'");
if ($row = mysql_fetch_array($result)) {
do {
echo ("Id Key: "); print $row["Id Key"]; print ("<p>");
echo ("Show field2 : "); print $row["field2"];
echo (" Show field 3 "); print $row["field3"];
echo (" Show field 4 "); print $row["field4"]; print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "there is no info avaliable, please review the idkey...";}
should be more like:

Code: Select all

$result = mysql_query ("SELECT * FROM table_name WHERE idkey LIKE '$idkey'");
while($row = mysql_fetch_array($result)) {
echo "Id Key: " . $row['idkey'] . "<p>";
echo "Show field 2: " . $row['field2'];
echo "Show field 3: " . $row['field3'];
echo "Show field 4: " . $row['field4'] . "<p>";
}
Post Reply