[SOLVED]$end problem

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

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

[SOLVED]$end problem

Post 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 ???
Last edited by ol4pr0 on Mon Jan 19, 2004 10:13 am, edited 1 time in total.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post 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...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

..

Post 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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

zend (my best mate) tells me i have a $end error when..........

i havent closed a } on my operators
Post Reply