ckdoublenecks Posted September 16, 2010 Share Posted September 16, 2010 I have a database with records containing fields named "compmo" which are int(2). The below code results in the message "No listing for the month". I print out the file and check the database and there are records that match? <?php mysql_connect(localhost,root,""); mysql_select_db(maintdb) or die( "Unable to select database"); if(!empty($_POST["submit"])) { $compmo = $_POST['compmo']; $query="SELECT * FROM maintdata Where compmo='$compmo' ORDER BY apt ASC, datereceived DESC "; $result=mysql_query($query); if(mysql_num_rows($result)) { echo "<form action='#' method='post'><b>Poject: Maintenance Log</b><br><br> <table cellspacing=5 cellpadding=0 border='0'> <tr> <TH>Apt</TH> <TH>Name</TH> <TH>Received</TH> <TH>Time</TH> <TH>Problem</TH> <TH>Correction</TH> <TH colspan=3>Finished</TH> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['apt'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['datereceived'] . "</td>"; echo "<td>" . $row['time'] . "</td>"; echo "<td>" . $row['symptom'] . "</td>"; echo "<td>" . $row['action'] . "</td>"; echo "<td>" . $row['compmo'] . "</td>"; echo "<td>" . $row['compday'] . "</td>"; echo "<td>" . $row['compyear'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</form>"; } else{echo "No listing for the month $compmo.<br />";} } ?> <form method="post" action="#"> <br /> <input type="text" name="month"/> <p> <input type="submit" name="submit" value="select maintenance month"/> </form> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 16, 2010 Share Posted September 16, 2010 You aren't doing anything to see if $_POST['compmo'] has a value. If it had a value, the message you'd be getting would be "No listing for the month [value of $compmo], or the query would return results. Quote Link to comment Share on other sites More sharing options...
ckdoublenecks Posted September 17, 2010 Author Share Posted September 17, 2010 I changed this $result=mysql_query($query); to this $result = mysql_query($check) or die(mysql_error()); //remove when working and went from: "Warning: mysql_num_rows() expects parameterNo listing for the month ." 1 to be resource, boolean given in C:\xampp\htdocs\hofiles\testing.php on line 11 to: "query was empty" As I posted, the records all have the field named "compmo" and one of them has the value that I am entering. the values could be from 1-12 - int(2). at this point the highest is 1 digit (9)? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 17, 2010 Share Posted September 17, 2010 Your "to this" code isn't using the correct variable name in the mysql_query(...) statement. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 17, 2010 Share Posted September 17, 2010 Also, I'm certain this: $compmo = $_POST['compmo']; should be this: ? $compmo = $_POST['month']; Since the name attribute in the form is 'month'. And you have nothing in that script to protect you against SQL injections. Quote Link to comment Share on other sites More sharing options...
chintansshah Posted September 17, 2010 Share Posted September 17, 2010 Please change your input box name to "compmo" Because you element name and what you have written in the query are different. Quote Link to comment Share on other sites More sharing options...
ckdoublenecks Posted September 17, 2010 Author Share Posted September 17, 2010 thanks for your help guys , you're great Quote Link to comment Share on other sites More sharing options...
pkphp Posted September 20, 2010 Share Posted September 20, 2010 i can't agree more for chintansshah. Quote Link to comment Share on other sites More sharing options...
chintansshah Posted September 20, 2010 Share Posted September 20, 2010 @pkphp Can you tell me where is a mistake in my suggestion? Quote Link to comment 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.