Jump to content

Form $_POST problem!


jmahdi

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/251262-form-_post-problem/
Share on other sites

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>";

Link to comment
https://forums.phpfreaks.com/topic/251262-form-_post-problem/#findComment-1288730
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/251262-form-_post-problem/#findComment-1288789
Share on other sites

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.