First off when it comes to PHP I feel like a total NOOB however I am a newbie with PHP so IO guess that's okay as long as I don't remain a NOOB forever. With that said here is my problem.
I am working on my first PHP website and I am having nothing but problems with it
The site is supposed to find fairs and festivals that are happening on a certain date.
So far I put one fair in my database with the fairopen (open date) set to 2010-06-14
and the fairclose field (closing date) set to 2010-07-05
However when I do a search using any of those dates (and any in between) using my website that I am developing I come up with this displayed on my screen
Array
(
[month] => 06
[serdate] => 20
[seryear] => 2010
[submit] => Submit
)
1
I have no rows to display
The first 8 lines were put in to test what I'm doing wrong and why there is nothing being displayed the exact code I am using is my form I will post 2 forms one is an html version that is what I used here and i will show the results with the php version last.
<p align="center"><select size="1" name="month"><option selected
value=01>Jan</option> <option value="02">Feb</option>
<option value="03">Mar</option> <option value="04">Apr</option>
<option value="05">May</option> <option
value=06>June</option> <option value="07">July</option>
<option value="08">Aug</option> <option value="09">Sept</option>
<option value="10">Oct</option> <option value="11">Nov</option>
<option value="12">Dec</option>
<\SELECT></select> <select size="1"
name=serdate><option selected value=01>01</option> <option
value=02>02</option> <option value="03">03</option> <option
value=04>04</option> <option value="05">05</option> <option
value=06>06</option> <option value="07">07</option> <option
value=08>08</option> <option value="09">09</option> <option
value=10>10</option> <option value="11">11</option> <option
value=12>12</option> <option value="13">13</option> <option
value=14>14</option> <option value="15">15</option> <option
value=16>16</option> <option value="17">17</option> <option
value=18>18</option> <option value="19">19</option> <option
value=20>20</option> <option value="21">21</option> <option
value=22>22</option> <option value="23">23</option> <option
value=24>24</option> <option value="25">25</option> <option
value=26>26</option> <option value="27">27</option> <option
value=28>28</option> <option value="29">29</option> <option
value=30>30</option> <option value="31">31</option>
<\SELECT></select> <select size="1"
name=seryear><option selected value=2010>2010</option>
<option value="2011">2011</option> <option
value=2012>2012</option> <option value="2013">2013</option>
<option value="2014">2014</option> <option
value=2015>2015</option> <\SELECT></select></p>
<p align="center"><input value="Submit" type="submit" name="submit"><input value="Reset"
type="reset" name="reset"></p></form>
Now the PHP version of the code is this
<?php
$months = array (1 => 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
$days = range (1, 31);
$years = range (2008, 2015);
?>
<form action="searchdays.php" method="post">
<p>Month:<select name="month">
<?php
foreach ($months as $value) {
echo '<option value="'.$value.'">'.$value.'</option>\n';
}
?>
</select></p>
<p>Day:<select name="day">
<?php
foreach ($days as $value) {
echo '<option value="'.$value.'">'.$value.'</option>\n';
}
?>
</select></p>
<p>Year:<select name="year">
<?php
foreach ($years as $value) {
echo '<option value="'.$value.'">'.$value.'</option>\n';
}
?>
</select></p>
<input type="submit" name="submit" value="submit" />
</form>
which in turn when processed the searchdays.php file will return this
Array
(
[month] => Jun
[day] => 20
[year] => 2010
[submit] => submit
)
1
I have no rows to display
the searchdays.php file has the following for code
<?php
echo "<pre>";
echo print_r($_POST);
echo "</pre>";
?>
<html>
<body>
<?php
$username="myusername";
$password="mypassword";
$database="mydatabase";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$date = $year.'-'.$month.'-'.$day;
$query="SELECT * FROM events WHERE fairopen >= '$date' AND fairclose <= '$date'";
$result=mysql_query($query);
if (mysql_num_rows($result) == 0) // Exits if your db table is empty
{
echo 'I have no rows to display';
exit;
}
$num=mysql_num_rows($result);
mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Value1</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value2</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value3</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value4</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value5</font></th>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"fairname");
$f2=mysql_result($result,$i,"fairadd");
$f3=mysql_result($result,$i,"faircity");
$f4=mysql_result($result,$i,"faircty");
$f5=mysql_result($result,$i,"fairstate");
?>
<tr>
<font face="Arial, Helvetica, sans-serif">Fair Name <?php echo $f1; ?></font><br>
<font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font><br>
<font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font><br>
<font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font><br>
<font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font><br>
</tr>
<?php
$i++;
}
?>
</body>
</html>
Can someone please tell me what I'm doing wrong ( since i'm searching the date 2010-06-20 it should show me the fair that I have entered.
Also how I can get the php version of the form show to user filling out the form the months i.e Jan Feb Mar but return to searchdays.php the values 01 02 03 respectfully