Page 1 of 1

[SOLVED]$end problem

Posted: Mon Jan 19, 2004 8:42 am
by ol4pr0
I got this unexpected $end problem in the closing tags ?> first i thought i might be something with apache 2.0.4.8 with being still experimental with php4 ( v4.3.4) so i installed version 1.3.29 however the ?> errror keeps on coming, now i know its not the closing tags however i can not seem to find the problem. ( 2 scripts )

Code: Select all

<?php
$dbase ='home';
$tablename ='pongo';
$connect= mysql_connect('localhost', 'root')
	or die("Cant connect: " .mysql_error());
$result=mysql_select_db($dbase)
	or die("Cant execute query: " .mysql_error());
$query = 'CREATE TABLE if not exist " . $tablename . "(Empresa varchar(20) Not Null, Codigo INT(10), From varchar(20) Not Null, To varchar(20) Not Null, Information varchar(20) Not Null, Comment varchar(20) Not Null Codigo_Env PRIMARY KEY)";
$result = mysql_query($query); 
if (!$result)
{ 
die ( "Execute error: " .mysql_error());
}
else
{
	echo $tablename . " Todo bien, comienza.\n";
}

$query ='INSERT INTO pongo VALUES ('" . $s1 ."', '" . $2 ."','"  . $3 . "','" . $4 . "','" . $5 . "','" . $6 . "','" . $7 . "','" . $8 . "','" $9 . "')';
if (!$result = mysql_query($query);
die(mysql_error());
}
?>
__________________________________________
second code with same error

Code: Select all

<?
function pc_print_form($errors) { 
$fields = array(Empresa => 'Empresa',
		       Informacion => 'Informacion',
			   Desde => 'Desde',
			   Envio => 'Envio');
if (count($errors)) {
	echo 'Por favor revisar to entradas';
}

echo '<table';

//printing errors
foreach ($fields as $field => $fieldname) {
	//open row
	echo '<tr><td>';

// printing error
if (!empty($errors[$field])) {
	echo $errors[$field];
}else {
	echo '&nbsp;'; // making sure the tables are printed correct
}

echo '</td></tr>';
// printing values
$value = isset($_REQUEST[$field]) ?
	htmlentities($_REQUEST[$field]) : '';

echo '$fieldname: ';
echo '<input type="text" name="$field" value="$value">';
echo '</td></tr>';
}
echo '</table>';
?>
both have error

Parse error: parse error, unexpected $end ($line :> )

Now where did i go wrong ???

Posted: Mon Jan 19, 2004 8:55 am
by Straterra
The reason you got an unexpected end is because you didn't close all of your brackets (if/then, case/switch, while, ect.,). Try going through your code again and carefully checking your brackets...

Posted: Mon Jan 19, 2004 8:58 am
by twigletmac
In the first piece of code, you start both SQL queries with single quotes and use double quotes to end them (change the first single quotes to double quotes). Then you also have a concenation mark missing in the second query (ie. you have "$variable."', instead of ".$variable."). Notice how the syntax highlighting really didn't like that code snippet.

In the second code snippet there is:
(1) No quotes around the element names in the definition for fields.
(2) No closing brace for the function.

Compare with the following, note how indenting makes the code easier to debug:

Code: Select all

<?php
function pc_print_form($errors) {
	$fields = array(
		'Empresa' => 'Empresa',
		'Informacion' => 'Informacion',
		'Desde' => 'Desde',
		'Envio' => 'Envio');

	if (count($errors)) {
	   echo 'Por favor revisar to entradas';
	}

	echo '<table>';

	//printing errors
	foreach ($fields as $field => $fieldname) {
	   //open row
	   echo '<tr><td>';

		// printing error
		if (!empty($errors[$field])) {
		   echo $errors[$field];
		} else {
		   echo ' '; // making sure the tables are printed correct
		}

		echo '</td></tr>';
		// printing values
		$value = isset($_REQUEST[$field]) ? htmlentities($_REQUEST[$field]) : '';

		echo '$fieldname: ';
		echo '<input type="text" name="$field" value="$value">';
		echo '</td></tr>';
	}
	echo '</table>';
}
?>
Mac

..

Posted: Mon Jan 19, 2004 10:14 am
by ol4pr0
Thanks alot....

still messing with the first code.. however i am confident ill figure it out..

i guess it should of been like this...

Code: Select all

$query ="INSERT INTO pongo VALUES ('".$s1."','".$s2."','".$s3."','".$s4."','".$s5."','".$s6."','".$s7."','".$s8."','".$s9."')";
if (!$result = mysql_query($query))";
die (  .mysql_error())";
i should get **** wooping :> lol..

thanks

Posted: Mon Jan 19, 2004 12:13 pm
by malcolmboston
zend (my best mate) tells me i have a $end error when..........

i havent closed a } on my operators