PDA

View Full Version : Input forms problem


Beeky
10-19-2010, 08:19 AM
I have a fairly simple form that adds a new event to a MySQL database. All inputs work fine except for the "fundsraised" field.When a new event is added the data is inserted into the database but I can't insert the fundraised field until I use another page that updates a record. The Data type for the field "fundsraised" is (decimal(5,2)). The input "type" on the form is also (decimal(5,2)).

The web pages relevant code is:

Code for working with db

//select a database to work with
$selected = mysql_select_db("eachfrie_Events",$dbhandle)
or die("Could not select eachfrie_Events");
// query db and loop through rows example
/// query db and loop through rows example

$field2 = $_POST['eventid'];
$field3 = $_POST['eventname'];
$field4 = $_POST['eventlocation'];
$field5 = $_POST['eventtype'];
$field6 = $_POST['eventstatus'];
$field7 = $_POST['eventdate'];
$field8 = $_POST['starttime'];
$field9 = $_POST['endtime'];
$field10 = $_POST['coordinator'];
$field11 = $_POST['comments'];
$field12 = $_POST['fundraised'];
$field13 = $_POST['financialyear'];

if($field2 && $field3){

mysql_query("INSERT INTO tblEvents(eventid,eventname,eventlocation,eventtyp e,eventstatus,eventdate,starttime,endtime,coordina tor,comments,fundsraised,financialyear)VALUES('$fi eld2','$field3','$field4','$field5','$field6','$fi eld7','$field8','$field9','$field10','$field11','$ field12','$field13')");


/// query db and loop through rows example
}
/// query db and loop through rows example

$query = mysql_query("SELECT * FROM tblEvents ORDER BY eventid;");

$table = "<table border=\"1\" cellspacing=\"10\" body bgcolor=\"#AABBCC\" Align=Center>\n";
" <tr>
<td>Event No</td>
<td>Event</td>
<td>Location</td>
<td>Status</td>
<td>Type of Event</td>
<td>Date</td>
<td>Start Time</td>
<td>End Time</td>
<td>Coordinator</td>
<td>Comments</td>
<td>Funds Raised</td>
<td>Financial Year</td>

</tr>";

while($row = mysql_fetch_array($query)){

$table .= " <tr>
<td>".$row['eventid']."</td>
<td>".$row['eventname']."</td>
<td>".$row['eventlocation']."</td>
<td>".$row['eventstatus']."</td>
<td>".$row['eventtype']."</td>
<td>".$row['eventdate']."</td>
<td>".$row['starttime']."</td>
<td>".$row['endtime']."</td>
<td>".$row['coordinator']."</td>
<td>".$row['comments']."</td>
<td>".$row['fundsraised']."</td>
<td>".$row['financialyear']."</td>
</tr>";
}

$table .= "</table>";
$note1 = "The table below shows the current programme list. To add a new event please enter a new 'UNIQUE' Event No (see from curent list)
and then fill in all relevant fields in the table and then click on the Submit button.";
?>Form Code:

<form id="form1" name="form1" method="post" action="">
<table width="49%" border="0" align="center">
<tr>
<td width="32%">eventid</td>
<td><input name="eventid" type="text" id="eventid" /></td>
</tr>
<tr>
<td>eventname</td>
<td><input name="eventname" type="text" id="eventname" size="64"/></td>
</tr>
<tr>
<td>Location</td>
<td><input name="eventlocation" type="text" id="eventlocation" size="64" /></td>
</tr>
<tr>
<td>Status</td>
<td><input name="eventstatus" type="text" id="eventstatus" /></td>
</tr>
<tr>
<td>Type of Event</td>
<td><input name="eventtype" type="text" id="eventtype" /></td>
</tr>
<tr>
<td>Date</td>
<td><input name="eventdate" type="Date" id="eventdate" /></td>
</tr>
<tr>
<td>Start Time</td>
<td><input name="starttime" type="text" id="starttime" /></td>
</tr>
<tr>
<td>End Time</td>
<td><input name="endtime" type="text" id="endtime" /></td>
</tr>
<tr>
<td>Coordinator</td>
<td><input name="coordinator" type="text" id="coordinator" /></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea name="comments" cols="64" id="comments"></textarea></td>
</tr>
<tr>
<td>Funds Raised</td>
<td><input name="fundsraised" type="decimal(5,2)" id="fundsraised" /></td>
</tr>
<tr>
<td>Financial Year</td>
<td><input name="financialyear" type="text" id="financialyear" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form></p></td> </tr></table></td> </tr></table>For interest the update form is exactly the same except I use an Update query instead of an insert query.

I have clearly made a basic error somewhere but I can't see it. Can anyone help please.

edbr
10-19-2010, 08:55 AM
type="decimal(5,2)" try text in the form input

Corrosive
10-19-2010, 08:57 AM
Yes, you have messed up your field names;

Your form says fundsraised and your php says fundraised (you missed out the 's'). Just needed fresh eyes I guess :)

Beeky
10-19-2010, 09:45 AM
Thank you corrosive. You know I looked through that code many times thinking it was something like this - and missed it. Appreciate your help and "new eyes"

Corrosive
10-19-2010, 09:48 AM
Thank you corrosive. You know I looked through that code many times thinking it was something like this - and missed it. Appreciate your help and "new eyes"

No problem, we all do it :)