0

Hi, I have been learning PHP/Mysql for only a few moths and am working on my own dynamic web-site. Stuck on what is probably very simple.

User inputs name($name)in form.
Table containing it has 15 fields - $name could be in any or none
How do I put $name into a query that will find the field it is in and echo the row ?

Thank you to anyone replying.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by cwarn23
0

It's difficult to figure out what you are trying to do. However you could select an entire row and then use WHERE in your query.
i.e.

SELECT * FROM yourtable WHERE id=uniquenumber AND name=$name;

or rather (excuse my pseudocode:

SELECT * FROM yourtable WHERE id=uniquenumber;
if ($name exists) {
//do something
}

Edited by Feemacbee: n/a

-1
$name=mysql_real_escape_string($_GET['name']);
$r=mysql_query('SELECT * FROM `table` WHERE `column1`="'.$name'" OR  `column2`="'.$name'" OR  `column3`="'.$name'" OR  `column4`="'.$name'" OR  `column5`="'.$name'" OR  `column6`="'.$name'" OR  `column7`="'.$name'" OR  `column8`="'.$name'" OR  `column9`="'.$name'" OR  `column10`="'.$name'" OR  `column11`="'.$name'" OR  `column12`="'.$name'" OR  `column13`="'.$name'" OR  `column14`="'.$name'" OR  `column15`="'.$name'"') or die(mysql_error());

if (mysql_num_rows($r)>0) {
//it exists
$row=mysql_fetch_assoc($r);
echo '<xmp>'; print_r($row); echo '</xmp>';
} else {
echo 'No results found.';
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.