Page 2 of 3

Posted: Fri Jul 28, 2006 5:00 am
by reecec
CREATE TABLE test;(
its finishing the create table before it gets to the while statement


any ideas


thanks reece

Posted: Fri Jul 28, 2006 8:47 am
by RobertGonzalez
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

Code: Select all

<?php
$maketable = 1
?>
add...

Code: Select all

<?php
echo '<strong>' . $howmanyfields . '</strong>';
?>
To see what is in the var $howmanyfields. Post back what you find.

Posted: Fri Jul 28, 2006 9:09 am
by reecec
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

Posted: Fri Jul 28, 2006 9:38 am
by reecec
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

Posted: Fri Jul 28, 2006 9:13 pm
by RobertGonzalez

Code: Select all

${$attribute.$endfield}=$_POST['attribute1' . $endfield];

Posted: Sat Jul 29, 2006 11:56 am
by reecec
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

Posted: Sat Jul 29, 2006 3:15 pm
by reecec
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

Posted: Sat Jul 29, 2006 9:39 pm
by RobertGonzalez
So are you ok with this, or do you still need help?

Posted: Sun Jul 30, 2006 6:57 am
by reecec
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

Posted: Sun Jul 30, 2006 8:44 am
by RobertGonzalez
Those values are being sent from post data, right? Or how are the values being set?

Posted: Sun Jul 30, 2006 9:24 am
by reecec
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

Posted: Sun Jul 30, 2006 9:41 am
by RobertGonzalez
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?

Posted: Sun Jul 30, 2006 9:58 am
by reecec
thats what i have tried before but it gives this

CREATE TABLE (; varchar() default '',; varchar() default '',

thanks for your help again

Posted: Sun Jul 30, 2006 10:14 am
by RobertGonzalez
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>';
} 
?>

Posted: Sun Jul 30, 2006 10:27 am
by reecec
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 (
(