The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/ Share on other sites More sharing options...
unkwntech Posted August 2, 2008 Share Posted August 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-605950 Share on other sites More sharing options...
JasonLewis Posted August 2, 2008 Share Posted August 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-605954 Share on other sites More sharing options...
The Little Guy Posted August 3, 2008 Author Share Posted August 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-607032 Share on other sites More sharing options...
JasonLewis Posted August 24, 2008 Share Posted August 24, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-624148 Share on other sites More sharing options...
Lamez Posted August 24, 2008 Share Posted August 24, 2008 This helped me a bit on the headers! I smell a sticky! Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-624156 Share on other sites More sharing options...
budimir Posted August 24, 2008 Share Posted August 24, 2008 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()); Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-624170 Share on other sites More sharing options...
The Little Guy Posted September 1, 2008 Author Share Posted September 1, 2008 I feel this should be a sticky too, because today, I have read at least 4 posts where one of the answers is found in this thread. Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-631373 Share on other sites More sharing options...
DeanWhitehouse Posted October 7, 2008 Share Posted October 7, 2008 Can a mod make this topic sticky as it will help so many new members. 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 Quote Link to comment https://forums.phpfreaks.com/topic/117728-some-common-errorswarnings/#findComment-659349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.