mysql - PHP Form will not post into my database -
my php form not post database. understand php , mysql connections i'm stumped on one. when hit submit on form doesn't echo values i(the user) put in. date shows 1969-12-31, not date user submits. if great. code follows
the form code is:
<form method="post" action="add_event.php" id="create_event"> <label for="event_name">event name:</label> <input type="text" id="event_name"><br /> <label for="date">date:</label> <input class="datepicker" type="date" id="date"><br /> <label for="zip_code">zip code:</label> <input type="text" id="zip_code" maxlength="5"><br /> <label for="description">description</label> <textarea id="description" rows="5" columns="10"></textarea> <br> <input type="submit" name="submit"> </form>
the add_event.php insert code is:
<?php require_once '../app_config.php'; require_once '../database_connection.php'; require_once '../authorize.php'; session_start(); // authorize user, long they're logged in authorize_user(); //get user id of user show $user_id = $_session['user_id']; $select_query = "select first_name, last_name users user_id = " . $user_id; // run query $result = mysql_query($select_query); if ($result) { $row = mysql_fetch_array($result); $first_name = $row['first_name']; $last_name = $row['last_name']; } $name = $first_name . ' ' . $last_name; $event_name = trim($_post['event_name']); $date = trim($_post['date']); $zip_code = trim($_post['zip_code']); $description = trim($_post['description']); // $date = "2012-08-22"; $newdate = date("y-m-d", strtotime($date)); // $event_name = "test"; // $zip_code = "22153"; // $description = "test"; $insert_sql = sprintf("insert events " . "(name, user_profile_id, event_name, date, zip_code, description) " . "values ('%s', %d, '%s', '%s', '%s', '%s');", mysql_real_escape_string($name), mysql_real_escape_string($user_id), mysql_real_escape_string($event_name), mysql_real_escape_string($newdate), mysql_real_escape_string($zip_code), mysql_real_escape_string($description)); //insert user database mysql_query($insert_sql); echo $insert_sql; ?>
much in advance.
you have not included name attribute in form. here how should be:
<label for="event_name">event name:</label> <input type="text" id="event_name" name="event_name"><br /> <label for="date">date:</label> <input class="datepicker" type="date" id="date" name="date"><br /> <label for="zip_code">zip code:</label> <input type="text" id="zip_code" maxlength="5" name="zip_code"><br /> <label for="description">description</label> <textarea id="description" rows="5" columns="10" name="description"></textarea>
note form inputs element have name attribute sent server. id used on client side.
Comments
Post a Comment