Problem setting up POST array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
genista
Forum Commoner
Posts: 57
Joined: Fri Aug 18, 2006 3:56 pm

Problem setting up POST array

Post by genista »

Hi all,

I have a script that combines a few different tables and in practtise allows a user to find a supplier and then submit an enquiry on this supplier. When they hit submit a table will be updated and an email will be sent. The problem I have is that the data that is output to the user is less comprehensive than the data the administrator needs to see, ie the user will see the supplierid, the services they offer etc, the administrator who reviews these enquiries or reads the email will need to see the address of the supplier, the name and relevant details etc.

This leads me onto my problem and hopefully it is easily solved. Any data that the user needs is output in html, ie the supplierid etc mentioned above. The stuff that they dont need to see is not output, however when I setup my POST array I have problems with undefined indexes from parts that are not output as html.

My script is very big so here is an example of what I am trying to achieve:

Code: Select all

//Simple select query
$query = "select * from suppliers where x = x";
$result = mysql_query($query) or die("Couldn't execute query");


//Set up rows of result set  
$row = mysql_fetch_array($result, MYSQL_ASSOC); 
 // $title = $row ["username"];
  $supplier = $row ["supplierid"];
  $town = $row ["town"];
  $county = $row ["county"];
  $enquirydetails = $row["enquirydetails"];


if(isset($_POST['submit'])){ 
 $supplier = $_POST ["supplierid"];
 $enquirydetails = $_POST["enquirydetails"];

//now update the database, send email etc


now for the html part:
<html>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="POST">
<tr><td>Please add any details or requests you would like to make:<BR> <TEXTAREA NAME="enquirydetails" value="<?php print isset($_POST["enquirydetails"]) ? $_POST["enquirydetails"] : "" ;?>"COLS=40 ROWS=6></TEXTAREA>
</td></tr>
//submit button etc etc
</html>
As we can see here our POSt array contains supplierid and enquirydetails, but as there is no field for supplierid there will be an undefined index error on it, but I need it in the array.

I know I could use hidden fields in html to set these up, but isnt there an alternative to just getting the rows retirieved into a POST array?

I have a cold and probably could have explained this in a shorter time, but hey ho.


Thanks,


G
lanasa
Forum Newbie
Posts: 14
Joined: Mon Mar 26, 2007 7:49 am
Location: Buffalo, NY

Re: Problem setting up POST array

Post by lanasa »

I'm not sure if I fully understand, but this command will work:

$_POST['supplierid'] = $row ["supplierid"];
genista
Forum Commoner
Posts: 57
Joined: Fri Aug 18, 2006 3:56 pm

Post by genista »

spot on! Thanks,


g
Post Reply