silverglade Posted August 29, 2011 Share Posted August 29, 2011 Awesome, after stripping off about 90% of my code, I found a tiny little error that made the whole thing not work. It was a form error. lol. So I have it working as a tiny skeleton now where it can return data matched LIKE a date of birth in database. But when it doesn't, it is supposed to echo "Sorry there was nothing in db matching that". But that message never appears. Please any advice appreciated. thank you. and that will be it for the night/morning now. lol <?php $host = " "; $database = " "; $username = " "; $password = " *"; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); mysql_select_db($database); if(isset($_POST['submit'])) { $dob= $_POST['dob']; $result = mysql_query("SELECT * FROM users WHERE dob LIKE '%$dob'"); if ($result) { while($row = mysql_fetch_array($result)) { echo $row['dob'] ; echo "<br />"; echo "CONGRATS!! you found one matching date of birth in the DB!"; } } else { echo "<br/> sorry ". $dob . "for date of birth is not in the database"; } } ?> <html> <body> <form action="login_successBACKUP02.php" method="post"> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="submit" name="submit" value="Search database" /> <input type="reset" value="Reset fields" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/245945-got-form-to-work-but-one-problem/ Share on other sites More sharing options...
mjahkoh Posted August 29, 2011 Share Posted August 29, 2011 Replace with this if(mysql_numrows($result) > 0){ Quote Link to comment https://forums.phpfreaks.com/topic/245945-got-form-to-work-but-one-problem/#findComment-1263130 Share on other sites More sharing options...
cyberRobot Posted August 29, 2011 Share Posted August 29, 2011 Replace with this if(mysql_numrows($result) > 0){ Should be mysql_num_rows() http://php.net/manual/en/function.mysql-num-rows.php Quote Link to comment https://forums.phpfreaks.com/topic/245945-got-form-to-work-but-one-problem/#findComment-1263140 Share on other sites More sharing options...
silverglade Posted August 29, 2011 Author Share Posted August 29, 2011 thank you, I made some major changes to the script. I think it is close to doing what I want. I want to enter user data in the form, and the form echoes out any matching data from the database. The problem is, when I type in a 5 for the date of birth form field, all of the $rows, echo out a 5. I didn't want to post all of the code it is long, so I just posted this. Please if anyone can understand it I need help. Thank you. //THE SEARCH FUNCTION $result = mysql_query ( "SELECT * FROM users WHERE dob LIKE '%$dob%' OR gender LIKE '%$gender%' OR race LIKE '%$ethnic%' OR job LIKE '%$job%' OR country LIKE '%$country%' OR state LIKE '%$state%' OR town LIKE '%$town%' OR zip LIKE'%$zip%' OR hobbies LIKE'%hobbies%' OR business LIKE '%$business%' OR religion LIKE'%$religion%' OR social_groups LIKE '%$social%' OR political_groups LIKE'%$political%' OR other_affiliations LIKE ' %$affiliations%' OR buying LIKE '%$buying%' OR selling LIKE '%$selling%' OR links LIKE '%$links%' OR likes LIKE '%$likes%' OR dislikes LIKE'%$dislikes%'"); if ($result) { while($row = mysql_fetch_array($result)) { //put the results on the screen if ($row=$_POST['dob']) echo $row['dob']." date of birth<br/>" ; if ($row['gender'])echo $row['gender']." gender <br/>" ; if ($row['race'])echo $row['race']." ethnicity <br/>" ; if ($row['job'])echo $row['job']."job <br/>"; if ($row['country'])echo $row['country']."country <br/>"; if ($row['state'])echo $row['state']." state<br/>"; if ($row['town'])echo $row['town']." town<br/>"; if ($row['zip'])echo $row['zip']." zip<br/>"; if ($row['hobbies'])echo $row['hobbies']." hobbies<br/>"; if ($row['business'])echo $row['business']." business<br/>"; if ($row['religion'])echo $row['religion']." religion<br/>"; if ($row['social'])echo $row['social']." social<br/>"; if ($row['political'])echo $row['political']." political<br/>"; if ($row['affiliations'])echo $row['affiliations']." affiliations<br/>"; if ($row['buying'])echo $row['buying']."buying <br/>"; if ($row['selling'])echo $row['selling']." selling<br/>"; if ($row['links'])echo $row['links']." links<br/>"; if ($row['likes'])echo $row['likes']." likes<br/>"; if ($row['dislikes'])echo $row['dislikes']." dislikes<br/>"; Quote Link to comment https://forums.phpfreaks.com/topic/245945-got-form-to-work-but-one-problem/#findComment-1263157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.