PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 16th, 2004, 11:11 AM
KnightRider KnightRider is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 KnightRider User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Creating SQL table via PHP

Hi friends,

I am having this problem which I am unable to solve.
I am trying to create a user friendly inventory database.
To create a table, the user enters the number of fields required.
The user clicks submit and (using a form) and is redirected to another page where there are (#of fields)textboxes displayed using a for loop. The user is supposed to type in the required fields and then click submit. It should then output the all the fields. My problem is that how can I access those text fields if I have used a for loop to create them. I know that if I normally give a text box a variable name.. I can then POST it. But here it's in a for loop that get repeated as many times depending on the number of fields selected by the user. Please help..I am trying to figure this out..and am still unsuccessful. Here is the part of the code causing all the problem:

PHP Code:
function create_table(){ 

global 
$_REQUEST;
$out.= "<H2><B>Create Table</B></H2>"
$out.= "<form action = '?res=tblinfo' method = 'post'> 
Table Name: <input type = 'text' name = 'tablename'/> 
Enter Fields: <input type = 'text' name = 'fields'/>
<input type = 'submit' name = 'submit' value = 'Submit table' /> 
</form>"
;
return 
$out;
}


function 
table_info(){
$out "<H4><b>{$_POST['tablename']}<b></H4>";
$out.= "<H4><b>Enter Required Fields<b><H4>";
$out.= "<form action = '?res=query' method = 'post'>";
for(
$i=1$i<=$_POST['fields']; $i++){
$out.= "<input type = 'text' name = 'field'/><br>";
}
$out.= "<input type = 'submit' name = 'submit' value = 'Submit' />
</form>"
;

return 
$out

Last edited by stumpy : June 18th, 2004 at 01:58 AM. Reason: Please use helpful thread titles, and wrap your code in code tags

Reply With Quote
  #2  
Old June 16th, 2004, 12:06 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
if you name the textfields numerical ei from 1 to what-ever-the-user-chooses. Then you can acces it by making an array with the same number of places as the for-loop makes.

Reply With Quote
  #3  
Old June 18th, 2004, 01:21 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
I modified your code slightly:

PHP Code:
<?php
function create_table()

    
$out.= '<H2><B>Create Table</B></H2>'
    
$out.= '<form action="" method="post">';
    
$out.= '<input type="hidden" name="res" value="tblinfo">';
    
$out.= 'Table Name: <input type="text" name="tablename"/> 
    # Fields: <input type="text" name="fields"/>
    <input type="submit" value="Submit table"/> 
    </form>'
;

    return 
$out;
}

function 
table_info()
{
    
$out '<H4><b>'.$_POST['tablename'].'<b></H4>';
    
$out.= '<H4><b>Enter Required Fields<b><H4>';
    
$out.= '<form action="" method="post">';
    
$out.= '<input type="hidden" name="res" value="query">';
    for(
$i=1$i<=$_POST['fields']; $i++){
        
$out.= '<input type="text" name="field[]"/><br>';
    }

    
$out.= '<input type="submit" value="Submit"/>
    </form>'
;
    
    return 
$out;
}

function 
show_table()
{
    print 
'<pre>'
    
print_r($_POST['field']);
    print 
'</pre>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php print ($_POST['res']=='tblinfo') ? 'Display Table' 'Create Table'?></title>
</head>
<body>
<?php
    
if ($_POST['res']=='tblinfo') {
        print 
table_info();
    } elseif (
$_POST['res']=='query') {
        
show_table(); 
    } else {
        print 
create_table();
    }
?>
</body>
</html>
You can also test it here: www.laidbak.net/codetest/create_table.php
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Creating SQL table via PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway