My problem is when you add a venue using the form I created it does not allow me to because of an error with "time" and "date"... Feel free to add a TEST venue to see the error url is above..Also I am new to PHP so any other comments or suggestions will be helpful.... The php and html is below,
Code: Select all
[color=#0000FF]<?php # add_venue.php
// Include the database connection script:
require_once('mysql.inc.php');
// Array for handling errors:
$errors = array();
// Validate the required data;
if (!empty($_POST['venue'])) {
$ve = mysql_real_escape_string($_POST['venue'], $dbc);
} else {
$errors[] = 'venue';
}
if (!empty($_POST['thisdate'])) {
$da = mysql_real_escape_string($_POST['thisdate'], $dbc);
} else {
$errors[] = 'date';
}
if (isset($_POST['city_id']) && is_numeric($_POST['city_id']) && ($_POST['city_id'] > 0)) {
$cid = (int) $_POST['city_id'];
} else {
$errors[] = 'city';
}
if (isset($_POST['thistime']) && is_numeric($_POST['thistime']) && ($_POST['thistime'] > 0)) {
$ti = (int) $_POST['thistime'];
} else {
$errors[] = 'time';
}
if (!$errors) { // If no errors, add the venue.
// Run the query:
/* ######################
COMPOSE the DATE
Note that each component of the date should be validated before you compose them for the datebase
######################## */
$thisDate = "{$_POST['M']}/{$_POST['D']}/{$_POST['Y']}";
$q = "INSERT INTO venues VALUES (NULL, '$cid', '$thisDate', '$ti', '$ve')";
echo $q;
// $r = mysql_query($q, $dbc);
// Check that the query worked:
/*
if (mysql_affected_rows($dbc) == 1) {
echo '<p><strong>The Concert Information has been added.</strong></p>';
} else { // Query failure.
echo '<p class="error">The Concert Information could not be added due to a system error.</p>';
}
*/
} else { // Errors!
echo '<p>The following errors occurred:</p><ul class="error">';
// Print each error:
foreach ($errors as $e) {
echo "<li>Please enter a valid $e.</li>\n";
}
echo '</ul>';
}
// Close the database connection.
//mysql_close($dbc);
?>
</body>and the HTML
Code: Select all
<div id="results"></div>
<form action="add_venue.php" method="post" id="venue_form">
<p><label class="title" id="venue_label">Venue <input type="text" id="venue" name="venue" /></label> </p>
<p>
<label class="title" id="date_label">Month
<select name="M">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
</label>
<label class="title" id="date_label">Day
<select name="D">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
</label>
<label class="title" id="date_label">Year
<select name="Y">
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
</select>
</label>
</p>
<p><label class="title" id="time_label">Time <input type="text" id="time" name="thistime" /></label> </p>
<p><label class="title" id="city_id_label">City <select id="city_id" name="city_id">
<option value="1">College Station </option>
<option value="2">Conroe</option>
<option value="3">Cypress</option>
<option value="4">Freiheit</option>
<option value="5">Humble</option>
<option value="6">Hunter</option>
<option value="7">Magnolia</option>
<option value="8">Mont</option>
<option value="9">Montgomery</option>
<option value="10">Navasota</option>
<option value="11">Porter</option>
<option value="12">Spring</option>
<option value="13">Texas</option>
<option value="14">Tomball</option>
<option value="15">Old Town Spring</option>
<option value="16">Webster</option>
<option value="17">Willis</option>
<option value="18">The Woodlands</option>
</select></label> </p>
<p><input name="add" type="submit" value="Add" /></p>
</form>