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
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Fri Jul 28, 2006 5:00 am
CREATE TABLE test;(
its finishing the create table before it gets to the while statement
any ideas
thanks reece
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Jul 28, 2006 8:47 am
It means that
$howmanyfields is either 0, 1 or not set. That is controlling the while loop and you are comparing
$maketable to being less that
$howmanyfields in a while loop. If that whle comparison returns false, then the while never executes.
Just after
add...
Code: Select all
<?php
echo '<strong>' . $howmanyfields . '</strong>';
?>
To see what is in the var
$howmanyfields . Post back what you find.
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Fri Jul 28, 2006 9:09 am
what like this
Code: Select all
$endfield=1;
$maketable="CREATE TABLE $table;(";
echo '<strong>' . $howmanyfields . '</strong>';
while ( $endfield <= 2) {
$maketable .= "${$field.$endfield} varchar(${$length.$endfield}) ${$null.$endfield} default '${$default.$endfield}',";
$endfield++;
}
it dint echo anything so you are right so i changed $howmanyfields to 2 and i now got this far which is further but still not right
Code: Select all
CREATE TABLE test;( varchar() default '', varchar() default '', which means it isnt putting in the values
i just also echoed ${$field.$endfield} and the value is blank so i will to sort that out and come back to you if i need help again thanks
thanks reece
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Fri Jul 28, 2006 9:38 am
is it not getting the value because of this
$_POST['attribute$endfield']; and isnt getting the value of $endfield in the _POST and is thinking it is attribute$endfield
Code: Select all
${$attribute.$endfield}=$_POST['attribute1$endfield'];
thanks reece
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Sat Jul 29, 2006 11:56 am
thanks everah thats sorted that and it now gets the text box value
but when i enter a value for the field name and length and defaults it puts the field name value in all boxes
heres the create table echo for a two field table
CREATE TABLE ;(testfieldname1; varchar(testfieldname1) testfieldname1 default 'testfieldname1',testfieldname1; varchar(testfieldname1) testfieldname1 default 'testfieldname1',
and here is the current code for the create table
Code: Select all
$endfield=1;
$maketable="CREATE TABLE $table;(";
while ( $endfield <= 2) {
$maketable .= "${$field.$endfield}; varchar(${$length.$endfield}) ${$null.$endfield} default '${$default.$endfield}',";
$endfield++;
}
thanks for all your help the script is nearly done
reece
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Sat Jul 29, 2006 3:15 pm
I have just sorted all the other fields as there whiles wernt working and have noticed that the last box you fill in on the form eg Defaults it will fill every thing in with the same
CREATE TABLE ;(testdefualtfield1; varchar(testdefualtfield1) testdefualtfield1 default 'testdefualtfield1',testdefualtfield2; varchar(testdefualtfield2) testdefualtfield2 default 'testdefualtfield2',
thanks reece
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Jul 29, 2006 9:39 pm
So are you ok with this, or do you still need help?
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Sun Jul 30, 2006 6:57 am
still need help as im dont know why its putting my last typed text box value in all like (name, length, defaults, extra) all become the same last value so if i typed in test in the default box as it is last it makes every thing test
why is this.
i think its to do with the while statement
sorry to be a pain
thanks reece
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Jul 30, 2006 8:44 am
Those values are being sent from post data, right? Or how are the values being set?
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Sun Jul 30, 2006 9:24 am
yes it gets the form data from $_POST then puts it into variables like this
Code: Select all
$table=$_POST['tbname'];
if ($_POST['form_create_table'] == 'yes'){
$endfield=1;
while ( $endfield <= 2) {
${$field.$endfield}=$_POST['field' . $endfield];
$endfield++;
}
$endfield=1;
while ( $endfield <= 2) {
${$length.$endfield}=$_POST['length' . $endfield];
$endfield++;
}
$endfield=1;
while ( $endfield <= 2) {
${$attribute.$endfield}=$_POST['attribute' . $endfield];
$endfield++;
}
$endfield=1;
while ( $endfield <= 2) {
${$null.$endfield}=$_POST['null' . $endfield];
$endfield++;
}
$endfield=1;
while ( $endfield <= 2) {
${$default.$endfield}=$_POST['default' . $endfield];
$endfield++;
}
$endfield=1;
$maketable="CREATE TABLE $table;(";
while ( $endfield <= 2) {
$maketable .= "${$field.$endfield}; varchar(${$length.$endfield}) ${$null.$endfield} default '${$default.$endfield}',";
$endfield++;
}
echo $maketable;
thanks again reece
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Jul 30, 2006 9:41 am
I would probably do something like...
Code: Select all
<?php
$maketable = '';
$table=$_POST['tbname'];
if ($_POST['form_create_table'] == 'yes'){
$maketable="CREATE TABLE $table (";
$endfield=1;
while ( $endfield <= 2) {
${$field.$endfield}=$_POST['field' . $endfield];
${$length.$endfield}=$_POST['length' . $endfield];
${$attribute.$endfield}=$_POST['attribute' . $endfield];
${$null.$endfield}=$_POST['null' . $endfield];
${$default.$endfield}=$_POST['default' . $endfield];
$maketable .= "${$field.$endfield}; varchar(${$length.$endfield}) ${$null.$endfield} default '${$default.$endfield}',";
$endfield++;
}
}
echo $maketable;
?>
But I am really wondering, in all those ${$varname.$endfield} vars, where does the $varname var get set? And where does the $endfield var get set?
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Sun Jul 30, 2006 9:58 am
thats what i have tried before but it gives this
CREATE TABLE (; varchar() default '',; varchar() default '',
thanks for your help again
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Jul 30, 2006 10:14 am
OK, I hate to be working backwards here, but we really need to start from the beginning of your code to see what is really going on here. Please execute this snippet and post back what is displayed.
Code: Select all
<?php
if ($_POST['form_create_table'] == 'yes'){
$maketable="CREATE TABLE $table (";
/* $endfield=1;
while ( $endfield <= 2) {
${$field.$endfield}=$_POST['field' . $endfield];
${$length.$endfield}=$_POST['length' . $endfield];
${$attribute.$endfield}=$_POST['attribute' . $endfield];
${$null.$endfield}=$_POST['null' . $endfield];
${$default.$endfield}=$_POST['default' . $endfield];
$maketable .= "${$field.$endfield}; varchar(${$length.$endfield}) ${$null.$endfield} default '${$default.$endfield}',";
$endfield++;
}
*/
echo '<h1>Field is ' . $field . '</h1>';
echo '<h1>Length is ' . $length. '</h1>';
echo '<h1>Attribute is ' . $attribute. '</h1>';
echo '<h1>Null is ' . $null. '</h1>';
echo '<h1>Default is ' . $default. '</h1>';
echo '<h1>Endfield is ' . $endfield. '</h1>';
echo '<h1>Maketable is ' . $maketable. '</h1>';
}
?>
reecec
Forum Contributor
Posts: 218 Joined: Sun Apr 02, 2006 7:12 am
Post
by reecec » Sun Jul 30, 2006 10:27 am
that wont work anyway as you have stoped the $_POST but you know what your doing most so heres what it gave
Field is
Length is
Attribute is
Null is
Default is
Endfield is
Maketable is CREATE TABLE (
(