Extracting a form from SQL to HTML text fields

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
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Extracting a form from SQL to HTML text fields

Post by Shujaa »

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
Last edited by Shujaa on Sun Mar 07, 2004 1:31 pm, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Not sure if this is what you are looking for, but... Play around abit with it.

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>
...and also this link might be of interest.
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Post by Shujaa »

Ahaaaaaa! That looks useful, still not 100% sure but I bet I can figure it out playing with that code...
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Post by Shujaa »

Related question: how do I pass a variable (say, a string) between PHP pages? I checked the documentation for variable scopes and can't see any way to increase the scope beyond one page.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

using forms: $_POST, $_GET
using urls: $_GET
using sessions: $_SESSION
check http://www.php.net/manual/en/language.v ... efined.php
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Post by Shujaa »

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.
User avatar
Phirus
Forum Commoner
Posts: 37
Joined: Thu Apr 18, 2002 4:10 pm
Contact:

Post by Phirus »

Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Post by Shujaa »

Hmm I'm starting to understand, but still have a major question:

Is it possible to pass variables from one PHP script to the next WITHOUT using html forms? Because as far as I can tell, using GET and POST rely on the user pressing a Submit button of some kind...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Yes - use sessions. E.g:

page1.php

Code: Select all

<?php
session_start();

$_SESSION['var1'] = 'foo';
$_SESSION['var2'] = 'bar';

?>
<a href="page2.php">Go to page 2...</a>
page2.php

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'];
?>
Mac
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

(Using twigletmac code) And - use GET without form. E.g:

page1.php

Code: Select all

<a href="page2.php?sVar1=foo&sVar2=bar">Go to page 2...</a>
page2.php

Code: Select all

<?php

echo 'The value of $_GETsVar1] is: '.$_GET['sVar1'];
echo '<br />';
echo 'The value of $_GET[sVar2] is: '.$_GET['sVar2'];
?>
You have to validate those variables, because the user an change them into mallicious code.
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Post by Shujaa »

$_SESSION looks like what I need. I'd rather not use GET method at all if I can help it, because of the security/validation issues that can arise. Thanks a lot :D
Post Reply