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.

Member Avatar for Feemacbee

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
}
$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.';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.