Jump to content

Recommended Posts

Parse error: syntax error, unexpected $end...

Usually means that there is an open "{" and no closing "}"

Example:

if(1 == 1){
echo '1 = 1';
}else{
echo 'NOT';

 

Fix:

if(1 == 1){
echo '1 = 1';
}else{
echo 'NOT';
}

 

 

 

 

Cannot modify header information - headers already sent...

This is because you are trying to set header information after you have added some output to your HTML source file.

To remove this error, simply take your header information, and place it before any HTML.

Example:

echo 'cat';
$i = $_GET['i'];
if($i == 1){
header("location: /");
exit;
}

 

Fix:

$i = $_GET['i'];
if($i == 1){
header("location: /");
exit;
}
echo 'cat';

 

 

 

 

Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';'...

This usually is because you forgot to add a semi-colon or colon at the end of one of your statements

Example:

echo 'cat'
echo 'dog';

// OR

switch(5){
case 4
	echo 'cat';
break;
case 5
	echo 'dog';
break;
}

 

Fix:

echo 'cat';
echo 'dog';

// OR

switch(5){
case 4:
	echo 'cat';
break;
case 5:
	echo 'dog';
break;
}

 

 

 

 

Parse error: syntax error, unexpected ')'...

This is usually because you are forgetting to add a expression to your condition.

Example:

if(){
echo 'dog';
}

 

Fix:

if(TRUE){
echo 'dog';
}

 

 

 

 

Parse error: syntax error, unexpected '<'...

You more than likely forgot to close one of your PHP tags "?>" or forgot to add a quote somewhere.

Example:

echo 'cat';
<div>dog</div>

 

Fix:

echo 'cat';
echo '<div>dog</div>';

// OR

echo 'cat';
?>
<div>dog</div>

 

 

 

Fatal error: Call to undefined function someFunction()...

You probably did one of 3 things

1. Made a spelling error in your function name

2. Don't have the extention installed

3. Didn't define your custom function before you called it

Example:

echo animals();
function animals(){
return 'cat';
}

 

Fix:

function animals(){
return 'cat';
}
echo animals();

 

 

 

 

Fatal error: Cannot redeclare animals() (previously declared...

This happens when you define a function more than one time by either calling a file 2+ times with the function in it

or because somehow you defined it 2+ times in more than one file, or just bad programming.

Example:

for($i=0;$i<5;$i++){
function myCall($num){return $num.' cats';}
echo myCall($i);
}

 

Fix:

function myCall($num){return $num.' cats';}
for($i=0;$i<5;$i++){
echo myCall($i);
}

 

 

 

 

Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE...

This will happen because your function is looking for a variable to be defined and none is given.

Example:

function myCall($one,){
return $one.' '.$two;
}

echo myCall($one,$two);

 

Fix:

function myCall($one,$two){
return $one.' '.$two;
}

echo myCall($one,$two);

 

 

 

 

Warning: Missing argument 2 for myCall()...

Your function is expecting more than one value to be passed to it, so either do one of 3 things:

1. Pass the missing value to it

2. Create a new function

3. Give each value you want opional a default value Ex: "function myCall($one, $two = 2)"

Example:

function myCall($one,$two){
return $one.' '.$two;
}

echo myCall($one);

 

Fix:

function myCall($one,$two){
return $one.' '.$two;
}
$one = 1;
echo myCall($one,$two);

// OR

function myCall($one){
return $one;
}
$one = 1;
echo myCall($one);

// OR

function myCall($one,$two = 2){
return $one. ' '.$two;
}
$one = 1;
echo myCall($one);

 

 

 

 

Warning: include(dog.php) [function.include]: failed to open stream:...

Warning: include() [function.include]: Failed opening 'dog.php' for inclusion...

This one is a little harder to fix, what you need to do is check and see if the file you are looking for

is actually where you say it is, and there is a function for that.

Example:

$filename = 'dog.php';  // Assuming this file is actually in the parent folder/directory
include $filename;

 

Fix:

$filename = '../dog.php';  // Assuming this file is actually in the parent folder/directory
if(file_exists($filename)){
include $filename;
}else{
echo "this file wasn't found";
}

Link to comment
https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/
Share on other sites

One quick suggestion

Cannot modify header information - headers already sent...

This is because you are trying to set header information after you have added some output to your HTML source file.

To remove this error, simply take your header information, and place it before any HTML.

you might want to change 'HTML' to 'any output including HTML and whitespace'

 

And this defiantly should be stickied

I've got another one you might want to add.

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

This error can occur when you don't escape quotes.

 

Example:

echo "<a href="http://www.google.com">Visit Google!</a>";

 

Fix:

echo "<a href=\"http://www.google.com\">Visit Google!</a>";

//OR

echo "<a href='http://www.google.com'>Visit Google!</a>";

 

+1 for sticky.

you might want to change 'HTML' to 'any output including HTML and whitespace'

 

HTML source file, that contains white space, html, text, javascript, HTML comments, anything in that source. That is what I meant by that line.

 

 

Thanks for the Error/Warnings addition(s) anyone else can add some common ones too.

  • 3 weeks later...

Another Common Error that has been posted on here a bit.

 

Parse error: syntax error, unexpected T_STRING

This error usually occurs when you do not end the string properly.

 

Example:

$string = "This is a string with no end;

 

Fix:

$string = "This is a string with an end"; //Notice the closing "

 

Can this thread be stickied?

This one could end up as a sticky.

It helps a lot!!

 

 

Her is another one:

 

When you have a problem with the query, not doing anything and not reporting anything.

 

Problem:

$result = mysql_query($sql,$conn);

 

Fix:

$result = mysql_query($sql,$conn) or die (mysql_error());

 

 

  • 2 weeks later...
  • 1 month later...

Can a mod make this topic sticky as it will help so many new members.

:D

 

Also

Notice: Undefined index:something

PHP code

<?php
//db connection
$sql= mysql_query("SELECT * FROM table");
while($row = mysql_fetch_assoc($sql))
{
echo $row['something'];
}
?>

 

It means that the row is not there, it doesnt exist, but in other cases it will mean that it is not defined (means the same thing)

 

Correct me if i'm wrong

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.