Jump to content

[SOLVED] Collecting $ POST over and over again?


stublackett

Recommended Posts

Hi,

 

I've got a huuuuuuuuuuge form posting multiple values into a page titled "order.php" I just need to collect some of the data for an SQL Insert

 

when I say a huge form, It has 29 fields of which 26 of them can potentially be filled in by the user

 

My question is how do I collect the forms' post values instead of constantly repeating code like this :

 

<?php
$sendertitle = $_POST['sendertitle'];
$senderforename = $_POST['senderforename'];
$sendersurname = $_POST['sendersurname'];
$senderaddress = $_POST['senderaddress'];
$senderaddress1 = $_POST['senderaddress1'];
$sendertown = $_POST['sendertown'];
$sendercounty = $_POST['sendercounty'];
$sendertelephone = $_POST['sendertelephone'];
$senderemail = $_POST['senderemail'];

//Number of people change to Integer Value
$numberofpeople = $_POST['os'];
?>

 

Is there a nice easier way round it?

you could use a code like this

 

 if ($_POST)

  {

     extract($_POST);

  }

 

this will extract all the post variables.

 

After which you could insert with a query like this

 

 $insertQuery = "INSERT INTO table VALUES (

'$variable1',

'$variable2',

'$variable3' ";

 

make sure you are sending the right variables into the correct fields in the table (order of the variables). Also be careful while inserting numbers, they would not need ' '.

 

Hope this helps.

you could use a code like this

 

 if ($_POST)

  {

     extract($_POST);

  }

 

this will extract all the post variables.

 

After which you could insert with a query like this

 

 $insertQuery = "INSERT INTO table VALUES (

'$variable1',

'$variable2',

'$variable3' ";

 

make sure you are sending the right variables into the correct fields in the table (order of the variables). Also be careful while inserting numbers, they would not need ' '.

 

Hope this helps.

 

The extract($_POST) Works a treat.... Thanks!

 

The Query is inserting the data, But having issues with the numbers, How do I present that data back?

 

My SQL Inser Command is :

	$sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail) values ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail')"; 

 

The field that is effected at the moment is sendertelephone

Still no joy :(

 

The telephone number seems to be missing the zero, Its not a major loss if it isnt there as the data is going to be re-presented back anyways

 

I've got the SQL Insert Query now as :

 

$sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail) values ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty',$sendertelephone,'$senderemail')";

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.