473,765 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form handling with PHP

I have a bunch of pages with long forms, with lots of input
types-text, radios, textareas, and the debugging process has become
overwhelming.
What I need to happen is to make sure that
1. Every field on the page is filled out-if not, a list of incorrect
fields is displayed, and any radio boxes that were checked still are
2. The fields are queried to a table in a database. (The table has the
same column names as the field names)

Here's what I did; can someone tell me why this doesn't work?

<?php
require_once ('../mysql_connect.p hp');
$page_title = 'Test page';

if (isset($_POST['submit'])) { // Handle the form.

// Create an empty new variable.
$message = NULL;

// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic _quotes_gpc')) {
$data = stripslashes($d ata);
}
return mysql_real_esca pe_string($data , $dbc);
}

//Create an array of all formfield names
$required=array ('field1','fiel d2','field3');

//Check to see if all field names are filled in
function field_check($re quired) {
foreach($requir ed as $q) {
if(empty($_POST[$q])) {
$message = 'Error: The following field was not filled in: $q';
$ok=FALSE;
}
else {
$ok;
}
}
}

// If no empty posts are returned
if ($ok) {
//set a variable for the current user
$u = addslashes($_CO OKIE['user_id']);

//insert all variable values into the table
foreach($requir ed as $q) {
$query = "INSERT INTO test_table ($q) VALUES ('$'.'$q')";
}

// Run the query
$result = @mysql_query ($query); // Run the query.

// If it ran OK, write the the page with a link to continue.
if ($result) {
include ('templates/header.inc');
$page_title = 'Entry Recorded';
echo "<p><b><a href=\"next_pag e.php\"
class=\"content \">Continue</a>";
include ('templates/footer.inc');
exit(); // Quit the script.
}
// If it did not run OK, show an error
else {
$message = '<p>Your form could not be recorded due to a system
error. We apologize for any inconvenience.</p><p>' . mysql_error() .
'</p>';
}
}

// Close the database connection
mysql_close($db c);
}

include ('templates/header.inc');

// Print the error message if there is one.
if (isset($message )) {
echo '<font color="red">', $message, '</font>';
}

// Print the page.
?>

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
<td><input type="radio" name="field1" value="1"</td>
<td><input type="radio" name="field1" value="2"></td>
<td><input type="text" name="field2"></td>
<td><textarea name="field3" rows="20" cols="30">
</textarea></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="Add to Record">
</p>
</form>
<?
include ('templates/footer.inc'); // Include the HTML footer.
?>
Thanks.
Jul 17 '05 #1
2 2102
I noticed that Message-ID:
<dd************ **************@ posting.google. com> from Glyphman
contained the following:
Here's what I did; can someone tell me why this doesn't work?


It doesn't work because it isn't coded properly...
What bit doesn't work?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
Hello,

On 02/16/2004 02:15 PM, Glyphman wrote:
I have a bunch of pages with long forms, with lots of input
types-text, radios, textareas, and the debugging process has become
overwhelming.
What I need to happen is to make sure that
1. Every field on the page is filled out-if not, a list of incorrect
fields is displayed, and any radio boxes that were checked still are
2. The fields are queried to a table in a database. (The table has the
same column names as the field names)


You may want to try this class instead of reinventing the wheel. It can
compose and validate HTML forms, either on client side with Javascript
or on the server side with the class code. It supports many common
validation types.

You can compose the forms output with a Smarty plugin that makes it
possible to integrate with the class. The generated output embeds the
necessary Javascript but you do not need to know Javascript at all.

http://www.phpclasses.org/formsgeneration

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
5225
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to complete in connection with attendance at a seminar. After spending more than 15 minutes on it, I clicked on the submit button - and nothing happened. Looking round the pages on Javascript form validation that Google produced for me (well,...
4
9301
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form action="MaintNotification.php?ReqID=5" method="post" name="frm5"> <tr align="left" bgcolor="#dddddd" class="text" onClick="submit()"
4
2822
by: John Fereira | last post by:
So, one of the limitations of multipart-form handling is that when an <input type="file" ..> tag is used it will bring up a window which allows a user to select a file for upload but won't allow the user to select multiple files. As you may know, the tag produces a text input field with an adjacent button for selecting a file from the local file system. As I would like to be able to allow the user to upload an arbitrary number of files...
1
1814
by: google | last post by:
It would seem that when I assign an HTML entity to a form text input using "inline" javascript that it will display properly. But when trying to set it via a function call, the entity text shows in the field instead of the symbol it represents. The following example produces these results on Opera 8.5 and IE 6.0 I am expecting the same results whichever way I set the contents of "myText". Why, when choosing "function" does "&copy"...
8
5158
by: swathky | last post by:
I've tried mutiple things but no go -- (sorry this is so long) I'm collecting a 5 digit number in an input box function and all works fine until a number is passed that doesn't exist in the database. I can't figure out where/how to check that the number exists before I get the error code 2105. Here's my function to get the number that I run when a command button is clicked to open the frmEditLoans form: Public Function...
15
4660
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field has the default value of the previous record. If I put the focus in any field to start, edit that...
16
7237
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
5
73215
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
6
4094
by: nadeem_far | last post by:
Hello All, I am working on a .Net desktop application and I am having problem displaying a form. I am using C# and version 1.1 of the framework. here is how the code looks likes and I will appreciate if someone can tell me how to resolve this problem. Main ( Args ) { Form1 f1 = new Form1();
2
2292
by: Esa | last post by:
Hi, I'm having problems with one strange web system where submitting an application and making queries about its handling status require a series of form submits and response parsing - all in HTML. Luckily other interfaces are "modern" using xml file up/downloads without any difficulties... I'm not very used to .NET-environment yet, so I'd appreciate some clues about the classes I should use to implement this stupid interface - stupid...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.