Extracting a form from SQL to HTML text fields
Moderator: General Moderators
Extracting a form from SQL to HTML text fields
Got a MySQL database storing user submitted application forms, storing basically Name, Address etc etc. Now I want users to be able to check on their data and be able to edit it again after submitting.
I can easily pull out the data from MySQL using a query and put it in an array variable. I can then split the relevant array elements into simple string variables for each column of data. From that I can put the string variables into text input boxes as default values, so the user can see their data and edit it directly and resubmit. However, I don't know how to do this for Drop Down Lists, or for Radio Buttons. Can anyone help on this? Sample code/tutorials would be much appreciated,
thanks
I can easily pull out the data from MySQL using a query and put it in an array variable. I can then split the relevant array elements into simple string variables for each column of data. From that I can put the string variables into text input boxes as default values, so the user can see their data and edit it directly and resubmit. However, I don't know how to do this for Drop Down Lists, or for Radio Buttons. Can anyone help on this? Sample code/tutorials would be much appreciated,
thanks
Last edited by Shujaa on Sun Mar 07, 2004 1:31 pm, edited 1 time in total.
Not sure if this is what you are looking for, but... Play around abit with it.
...and also this link might be of interest.
Code: Select all
<pre>
<?php
print_r($_POST);
?>
<form method="post">
<select name="foo">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type="radio" name="bar" value="foo" />
<input type="radio" name="bar" value="kitty" />
<input type="radio" name="bar" value="beer" />
<input type="submit">
</form>- AVATAr
- Forum Regular
- Posts: 524
- Joined: Tue Jul 16, 2002 4:19 pm
- Location: Uruguay -- Montevideo
- Contact:
using forms: $_POST, $_GET
using urls: $_GET
using sessions: $_SESSION
check http://www.php.net/manual/en/language.v ... efined.php
using urls: $_GET
using sessions: $_SESSION
check http://www.php.net/manual/en/language.v ... efined.php
I find it difficult understanding the documentation for POST and GET, could someone please take me through the basics of it? I know how to use $_POST to get data that has been submitted through an HTML form, but I can't seem to get it to do anything else. How do I tell a script to "pass" the variables along into the $_POST variable? And how do I tell a script to take variables back out from $_POST?
I appreciate your help, thanks.
I appreciate your help, thanks.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Yes - use sessions. E.g:
page1.php
page2.php
Mac
page1.php
Code: Select all
<?php
session_start();
$_SESSION['var1'] = 'foo';
$_SESSION['var2'] = 'bar';
?>
<a href="page2.php">Go to page 2...</a>Code: Select all
<?php
session_start();
echo 'The value of $_SESSION[var1] is: '.$_SESSION['var1'];
echo '<br />';
echo 'The value of $_SESSION[var2] is: '.$_SESSION['var2'];
?>- AVATAr
- Forum Regular
- Posts: 524
- Joined: Tue Jul 16, 2002 4:19 pm
- Location: Uruguay -- Montevideo
- Contact:
(Using twigletmac code) And - use GET without form. E.g:
page1.php
page2.php
You have to validate those variables, because the user an change them into mallicious code.
page1.php
Code: Select all
<a href="page2.php?sVar1=foo&sVar2=bar">Go to page 2...</a>Code: Select all
<?php
echo 'The value of $_GETsVar1] is: '.$_GET['sVar1'];
echo '<br />';
echo 'The value of $_GET[sVar2] is: '.$_GET['sVar2'];
?>