Page 1 of 1

Help with Error from a simple Create databasetable.

Posted: Fri Mar 19, 2004 10:28 am
by bironeb
Below is the code for the html page:

Code: Select all

<html>
<head>
<title>Create a Database Table: Step 1</title>
</head>
<body>
<h1>Step 1: Name and Number </h1>
<form method="POST" action="do_showfielddef.php">
<p><strong>Table Name:</strong><br>
<input type="text" name="table_name" size=30></p>
<p><strong>Number of Fields:</strong><br>
<input type="text" name="num_fields" size=5></p>
<p><input type="submit" name="submit" value="Go to Step 2"></p>
</form>
</body>
</html>
Below is the PHP code to set up the table:

Code: Select all

<?php 
if ((!$_POST[table_name]) || (!$_POST[num_fields])) {
	header("Location: http://127.0.0.1/testing/show_createtable.html");
	exit;
}
$form_block = "
<FORM METHOD="POST" ACTION="do_createtable.php">
<INPUT TYPE="hidden" NAME="table_name" VALUE="$_POST[table_name]">
<TABLE CELLSPACING=5 CELLPADDING=5>
<TR>
<TH>FIELD NAME</TH><TH>FIELD TYPE</TH><TH>FIELD LENGTH</TH></TR>";
for ($i=0; $i < $_POST[num_fields]; $i++) {
	$form_block .="
	<TR>
	<TD ALIGN=CENTER><INPUT TYPE="text" NAME="field_name[]" SIZE="30"></TD>
	<TD ALIGN=CENTER>
	<SELECT NAME = "field_type[]">
		<OPTION VALUE="char">char</OPTION>
		<OPTION VALUE="date">date</OPTION>
		<OPTION VALUE="float">float</OPTION>
		<OPTION VALUE="int">int</OPTION>
		<OPTION VALUE="text">text</OPTION>
		<OPTION VALUE="varchar">varchar</OPTION>
	</SELECT>
	</TD>
	<TD ALIGN=CENTER><INPUT TYPE="text" NAME="field_length[]" SIZE="5"></TD>
	</TR>";
}
$form_block .="
<TR>
<TD ALIGN=CENTER COLSPAN=3><INPUT TYPE="submit" VALUE="Create Table"></TD>
</TR>
</TABLE>
</FORM>";
?>
<html>
<head>
<title>Create a Database Table: Step 2</title>
</head>
<body>
<H1>Define fields for <? echo "$_POST[table_name]"; ?></H1>
<? echo "$form_block"; ?>
</body>
</html>
Below is the Error:

Notice: Use of undefined constant table_name - assumed 'table_name' on line 2

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 2

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12

Notice: Use of undefined constant num_fields - assumed 'num_fields' on line 12


Any Ideas?

Re: Help with Error from a simple Create databasetable.

Posted: Fri Mar 19, 2004 10:39 am
by TheBentinel.com
bironeb wrote:if ((!$_POST[table_name]) || (!$_POST[num_fields])) {
Wrap table_name and identifiers like that in quotes:

Code: Select all

if ((!$_POST['table_name']) || (!$_POST['num_fields'])) {
And the other ones as well. See if that takes care of it.

Posted: Fri Mar 19, 2004 11:07 am
by bironeb
I changed the php code to the below:

Code: Select all

<?php
if ((!$_POST['table_name']) || (!$_POST['num_fields'])) {
	header("Location: http://127.0.0.1/testing/show_createtable.html");
	exit;
}
$form_block = "
<FORM METHOD="POST" ACTION="do_createtable.php">
<INPUT TYPE="hidden" NAME="table_name" VALUE="$_POST['table_name']">
<TABLE CELLSPACING=5 CELLPADDING=5>
<TR>
<TH>FIELD NAME</TH><TH>FIELD TYPE</TH><TH>FIELD LENGTH</TH></TR>";
for ($i=0; $i < $_POST['num_fields']; $i++) {
	$form_block .="
	<TR>
	<TD ALIGN=CENTER><INPUT TYPE="text" NAME="field_name[]" SIZE="30"></TD>
	<TD ALIGN=CENTER>
	<SELECT NAME = "field_type[]">
		<OPTION VALUE="char">char</OPTION>
		<OPTION VALUE="date">date</OPTION>
		<OPTION VALUE="float">float</OPTION>
		<OPTION VALUE="int">int</OPTION>
		<OPTION VALUE="text">text</OPTION>
		<OPTION VALUE="varchar">varchar</OPTION>
	</SELECT>
	</TD>
	<TD ALIGN=CENTER><INPUT TYPE="text" NAME="field_length[]" SIZE="5"></TD>
	</TR>";
}
$form_block .="
<TR>
<TD ALIGN=CENTER COLSPAN=3><INPUT TYPE="submit" VALUE="Create Table"></TD>
</TR>
</TABLE>
</FORM>";
?>
<html>
<head>
<title>Create a Database Table: Step 2</title>
</head>
<body>
<H1>Define fields for <? echo "$_POST['table_name']"; ?></H1>
<? echo "$form_block"; ?>
</body>
</html>
And now I get a different error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 8

Any Idea what this one might be?

Posted: Fri Mar 19, 2004 11:31 am
by TheBentinel.com
bironeb wrote:I changed the php code to the below:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 8

Any Idea what this one might be?
No, but my quick research suggests it's a misplaced $ or ", though I couldn't find one in your code.

Best idea would be to reduce the code. Take that first multi-line string and reduce it to just "hi" or something small like that. See if the error goes away. If it does, then your error is in there. If it doesn't, put it back and do it again on the next block.

I hope it helps!

Posted: Fri Mar 19, 2004 11:37 am
by Illusionist
try changing this line:

Code: Select all

<INPUT TYPE="hidden" NAME="table_name" VALUE="$_POST['table_name']">
to:

Code: Select all

<INPUT TYPE="hidden" NAME="table_name" VALUE="{$_POST['table_name']}">

Posted: Fri Mar 19, 2004 11:43 am
by bironeb
Well I figured it out... I had to remove the ' that i added in some of the other lines.

Code: Select all

<?php
<INPUT TYPE="hidden" NAME="table_name" VALUE="$_POST[table_name]">
?>
and

Code: Select all

<?php
<H1>Define fields for <? echo "$_POST[table_name]"; ?></H1>


?>
i removed the ' ' around the table_name and it works great now.

Thanks.

Posted: Fri Mar 19, 2004 11:46 am
by TheBentinel.com
bironeb wrote:Well I figured it out... I had to remove the ' that i added in some of the other lines.
I keep telling people that there's nothing to be gained by listening to me, but do they listen?

Sorry I misled you, glad you got it fixed! Though I must admit, I don't quite understand why it works without the quotes.

Posted: Fri Mar 19, 2004 11:55 am
by Illusionist
TheBentinel, you were right in tellign himt o do that. Bironeb, I suggest putting the quotes back in there and then go back and read my previous post and do what it suggests!