Page 1 of 1

Unexpected T-string

Posted: Thu Oct 12, 2006 3:16 pm
by darkfreaks
it says there is an unexpected t-string in line 12 of my php file, i cant find it help me guys.


line 12: $form_block ="

Posted: Thu Oct 12, 2006 3:21 pm
by SpecialK
You haven't properly closed your string.

Code: Select all

line 12: $form_block ="
should be

Code: Select all

line 12: $form_block ="";

Posted: Thu Oct 12, 2006 3:36 pm
by darkfreaks
now it says unexpected '<' in line 11

Line 11: <form method="post" action="show_createtable.php">

Posted: Thu Oct 12, 2006 3:39 pm
by d3ad1ysp0rk
Please post your entire code, I have a strange feeling you're not grasping how PHP works.

Posted: Thu Oct 12, 2006 3:39 pm
by darkfreaks
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php 

//validate important input

if ((!$_POST[table_name])  ||  (!$_POST[num_fields]))  {
header ("location:show_createtable.html");
exit;
}
//begin creating form for display
$form_block ="";

<form method="post" action="show_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>";

//count from 0 until you reach the number of fields for
 
($i = 0; $i < $_POST[num_fields]; $i++) {

//add to the form , one row for each field

$form_block ="";
<TR>
<TD ALIGN=CENTER>
<input type="text" name="field_name[]" size=30></TD>
<TD ALIGN=CENTER>
<select name="field_type[]">
  <option value="field">field</option>
  <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>
<p>";
  }
  
//finish up the form</p>
$form_block .= "
<TR>
<TD ALIGN=CENTER COLSPAN=3><input type="submit" value="Create Table"></TD>
</TR>
</TABLE>
</FORM>";
?>
<html>
<head>
<title>Cteate Table Step 2</title>
<body>
<h1>Define fields for <? echo $_POST[table_name]; ?> 
</h1>
<? echo $form_block ?>
</body>
</html>

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Oct 12, 2006 3:58 pm
by volka
the whole <form .... text should be part of the string stored in $form_block.

Code: Select all

$s = "abc"; ?>
The first " tells php that a string literal begins. The next unescaped " ends the string.
So what does

Code: Select all

$form_block ="
<form method="post" action="show_createtable.php">
tell php? You can see how the syntaxhighlither changes the color after <form method=". It does not consider post as part of the string; neither does php.
try

Code: Select all

$form_block = '
		<form method="post" action="show_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>';
There are two more identical error sources.
($i = 0; $i < $_POST[num_fields]; $i++) {
missing for

Posted: Thu Oct 12, 2006 4:06 pm
by RobertGonzalez
Your code needs to be reviewed. There are a lot of issues with it.

Posted: Thu Oct 12, 2006 4:14 pm
by RobertGonzalez
Try this one (there are still things in this that need attention, but it is a little better than the originally posted code):

Code: Select all

<?php
//validate important input
if ((!$_POST['table_name'])  ||  (!$_POST['num_fields']))  {
    header ("location:show_createtable.html");
    exit;
}

//begin creating form for display
$form_block = '
<form method="post" action="show_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>';

//count from 0 until you reach the number of fields for
for ($i = 0; $i < $_POST['num_fields']; $i++) {
    //add to the form , one row for each field

    $form_block = '
<TR>
<TD ALIGN=CENTER>
<input type="text" name="field_name[]" size=30></TD>
<TD ALIGN=CENTER>
<select name="field_type[]">
  <option value="field">field</option>
  <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>
';
}
 
//finish up the form</p>
$form_block .= '
<TR>
<TD ALIGN=CENTER COLSPAN=3><input type="submit" value="Create Table"></TD>
</TR>
</TABLE>
</FORM>';
?>
<html>
<head>
<title>Cteate Table Step 2</title>
<body>
<h1>Define fields for <? echo $_POST['table_name']; ?>
</h1>
<? echo $form_block ?>
</body>
</html>

hehe

Posted: Thu Oct 12, 2006 4:19 pm
by darkfreaks
hmmm seems ive got to code better syntax next time too man errors.

anyways it doesnt give me any errors just page cant be found.

hmmm

Posted: Thu Oct 12, 2006 4:24 pm
by darkfreaks
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


now it works but at the top is some of the code

Code: Select all

//validate important input if ((!$_POST['table_name']) || (!$_POST['num_fields'])) { header ("location:show_createtable.html"); exit; } //begin creating form for display $form_block = ' 
 FIELD NAME FIELD TYPE FIELD LENGTH 
'; //count from 0 until you reach the number of fields for for ($i = 0; $i < $_POST['num_fields']; $i++) { //add to the form , one row for each field $form_block = '    field char date float int text varchar   
'; } //finish up the form

$form_block .= '
i can see it on the page err?


and where it says define fields it says

\' . $_POST[\'table_name\'] . \'


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Oct 12, 2006 4:33 pm
by RobertGonzalez
What is your question? And please, when you post code, highlight it then click the PHP button just above the input area. Thanks.

Code: Select all

//validate important input 
if ((!$_POST['table_name']) || (!$_POST['num_fields'])) { 
    header ("location:show_createtable.html"); 
    exit; 
} 
//begin creating form for display 
$form_block = '
FIELD NAME FIELD TYPE FIELD LENGTH
'; 
//count from 0 until you reach the number of fields for 
for ($i = 0; $i < $_POST['num_fields']; $i++) 
{ 
    //add to the form , one row for each field 
    $form_block = '    field char date float int text varchar   '; 
} 

//finish up the form
$form_block .= '