Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse error 3

Status
Not open for further replies.

Sardamil

Programmer
Apr 14, 2001
77
NL
Sorry to bother you with this, but I've been staring at this code for a few days now and can't find where I went wrong. I'm very new to php, so it might be something basic. Hope you won't mind helping me out.


Parse error: syntax error, unexpected $end in /var/ on line 44

<?php

//Betekent dat er met sessies word gewerkt

session_start();



/* Deze pagina heet: aanwezigcode.php */



//Query opstellen om gegevens uit de database te halen.

$que = "SELECT * FROM wedstrijden;

//Query uitvoeren

$uitvoeren1 = mysql_query($que) or die(mysql_error());

//rij maken zodat je gegevens kan gebruiken

while($rij = mysql_fetch_assoc($uitvoeren1)){



//Echo(laat zien simpel form)

echo '

<form action="aanwezig.php" method="POST">

Ben jij aanwezig bij de wedstrijd op '.htmlenspecialchars($rij['datum']).'?<br>

Thuis '.htmlenspecialchars($rij['thuis']).'!
Uit '.htmlenspecialchars($rij['uit']).'!

<input type="radio" name="aanwezig" value="aanwezig">Aanwezig</input>

<input type="radio" name="aanwezig" value="afwezig">Afwezig</input>

<input type="submit" name="submit" value="Verstuur" />

</form>';



//Even een dingetje opstellen voor de database

$wedstrijdid = $_POST['wedstrijdid'];



//Als form verstuurd is

if( isset($_POST['verstuur'])){



//Connecteren met aanwezigheid

$host = 'xxxxx'; //Host

$gebruikersnaam = 'xxxxx'; //Gebruikersnaam

$wachtwoord = 'xxxxx'; //Wachtwoord

$database = 'xxxxx'; //Naam database



$conn = mysql_connect($host, $gebruikersnaam, $wachtwoord);

mysql_select_db($database) or die(mysql_error());



//Een query maken en beveiligen met mysql_real_escape_string

$query = "UPDATE aanwezigheid SET spelerid='".mysql_real_escape_string($_SESSION['speler'])."', wedstrijdid = '".mysql_real_escape_string($_POST[$wedstrijdid])."'";

$uitvoeren = mysql_query($query) or die(mysql_error());

}

?>

Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
Basically your query never ends, as you are missing a closing pair of quotes:

Code:
$que = "SELECT * FROM wedstrijden[red]>><<[/red];


This begins a cascade effect, until the end of the script where it mysteriously ends. Which is why it finds an unexpected end.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks, I missed that one. But it seems there's more in my script that's lacking. Is there anything that'll help me to debug this thing without me having to bother you guys all the time?

Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
The errors should be the ones to provide help.

What other error do you get?


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I keep getting parse errors, but now it's

Parse error: syntax error, unexpected $end in /var/ on line 17

This error is in this script or could the login script, which refers to this script also be the cause?

Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
Well you'd need to check that you quotes are balanced. That you have semicolons where they need to be etc...


Its telling you the line number it finds the error. Look at all the lines prior to line 17 make sure everything is o.k.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I did check my quotes after my previous parse error, but couldn't find any. I'll check again when I get home. I must have overlooked something.

Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
Hi

Such errors usually are clearly visible when editing your script with a text editor with syntax highlighting feature. If not using such editor, I suggest to take a look at faq434-4252 and try one/some from there.

Feherke.
 
Sardamil said:
Code:
htmlenspecialchars()
is this a user defined function that you have not shown us the code for? for built in functions I am aware of htmlspecialchars() and htmlentities() but not the hybrid that you suggest.

unless this is a UDF, php should throw an error and stop working when you run this code.
 
I deleted the htmlenspecialchars() statements last night. Don't think I need it.
But you're right, must have been a mistake on my part. Perhaps I should have another look at my code and if I really can't find where I went wrong, I should repost the code?

Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
this code should work. you were also testing for isset($_POST['verstuur']) whereas i don't think that you have a control named verstuur. it's named submit instead.

note the use of the heredoc syntax in lieu of quotes. it makes life significantly easier.

note also that
1. you are updating the database with a value of $_POST[$wedstrijdid] but the variable $wedstrijdid is not defined. i assume that you want to update with the value of a match ID which should be stored, perhaps in a hidden field, in the form.
2. you are not doing anything with the value of aanwezig in your update code.
3. the database select code is in a while loop and so you will get a form for each record. however you are not including anything in the form output that allows you to identify the record that you are addressing. (although you later address the match ID in your update code.
4. it would be perhaps better to preselect the radio status with the current value of the player's presence in the relevant match.

Code:
<?php
//Betekent dat er met sessies word gewerkt
session_start();
/* Deze pagina heet: aanwezigcode.php */
//Query opstellen om gegevens uit de database te halen.
$que = "SELECT * FROM wedstrijden";
//Query uitvoeren
$uitvoeren1 = mysql_query($que) or die(mysql_error());

//rij maken zodat je gegevens kan gebruiken
while($rij = mysql_fetch_assoc($uitvoeren1)){
	//Echo(laat zien simpel form)
	array_map('htmlspecialchars', $rij);
	echo <<<HTML
<form action="aanwezig.php" method="POST">
<p>
Ben jij aanwezig bij de wedstrijd op {$rij['datum']}?<br/>
Thuis {$rij['thuis']}!<br/>
Uit {$rij['uit']}!<br/>
</p>
<p>
<input type="radio" name="aanwezig" value="aanwezig" />Aanwezig
<input type="radio" name="aanwezig" value="afwezig"/>Afwezig
<input type="submit" name="submit" value="Verstuur" />
</p>
</form>
HTML;
}
//Even een dingetje opstellen voor de database
$wedstrijdid = $_POST['wedstrijdid'];
//Als form verstuurd is
if( isset($_POST['submit'])){
	//Connecteren met aanwezigheid
	$host =         'xxxxx'; //Host
	$gebruikersnaam =     'xxxxx'; //Gebruikersnaam
	$wachtwoord =         'xxxxx'; //Wachtwoord
	$database =         'xxxxx'; //Naam database
	$conn = mysql_connect($host, $gebruikersnaam, $wachtwoord);
	mysql_select_db($database) or die(mysql_error());
	//Een query maken en beveiligen met mysql_real_escape_string

	$query = "	UPDATE aanwezigheid 
				SET 
				spelerid='".mysql_real_escape_string($_SESSION['speler'])."', 
				wedstrijdid = '".mysql_real_escape_string($_POST[$wedstrijdid])."'";

	$uitvoeren = mysql_query($query) or die(mysql_error());
}
?>
 
thanks. I had to add another connect and then the script worked. Thought the login script would provide the connect. Apparently not. Now I have to find out why the update scrpt updated all spelerid and wedstrijdid fields to 0. Now I have to edit about 400 records :-(

<?php
//Betekent dat er met sessies word gewerkt
session_start();
/* Deze pagina heet: aanwezigcode.php */

//Connecteren met wedstrijden

$mysqlhost = 'xxxxx'; //Host

$mysqlgebruikersnaam = 'xxxxx'; //Gebruikersnaam

$mysqlwachtwoord = 'xxxxx'; //Wachtwoord

$mysqldatabase = 'xxxxx'; //Database



$conn1 = mysql_connect($mysqlhost, $mysqlgebruikersnaam, $mysqlwachtwoord);

mysql_select_db($mysqldatabase) or die(mysql_error());


//Query opstellen om gegevens uit de database te halen.
$que = "SELECT * FROM wedstrijden";
//Query uitvoeren
$uitvoeren1 = mysql_query($que) or die(mysql_error());

//rij maken zodat je gegevens kan gebruiken
while($rij = mysql_fetch_assoc($uitvoeren1)){
//Echo(laat zien simpel form)
array_map('htmlspecialchars', $rij);
echo <<<HTML
<form action="aanwezig.php" method="POST">
<p>
Datum {$rij['datum']}<br/>
Thuis {$rij['thuis']}<br/>
Uit {$rij['uit']}<br/>
</p>
<p>
<input type="radio" name="aanwezig" value="aanwezig" />Aanwezig
<input type="radio" name="aanwezig" value="afwezig"/>Afwezig
<input type="submit" name="submit" value="Verstuur" />
</p>
</form>
HTML;
}
//Even een dingetje opstellen voor de database
$wedstrijdid = $_POST['wedstrijdid'];
//Als form verstuurd is
if( isset($_POST['submit'])){
//Connecteren met aanwezigheid

$host = 'xxxxx'; //Host

$gebruikersnaam = 'xxxxx'; //Gebruikersnaam

$wachtwoord = 'xxxxx'; //Wachtwoord

$database = 'xxxxx'; //Naam database

$conn = mysql_connect($host, $gebruikersnaam, $wachtwoord);
mysql_select_db($database) or die(mysql_error());
//Een query maken en beveiligen met mysql_real_escape_string

$query = " UPDATE aanwezigheid
SET
spelerid='".mysql_real_escape_string($_SESSION['speler'])."',
wedstrijdid = '".mysql_real_escape_string($_POST[$wedstrijdid])."'";

$uitvoeren = mysql_query($query) or die(mysql_error());
}
?>

Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
query was wrong. I put the where in the set.
would this work?

$query = " UPDATE aanwezigheid
SET aanwezigheid = '".mysql_real_escape_string($_POST[$aanwezig])."'
where spelerid='".mysql_real_escape_string($_SESSION['speler'])."'
and wedstrijdid = '".mysql_real_escape_string($_POST[$wedstrijdid])."'";


Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
would this work: no.

this would

Code:
 $query = "    UPDATE aanwezigheid
                SET aanwezigheid = '".mysql_real_escape_string($_POST['aanwezig'])."'
                where spelerid='".mysql_real_escape_string($_SESSION['speler'])."'
                and wedstrijdid = '".mysql_real_escape_string($_POST['wedstrijdid'])."'";

you were using undefined variables as array keys.

 
I know it's possible to put this fields in the form in a table. I tried to do this, but ended up making a mess of it. I'm still not used to combining html and php. I only started php a week ago and managed to piece together this bit of code with lots of help. So I hope you can forgive me these stupid questions. I'm trying to learn, but it's a slow process.

/ de table beginnen
echo '
<table>
<tr>
<td>Datum</td>
<td>Thuis</td>
<td>Uit</td>
<td>Aanwezig</td>';

//rij maken zodat je gegevens kan gebruiken
while($rij = mysql_fetch_assoc($uitvoeren1)){
//Echo(laat zien simpel form)
array_map('htmlspecialchars', $rij);
echo <<<HTML
<form action="aanwezig.php" method="POST">
</tr>
<tr>
<td>'.$rij['datum'].'</td>
<td>'.$rij['thuis'].'</td>
<td>'.$rij['uit'].'</td>
<td><input type="radio" name="aanwezig" value="aanwezig" />Aanwezig
<input type="radio" name="aanwezig" value="afwezig"/>Afwezig
<input type="submit" name="submit" value="Verstuur" /></td>'

// en tenslotte de boel afsluiten
echo '
</tr>
</table>';
</form>
HTML;
}

Murphy's Law said:
Anything that can go wrong will go wrong

Window to my world
 
you're nearly right. read up lots more on heredoc

Code:
  echo <<<HTML
<form action="aanwezig.php" method="POST">
                </tr>
                <tr>
                    <td>{$rij['datum']}</td>
                    <td>{$rij['thuis']}</td>
                    <td>{$rij['uit']}</td>
                    <td><input type="radio" name="aanwezig" value="aanwezig" />Aanwezig
                            <input type="radio" name="aanwezig" value="afwezig"/>Afwezig
                            <input type="submit" name="submit" value="Verstuur" /></td>'
HTML;
// en te

use curly braces inside heredoc for object properties (and methods) and array elements. otherwise just use variables as if they were inside double quotes.

note carefully the rules about terminating heredoc. dreamweaver mucks this up every time unless you turn auto-line-indenting off
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top