jmahdi Posted November 16, 2011 Share Posted November 16, 2011 Hi there I'm trying to make this form submit...but alas, is to no avail .... i have two forms on top of each other one of them is: <form name="entries_form" method="post" action="index.php"> <table> <tr> <th><label>Date</label></th> <th><label>From</label></th> <th><label>To</label></th> <th><label>Break</label></th> <th><label>Hours</label></th> <th><label>Required Hours</label></th> <th><label>Notes</label></th> </tr> <tr> <td> <input name="Date" type="text" id="Date" /> </td> <td> <input name="From" type="text" id="From" /> </td> <td> <input name="To" type="text" id="To" /> </td> <td> <input name="Break" type="text" id="Break" /> </td> <td> <input name="Hours" type="text" id="Hours" /> </td> <td> <input name="Rqrd_hrs" type="text" id="Rqrd_hrs" /> </td> <td> <input name="Notes" type="text" id="Notes" /> </td> <td> <input type="submit" name="Save" value="Save" id="Save" style="background-color:#7A70A4;" /> </td> </tr> </table> </form> to post i'm using this code (to much over the top maybe): <?php $session = new Session(); $u_id = $session->get('id'); //to get the user id from session if(isset($_POST['submit']) == 'Save'){//form's button name is Save $entry->user_id = $user_id = $u_id; $entry->date = $date = trim(strtolower($_POST['Date'])); $entry->start_time = $start_time = trim(strtolower($_POST['From'])); $entry->end_time = $end_time = trim(strtolower($_POST['To'])); $entry->breaks = $break = trim(strtolower($_POST['Break'])); $entry->total_hours = $total_hours = trim(strtolower($_POST['Hours'])); $entry->reqd_hours = $required_hours = trim(strtolower($_POST['Rqrd_hrs'])); $entry->notes = $notes = trim(strtolower($_POST['Notes'])); $entry->add_entry(); }else die("Not Posted"); ?> the add entry() function does the following: public function add_entry(){ global $database; $sql = "INSERT INTO sheetentries ("; $sql .= "user_id, date, start_time, end_time, break, required_hours, total_hours, notes"; $sql .= ") VALUES ('"; $sql .= $this->user_id ."', '"; $sql .= $this->date ."', '"; $sql .= $this->start_time ."', '"; $sql .= $this->end_time ."', '"; $sql .= $this->breaks ."', '"; $sql .= $this->reqd_hours ."', '"; $sql .= $this->total_hours ."', '"; $sql .= $this->notes ."')"; $database->query($sql); } the user_id or $u_id brought from the session when the user loggs in: $u_id = $session->get('id'); anyway, whenever i try submitting the form nothing happens, what am i missing,,, thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/251262-form-_post-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2011 Share Posted November 16, 2011 The name='...' attribute of your submit button is 'Save'. You would need to test for that name in your php code - $_POST['Save'] I recommend that you add the following debugging logic to your code so that you can see exactly what post data is being submitted - echo "<pre>"; echo "POST:"; print_r($_POST); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/251262-form-_post-problem/#findComment-1288730 Share on other sites More sharing options...
btellez Posted November 16, 2011 Share Posted November 16, 2011 I think you may mean: if (isset($_POST['Save'])){ .... } or if (isset($_POST['Save'])){ if ($_POST['Save'] == 'Save' ){ ..... } } Note your buttons identifier is "Save" not "submit" Quote Link to comment https://forums.phpfreaks.com/topic/251262-form-_post-problem/#findComment-1288741 Share on other sites More sharing options...
jmahdi Posted November 16, 2011 Author Share Posted November 16, 2011 Thanks a bunch PFMaBiSmAd and btellez the problem was the name , i had changed both forms names to submit and kept the value to be more specific, Save and Go for the other form. I hope this is best practice(i.e. to keep the name as submit always)?! or isn't it! Quote Link to comment https://forums.phpfreaks.com/topic/251262-form-_post-problem/#findComment-1288785 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 It's actually better to see if a form that uses the POST method has been submitted by checking the value of $_SERVER['REQUEST_METHOD'], because some browsers mishandle the value of submit buttons. Alternately, you can add a hidden field to a form, and check for its presence to determine if the form has been sent. if( strcasecmp($_SERVER['REQUEST_METHOD'], 'post') === 0 ) { Quote Link to comment https://forums.phpfreaks.com/topic/251262-form-_post-problem/#findComment-1288789 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.