Forum Moderators: coopster

Message Too Old, No Replies

Displaing MySQL data on web form

         

olly79

12:30 pm on Feb 8, 2009 (gmt 0)

10+ Year Member



Hi all,

Just wondering if someone can help me with the following.

I'm inserting data from a web form into MySQL (below is the data that I'm inserting):

$Body .= $_POST['m'].' '.$name.''.$surname.'<br />';
if(!empty($_POST['month']) && !empty($_POST['day']) && !empty($_POST['year']) )$Body .= 'Date of Birth: '.$_POST['month'].' '.$_POST['day'].' '.$_POST['year'].'<br />';
if(!empty($_POST['gender']))$Body .= 'Gender: '.$_POST['gender'].'<br />';
if(!empty($address))$Body .= 'Street Address: '.$address.'<br />';
if(!empty($city))$Body .= 'City: '.$city.'<br />';
if(!empty($zip))$Body .= 'Zip Code: '.$zip.'<br />';
if(!empty($_POST['country']))$Body .= 'Country: '.$_POST['country'].'<br />';
if(!empty($state))$Body .= 'State/Province: '.$state.'<br />';
if(!empty($day_ph))$Body .= 'Daytime phone: '.$day_ph.'<br />';
if(!empty($mob_ph))$Body .= 'Mobile Telephone: '.$mob_ph.'<br />';
if(!empty($email))$Body .= 'Email: '.$email.'<br />';
if(!empty($add_info))$Body .= 'Additional Information: '.$add_info.'<br />';

I now want to display this data on a web form I have:

<form action="insert.php" method="post">
MySQL Table Name:
<div class="indent-form"><input type="text"/></div>
<br />
<textarea name="mysql recruitment data" rows="20" cols="150" wrap="physical"></textarea>
<br />
<INPUT TYPE="submit" value="load data">
<INPUT TYPE="submit" value="export data" />
</form>

I basically wanted to load the data via the "load data" button, and I would firstly load the table name into the first textbox and then all the data for the database named "recruitment" would be loaded into the textarea in tabluar format.

I have seen ways in which I can load MySQL data; however, I'm struggling with how I can achieve this based on what I want to do.

Any help would be much appreciated.

olly79

2:35 pm on Feb 8, 2009 (gmt 0)

10+ Year Member



Hi,

I have come up with the following:

<textarea name="comments" rows="20" cols="150" wrap="physical"><?php
$sql = mysql_query(" SELECT * FROM table");
$f = 0; //for showing the fields.
while($arr = mysql_fetch_array($sql)){
if($f == 0){
$f++; //this is so we never show the fields again
//dump fields
$rl = 0; //just to make a separator
$j = 1; //field count
foreach($arr as $key => $value){
$j++;
if($j % 2){ //mysql will give us numeric and text values as keys, we want to skip numeric
$rl += strlen($key);
echo strtoupper($key) . "\t";
}
}
echo "\n" . str_repeat("-", $rl) . "\n"; //this is the separator
}
$i = 1;
foreach($arr as $key => $value){
$i++;
if($i % 2){ //again, skipping numeric field values
echo $value . "\t";
}
}
echo "\n";
}
?></textarea>
<br />
<INPUT TYPE="submit" value="load data">
<INPUT TYPE="submit" value="export data" />

However, I'm not sure how I can call this from the 'load data' button, and what else I would need to perform the action?