|
-
Jan 10th, 2011, 05:12 PM
#1
Thread Starter
Member
How to get wrong values when executing MySQL query?
0
down vote
favorite Hi
Let's say that I have this query:
Code:
SELECT * FROM students_results WHERE full_name LIKE '".trim($_POST['full_name'])."' AND mother_name LIKE '".$database->escape_value(trim($_POST['mother_name']))."' AND birthday = '".$database->escape_value($_POST['year2'])."'"
I need to display a message for the vistor to tell him that he entered a wrong name or wrong mother name or wrong year.
Now, I display a message for the user that he entered wrong values, I want to display detailed information about what wrong values he entered.
for example, if the user entered wrong name and year, mother name are right, I want to tell him that you entered a wrong name. How I can do that?
Thanks in advance.
-
Jan 10th, 2011, 05:45 PM
#2
Junior Member
Re: How to get wrong values when executing MySQL query?
What i would do personally is query each row individually, i'm sure theres a more efficient way but i'm not the best at php...but this is how i'd do it...
PHP Code:
<?php
$query=mysql_query("SELECT * FROM students_results WHERE full_name LIKE '".trim($_POST['full_name'])."' AND mother_name LIKE '".$database->escape_value(trim($_POST['mother_name']))."' AND birthday = '".$database->escape_value($_POST['year2'])."'")
$count=mysql_num_rows($query)
if($count==0)
{
echo "Nothing found";
die();
}
else
{
while($row=mysql_fetch_array($query)
{
if($row['full_name']==0)
{
echo "Full name not found";
}
if($row['mother_name']==0)
{
echo "Mother name not found";
}
//etc etc
}
}
?>
that's how i'd do it, if the above doesn't work it may need some tweaking. Admins/mods feel free to edit if this doesn't work...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|