Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-284857
Share on other sites

		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

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-284869
Share on other sites

		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

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-284876
Share on other sites

		<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.

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-284885
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-284886
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-284891
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-285268
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/57558-solved-switch-error/#findComment-285271
Share on other sites

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.