Forum Moderators: coopster

Message Too Old, No Replies

Form processing .php- variables from form/database id?`

Need help listing the values into the insert from a form to a database

         

aftershock2020

1:50 am on Dec 18, 2007 (gmt 0)

10+ Year Member



To variable or not to varliable the value, that is the question...

Basic processing.php form for entering form data into a database:

<?
$name=$_POST['name'];
$email=$_POST['email'];
$location=$_POST['location'];
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");
Print "Your information has been successfully added to the database.";
?>

I have named my fields like this in my form:

<td width="25%" height="38"><font size="2"><b>Customer Representative:</b> <input type="text" name="customerrep_id" size="20" maxsize="20" /></font></td>

To bring that code into proper function, I would need to make that "customerrep_id" into a variable, right? Then, from there, list it into the Insert statement like the variables listed in the example...Is this the correct way to do this?

My attempt:

<?
$customerrep='customerrep_id'
$customerrep=$_POST['customerrep_id']
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$customerrep')");
Print "Your information has been successfully added to the database.";
?>

I have a massive database to complete tonight and need to get cracking before it's due. Can someone please advise asap? Help a fellow programmer.This is the final point to my final project of the year and it's paying for the last few late presents for my daughter that I have on order to pick up. HELP!

Thanks and HAPPY HOLIDAYS!

phparion

4:32 am on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

Your thread is kind of confusing for me because I am not able to understand your goal.

Do you want to insert only one column value in the table?

if yes, then you need to mention the column name in your query like

INSERT INTO tableName('columnName') values('columnsValue')

Or if you want to know about receiving form values, then you must do form validation to purify the data sent, afterwards use global arrays like $_GET or $_POST etc to get the variables because in the recent versions of PHP the global settings are set to OFF and you cannot read them with just form field reference.

aftershock2020

10:18 am on Dec 18, 2007 (gmt 0)

10+ Year Member



It was to confirm that converting the value of the field name in the form over to a variable for the secondary processing.php to read the value in the insert statement correctly.

So, I already have converted the field name value over to a variable. Problem solved there.

Currently, the goal is to find out how to string these properly so that I still get the vales processed into the database but without having to list them in the method of this example below. Can you help me streamline the code for a more practical code layout for this?

The table has to have all 42 values due to it being a form that is being processed and the results are going to be displayed in a seperate client reference search page for complete stats of the active projects they have going within the client company.

PHP CODE:

<?
$customer=$_POST['customer_id'];
$partdes=$_POST['part_description_id'];
$fieldadmin=$_POST['filed_admin_id'];
$dateofjob=$_POST['date_id'];
$shift=$_POST['shift_id'];
$customerrep=$_POST['customer_rep_id'];
$plantcon=$_POST['plant_contact_id'];
$location=$_POST['location_id'];
$prepby=$_POST['prep_by_id'];
$sortrate=$_POST['sort_rate_id'];
$estimated=$_POST['estimated_id'];
$sort=$_POST['sort_id'];
$rework=$_POST['rework_id'];
$attachprodcert=$_POST['attach_prod_cert_id'];
$custchange=$_POST['customer_changed_id'];
$parttoolnum=$_POST['part_tool_num_id'];
$qtyproc=$_POST['qty_processed_id'];
$d1s=$_POST['d_1_s_id'];
$d1r=$_POST['d_1_r_id'];
$d2s=$_POST['d_2_s_id'];
$d2r=$_POST['d_2_r_id'];
$d3s=$_POST['d_3_s_id'];
$d3r=$_POST['d_3_r_id'];
$d4s=$_POST['d_4_s_id'];
$d4r=$_POST['d_4_r_id'];
$d5s=$_POST['d_5_s_id'];
$d5r=$_POST['d_5_r_id'];
$d6s=$_POST['d_6_s_id'];
$d6r=$_POST['d_6_r_id'];
$ncrtot=$_POST['nc_right_total_id'];
$bqtyproctot=$_POST['bottom_qty_proc_total_id'];
$totcontain=$_POST['total_contained_id'];
$totscrap=$_POST['total_scrapped_id'];
$totrework=$_POST['total_reworked_id'];
$totconfirm=$_POST['total_confirming_id'];
$defectdescript=$_POST['defect_descriptions_id'];
$operator=$_POST['operator_id'];
$inid=$_POST['in_id'];
$outid=$_POST['out_id'];
$tothours=$_POST['total_hours_id'];
$comnotes=$_POST['comments_notes_id'];
$workremain=$_POST['work_remaining_id'];
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$customer', '$partdes', '$fieldadmin', '$dateofjob', '$shift', '$customerrep', '$plantcon', '$location', '$prepby', '$sortrate', '$estimated', '$sort', '$rework', '$attachprodcert', '$custchange', '$parttoolnum', '$qtyproc', '$d1s', '$d1r', '$d2s', '$d2r', '$d3s', '$d3r', '$d4s', '$d4r', '$d5s', '$d5r', '$d6s', '$d6r', '$ncrtot', '$bqtyproctot', '$totcontain', '$totscrap', '$totrework', '$totconfirm', '$defectdescript', '$operator', '$inid', '$outid', '$tothours', '$comnotes', '$workremain')");
Print "Your information has been successfully added to the database.";
?>

aftershock2020

10:52 am on Dec 18, 2007 (gmt 0)

10+ Year Member



Next thing I have to figure out is how to create a proper update for this form.

How do I update the form the most productive way? Does it require I use hidden fields and if so, how and where do I use them?

I know the query statement is like this example, I just don't know how to code it to make it work...:

mysql_query ("UPDATE address SET name = '$name', phone = '$phone', email = '$email' WHERE id = $id");

Help please!