Jump to content

can someone look at this code?


ckdoublenecks

Recommended Posts

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>

 

 

Link to comment
https://forums.phpfreaks.com/topic/213613-can-someone-look-at-this-code/
Share on other sites

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.

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)?

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.