wrathican Posted June 28, 2007 Share Posted June 28, 2007 im getting an error when using a switch statement. im quite uncertain as to why im getting this error. here it is: Parse error: syntax error, unexpected T_CASE in F:\wamp\www\CycleYorkshire\cms\commentadmin.php on line 160 my line 160 is this: case "view": and the little section of code that this little piece resides in is this: case "dele": $id = $_GET['id']; $query = "DELETE FROM cy_comment WHERE com_id='".$id."'"; mysql_query($query); echo 'Thank you. The selected comment has been deleted. Please go <a href="commentsadmin.php">back</a> and select a different option'; break; case "processadd": //get the variables, make a get date, insert into db, show confirmation $name = $_POST['name']; $email = $_POST['email']; $tour = $_POST['tour']; $title = $_POST['subject']; $body = $_POST['comment']; $date = date("Y/d/m"); $query = "INSERT INTO cy_comment (com_title, com_date, com_body, com_owner, com_email, com_tour) values ('$title', '$date', '$body', '$name', '$email', '$tour')"; mysql_query(query); echo 'Thank you. Your comment has been added. Please go <a href="commentsadmin.php">back</a> and make a new selection.'; break; case "display": //display list of all comments $query = "SELECT * FROM cy_comment"; $result = mysql_query($query); ?> <table width="349" border="0" cellpadding="0" cellspacing="0"> <? while ($row = mysql_fetch_array($result, MYSQL,NUM)) { $id = $row[0]; $title = $row[1]; $name = $row[4]; ?> <tr> <td width="118" height="19" valign="top"><?php echo $title; ?></td> <td width="22" valign="top">by</td> <td width="130" valign="top"><?php echo $name; ?></td> <td width="40" valign="top"><a href="commentadmin.php?func=view&id=<?php echo $id; ?>">View</a></td> <td width="39" valign="top"><a href="commentadmin.php?func=dele&id=<?php echo $id; ?>">Delete</a></td> </tr> <?php }; ?> </table> <?php break; case "view": //view selectd comment, need table to display it $id = $_GET['id']; $query = "SELECT * FROM cy_comment WHERE com_id='".$id."'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $id = $row[0]; $title = $row[1]; any suggestions Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted June 28, 2007 Share Posted June 28, 2007 which line number is 160? You have no default case. Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 i said in the post above, it reads: case "view": Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted June 28, 2007 Share Posted June 28, 2007 you have no default case, but you might need to add "break;" at the end. Quote Link to comment Share on other sites More sharing options...
trq Posted June 28, 2007 Share Posted June 28, 2007 We need to see a few lines prior. Quote Link to comment Share on other sites More sharing options...
bbaker Posted June 28, 2007 Share Posted June 28, 2007 5 lines up from the line case "view": there is }; remove the ; as it's at the end of your while statement and not needed. If that doesn't do it, can you show the entire switch statement instead of just a piece of it? Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 here is the whole statement: <?php include '../include/switch.inc'; include '../include/misc.inc'; include '../include/opendb.inc'; ?> <HTML> <HEAD> <TITLE>CycleYorkshire.co.uk: Content Management System</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="../cy.css"> </HEAD> <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0><center> <!-- ImageReady Slices (layout_concept3.psd) --> <TABLE WIDTH=800 BORDER=0 CELLPADDING=0 CELLSPACING=0> <!--DWLayoutTable--> <TR> <TD height="301" COLSPAN=2 valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD width="800" height="11" valign="top"> <IMG SRC="../images/cycleyorkshirebase_01.gif" WIDTH=800 HEIGHT=11 ALT=""></TD> </tr> <tr> <TD height="290" valign="top"> <a href="index.php"><IMG SRC="../images/cycleyorkshirebase_02.gif" ALT="" WIDTH=800 HEIGHT=290 border="0"></a></TD> </tr> </table> </TD> </TR> <TR> <TD width="216" height="751" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD width="200" height="23" valign="top"> <IMG SRC="../images/cycleyorkshirebase_03.gif" WIDTH=200 HEIGHT=23 ALT=""></TD> <td width="16" rowspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="16" height="751"> </td> </tr> </table> </td> </tr> <tr> <TD height="420" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <?php include '../include/navicms.inc'; ?> </tr> </table></TD> </tr> <tr> <TD height="58" valign="top"> <IMG SRC="../images/cycleyorkshirebase_26.gif" WIDTH=200 HEIGHT=58 ALT=""></TD> </tr> <tr> <TD height="19" valign="top"><p><?php //get the 'this weekend' and display $query = "SELECT * FROM cy_weekend"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $body = $row[1]; } echo $body;?></p></TD> </tr> <tr> <TD height="231" valign="top"> <IMG SRC="../images/cycleyorkshirebase_30.gif" WIDTH=200 HEIGHT=231 ALT=""></TD> </tr> </table></TD> <TD width="584" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD height="19" colspan="2" valign="top"><h1>Comments Admin</h1></TD> </tr> <tr> <TD height="19" colspan="2" valign="top"><p> <?php switch($_GET['func']){ case "add": //show form to add a comment to DB post to commentadmin.php?func=processadd ?> <form id="form1" name="form1" method="post" action="commentadmin.php?func=processadd"> <p>Name:<br /> <input name="name" type="text" id="name" /> <br /> E-Mail:<br /> <input name="email" type="text" id="email" /> <br /> Course/Tour name:<br /> <input name="tour" type="text" id="tour" /> <br /> Subject:<br /> <input name="subject" type="text" id="subject" /> <br /> Comments:<br /> <textarea name="comment" cols="50" rows="10" id="comment"></textarea> <br /> <input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /> </p> </form><a href="cms.php">Back</a> <?php break; case "dele": $id = $_GET['id']; $query = "DELETE FROM cy_comment WHERE com_id='".$id."'"; mysql_query($query); echo 'Thank you. The selected comment has been deleted. Please go <a href="commentsadmin.php">back</a> and select a different option'; break; case "processadd": //get the variables, make a get date, insert into db, show confirmation $name = $_POST['name']; $email = $_POST['email']; $tour = $_POST['tour']; $title = $_POST['subject']; $body = $_POST['comment']; $date = date("Y/d/m"); $query = "INSERT INTO cy_comment (com_title, com_date, com_body, com_owner, com_email, com_tour) values ('$title', '$date', '$body', '$name', '$email', '$tour')"; mysql_query(query); echo 'Thank you. Your comment has been added. Please go <a href="commentsadmin.php">back</a> and make a new selection.'; break; case "display": //display list of all comments $query = "SELECT * FROM cy_comment"; $result = mysql_query($query); ?> <table width="349" border="0" cellpadding="0" cellspacing="0"> <? while ($row = mysql_fetch_array($result, MYSQL,NUM)) { $id = $row[0]; $title = $row[1]; $name = $row[4]; ?> <tr> <td width="118" height="19" valign="top"><?php echo $title; ?></td> <td width="22" valign="top">by</td> <td width="130" valign="top"><?php echo $name; ?></td> <td width="40" valign="top"><a href="commentadmin.php?func=view&id=<?php echo $id; ?>">View</a></td> <td width="39" valign="top"><a href="commentadmin.php?func=dele&id=<?php echo $id; ?>">Delete</a></td> </tr> <?php } ?> </table> <?php break; case "view": //view selectd comment, need table to display it $id = $_GET['id']; $query = "SELECT * FROM cy_comment WHERE com_id='".$id."'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $id = $row[0]; $title = $row[1]; $name = $row[4]; $date = $row[2]; $body = $row[3]; $email = $row[5]; $tour = $row[6]; $fdate = date('j/n/Y', strtotime($date));; ?> <table width="349" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td height="19" colspan="2" valign="top"><?php echo $title; ?></td> <td width="22" valign="top">by</td> <td colspan="2" valign="top"><?php echo $name; ?></td> <td width="22" valign="top">on</td> <td width="57" valign="top"><?php echo $fdate; ?></td> </tr> <tr> <td width="19" rowspan="3" valign="top"><!--DWLayoutEmptyCell--> </td> <td height="19" colspan="6" valign="top"><?php echo $tour; ?></td> </tr> <tr> <td height="53" colspan="6" valign="top"><?php echo $body; ?></td> </tr> <tr> <td height="19" colspan="6" valign="top"><?php echo $email; ?></td> </tr> <tr> <td height="19" colspan="4" valign="top"><!--DWLayoutEmptyCell--> </td> <td colspan="2" valign="top"><a href="commentadmin.php?func=display">Back</a></td> <td valign="top"><a href="commentadmin.php?func=dele&id=<?php echo $id; ?>">Delete</a></td> </tr> <tr> <td height="1"></td> <td width="99"></td> <td></td> <td width="104"></td> <td width="26"></td> <td></td> <td></td> </tr> </table> <?php break; default: //display links to other functions ?> <a href="commentadmin.php?func=display">View list of comments</a><br> <a href="commentadmin.php?func=add">Add new comment</a><br> <a href="cms.php">Back</a> <? }?></p></TD> </tr> <tr> <TD height="1"> </TD> <TD></TD> </tr> </table></TD> </TR> <TR> </center> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted June 28, 2007 Share Posted June 28, 2007 line 174 has ;; Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 nicely spotted mistake there but unfortunately that did not help. i still get the error on line 160 Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted June 28, 2007 Share Posted June 28, 2007 does perhaps closing the while loop on 165 make a difference? You have no closing braket } Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 case "display": //display list of all comments $query = "SELECT * FROM cy_comment"; $result = mysql_query($query); ?> <table width="349" border="0" cellpadding="0" cellspacing="0"> <? while ($row = mysql_fetch_array($result, MYSQL_NUM)) { You are not using <?php which could be the problem as <? is depreciated in later versions of PHP, also you have a comma between MYSQL and NUM Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 as far as i can see i do have a closing bracket.... could you point out where? Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted June 28, 2007 Share Posted June 28, 2007 your opening bracket is on 166, and a closing bracket is not found until 222 which is inside the default case. I gotta go, hope you figure it out! Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 case "display": //display list of all comments $query = "SELECT * FROM cy_comment"; $result = mysql_query($query); ?> <table width="349" border="0" cellpadding="0" cellspacing="0"> <? while ($row = mysql_fetch_array($result, MYSQL_NUM)) { You are not using <?php which could be the problem as <? is depreciated in later versions of PHP, also you have a comma between MYSQL and NUM ehrmmm Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 sorry that was aimed at sKunKbad. that sorted that, now i have an error on line 214 that line being: default: Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 <a href="commentadmin.php?func=add">Add new comment</a><br> <a href="cms.php">Back</a> <? }?> Same deal here, need the <?php and here <td></td> <td></td> </tr> </table> <?php } // added to close the while loop break; default: you need a } to close the while loop. Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 ok scratch that, i dodnt close the while statement there. but now i have another error: Parse error: syntax error, unexpected $end in F:\wamp\www\CycleYorkshire\cms\commentadmin.php on line 235 and that line is the end of my html </HTML> Quote Link to comment Share on other sites More sharing options...
bbaker Posted June 28, 2007 Share Posted June 28, 2007 add a } before break; default: to close your while statement that is started in case "view": Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 [move]thank you very much[/move] for all your help that worked just as i need. Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 Do you understand what those syntax errors mean and how to fix them yourself. My post above should solve the problem. But these are all pretty basic syntax errors. My main suggestion is either learn how to detect what causes it and how to fix it, or make the code not go in and out of <?php ?> so much, which would make it easier to see the code and where it might be going wrong... Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 which is the best way to use html with php? is it to break up the php sections so that i have lots of open and closing section? or use echo to display the pieces i want? but yeah i do understand what the syntax errors mean and how to fix them now. thats the great thing about this forum. i learn from the pros. thanks again Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 I prefer to echo, some other people prefer to open and close. But if you want to be real technical I actually do not echo =) I store all the data I want displayed in a variable of $output and than at the very end of the script I echo that one variable. That way I have full control of the data and no surprises happen. Quote Link to comment Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 ive thought about doing that but i havent tested it yet actually. thanks for the tip. i will have to try it out. Quote Link to comment 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.