homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

how to confirm before submitting the form value in database

 1:14 pm on Jun 19, 2012 (gmt 0)

i am using registration form. if the user submit the form,it will show the form details which user have submitted ,
if he agree with that then user click the save button ..it will save in database.otherwise user will have edit button .
is this possible or not tell me?
i am new to this php and javascript...
thanks in advance ...



 5:02 pm on Jun 30, 2012 (gmt 0)

Sure, sounds reasonable enough. You can check to see if the user is already logged in and if so you will not show a registration form with a "save" option but rather you will display their current information which they can edit.


 6:58 am on Jul 2, 2012 (gmt 0)

Thanks for replay..
Actually i want edit the form which consist of 20 fields.
Is there any easy way to do that?
Thanks advance...


 11:57 am on Jul 3, 2012 (gmt 0)

Easy? As in magical? ;)
You need to read in the data from the database and populate your HTML form with the data. Here is a pseudo code sample to give you an idea ...
$userid = $_SESSION['userid'];
$sql = "SELECT firstname, lastname FROM table WHERE userid = {$userid}";
execute query, fetch row into variables
First Name: <input name="firstname" value="<?php print $firstname; ?>">
Last Name: <input name="lastname" value="<?php print $lastname; ?>">
<input name="formSubmit" type="submit" value="Submit Changes">


 3:58 pm on Jul 8, 2012 (gmt 0)

easy? i mean is there any way fetch the value from the database with out specific field ..
using array or something ..
because i need 20 fields values .


 12:45 pm on Jul 9, 2012 (gmt 0)

If you have 20 fields you need to place them individually into your HTML so you are going to need to be specific.


 3:44 pm on Jul 9, 2012 (gmt 0)

i mean is there any way fetch the value from the database with out specific field ..

Start with some variables . . .
$tablename = 'whaever_your_table_name_is';
$identifier = 'user_id';
$id = 12345; // whatever your user id is

Create some function to get field table names. You will need this in the get record function as well as in the event there are no values in post, such as on the first load of the page. There are probably more efficient ways, but off the top of my head . . . .

$fields = field_names($tablename);

function field_names($tablename) {
if (! isset($table)) { die("No table name in field names"); }
$fields = Array();
$result = mysql_query("show columns from $table") or die ("Could not get table names");
while ($row = mysql_fetch_array($result)) {
return $fields;

Now you have a list of fields. Create some function to get records from table X by unique identifier Y. This allows you to query ANY table for a record.

if (is_numeric($the_id) and ($the_id > 0)) {
$myvalues = get_record($tablename,$fields,$identifier,$id);
function get_record($table,$tablefields,$field,$target_id) {
$select = "select * from $tablename where $field=$target_id";
$result=mysql_query("$select") or die("Could not get record for table $table");
if ($row=mysql_fetch_array($result)) {
foreach ($tablefields as $fld) { $allvalues[$fld] = $row[$fld]; }
return $allvalues;

Now you have all the values loaded (maybe! remember it will be empty on first load), squelch "undefined variable" and/or offset errors if there was no record found by setting the values to null only if there isn't an existing value.

foreach ($fields as $fld) { $myvalues[$fld]=(isset($myvalues[$fld]) and ! empty($myvalues[$fld]))?$myvalues[$fld]:null; }

Then you'd continue with your form like so.

<p><label for="fname">First Name:</label> <input type="text" name="fname" id="fname" value="<?php echo $myvalues['fname']; ?>"></p>

Or get slick about it; you'll have to make some if/else's to get this to work:

$ignoreme = ('id','member_status','access_level'); // whatever, fields you don't want in form

foreach ($fields as $fld) {
if (! in_array($fld,$ignoreme)) {
echo "<p><label for=\"$fld\">" . $english[$fld] . ":</label>
<input type=\"text\" name=\"$fld\" id=\"$fld\" value=\"" . $myvalues[$fld] . "\"></p>\n";

Entire form in five lines.

What is "$english?" An array you'd have somewhere with an association between field labels and actual field names. Along that thought, the previous "as posted" is a little dangerous as it reveals database field names in your forms, you should always create aliases somewhere internal to your programming (or, a table in the DB reserved for this purpose.) The previous is not copy and paste code (though I'm sure many will try) but it's to give you an idea of how to perform your tasks anonymously so they can be re-used and expandable.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved