faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 14 people (86%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I pass a variable coming from a form to make up an sql query? (ie=create table <VARIABLE>)

Mar 19th, 2008 21:56
ha mo, Scott Noyes, B C,


Form variables appear in two superglobal arrays: $_REQUEST, and either
$_GET or $_POST.  The element names appear as the indices of these arrays.
For example, if your form contained this element:
<input type='text' name='tableName'>
then the value of that input will appear in
$_REQUEST['tableName']
You can construct a string in several ways.  The following all result in
the same string:
$sql = sprintf("CREATE TABLE %s", $_REQUEST['tableName']);
$sql = "CREATE TABLE " . $_REQUEST['tableName'];
$sql = "CREATE TABLE {$_REQUEST['tableName']}";
http://www.php.net/reserved.variables
http://www.php.net/manual/en/function.sprintf.php
http://www.php.net/types.string
http://www.tantofa.com
http://www.fantofa.com
http://www.mantofa.com
http://www.tanpola.com
http://www.tampola.com
http://www.yamot.com
http://www.mozmar.com
http://www.templatestemp.com