Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

What I'm I doing wrong

php code parse error syntax error

Best Answer hard1010lad, 22 May 2014 - 05:15 PM

I finally figured a way about it. I divided the task into two files (edit.php and modify.php) and it worked. Look below:

 

EDIT.PHP

---------------

<?php
	require_once('home_header.php');
	@include 'connection.php';
?>
<html>
<head>
<meta name="description" content="Edit Student Record"/>
<title>Edit Student Record</title>
</head>
<body>
<span class="menuitem"><a href="admin_home.php">| &nbsp; 

Admin Home</a></span>
<br><br><br><br><br>
<?php
$id=$_GET["id"];
$order = "SELECT * FROM students where id='$id'";
	      $result = mysql_query($order);
	      $row = mysql_fetch_array($result);
	      ?>
<form name="update" method="post" action="modify.php">
	<input type="hidden" name="id" value="<?php echo $row[0];?>">
	<table style="border:1px solid silver" cellpadding="5px" cellspacing="0px"
	align-"center" border="0"><tr>
	<td colspan="4"style="background:#0066ff; color:$ffffff; font-size
	:20px">ADD STUDENT RECORD</td>
	</tr><tr>
	<td>Matric Number</td>
	<td><input type="text"name="matric" size="20"value="<?php echo $row[10];?>"></td>
	<td>Department</td><td><input type="text" name="department" size="20" value="<?php echo $row[13];?>"></td>
	<td>Level</td><td><input type="text" name="stlevel" size="20" value="<?php echo $row[12];?>"></td>
	<td>Session</td><td><input type="text" name="session" size="20" value="<?php echo $row[11];?>"></td>
	</tr>
	<tr><td>Surname</td>
	<td><input type="text" name="sname"size="20" value="<?php echo $row[1];?>"></td>
	<td>First Name</td><td><input type="text" name="fname"size="20" 
	value="<?php echo $row[2];?>"></td>
	<td>Middle Name</td>
	<td><input type="text" name="mname"size="20" value="<?php echo $row[3];?>"></td>
	</tr>
	<tr>
	<td>Gender</td>
	<td><input type="radio" name="gender" value="Male" checked="checked">
	Male<input type="radio" name="gender"value="Female">
	Female</td><td>State of Origin</td>
	<td><input type="text" name="state" size="20" value="<?php echo $row[7];?>"></td>
	<td>L.G.A</td>
	<td><input type="text" name="lga" size="20" value="<?php echo $row[8];?>"></td>
	<td>Address</td>
	<td><input type="text" name="address" size="20" value="<?php echo $row[6];?>"></td>
	</tr>
	<tr>
	<td>Telephone</td><td><input type="text" name="phone" size="20" value="<?php echo $row[9];?>"></td>
	<td>Email</td>
	<td><input type="text" name="email" size="20" value="<?php echo $row[15];?>"></td>
	<td>Date Of Birth</td>
	<td><input type="text" name="dob" size="20" value="<?php echo $row[4];?>"></td>
	</tr>
	<tr>
	<td colspan="4" align="center"><input type="hidden" name="do" value=1>
	<input type="submit" value="UPDATE RECORD"></td></tr>
	</table>
	</form>
	</body>
	</html>

=========================

AND HERE IS modify.php.

------------------------------------

<?php
require_once('home_header.php');
@include 'connection.php';
if($_POST["do"]>0);{
	$id2=$_POST["id"];
	$matric=$_POST["matric"];
	$sname=$_POST["sname"];
	$fname=$_POST["fname"];
	$mname=$_POST["mname"];
	$dept=$_POST["department"];
	$asession=$_POST["session"];
	$stateorigin=$_POST["state"];
	$lga=$_POST["lga"];
	$straddress=$_POST["address"];
	$phone=$_POST["phone"];
	$dob=$_POST["dob"];
	$email=$_POST["email"];
	$gender=$_POST["gender"];
	$stlevel=$_POST["stlevel"];
	$query="UPDATE students SET
	st_sname='$sname', st_fname='$fname', st_mname='$mname',
	st_matric='$matric', department='$dept', level='$stlevel', st_session='$asession',
	st_stateorigin='$stateorigin', st_lga='$lga', st_address='$straddress',
	st_telephone='$phone', st_dob='$dob', email='$email', st_gender='$gender'
	WHERE id='$id2'";
	mysql_query($query);
	echo "<br/><br/><br/><br/><br/><center class='confirmation'><h2>Record Successfully Updated in Database</h2></center>";
	echo "<center><h3><a href='find.php'>Return to Search</a></h3></center>";
}
?>

Though it gave me some real troubles especially seeing that I have actually been suffering from my version of php (5.4). with this version, I had some problem with <? ?> tag, it's not working until I change to <?php ?>. I don't know why it's so but only guessed it's the version of php I'm working with.

 

Thanks blackrabbit for taking your time to respond. :thumbup1:

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 hard1010lad

hard1010lad

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 19 May 2014 - 01:51 PM

Hello, thanks for stopping by to check my question.  I'm I'm currently working on a class assigment where we were asked to develop a student management system.

I am currently having some problem with the file handling the "edit student" function. View the code below and help check what I am doing wrong:

The file name is edit.php

<?php
	require_once('home_header.php');
	@include 'connection.php';
?>
<html>
<head>
<meta name="description" content="Edit Student Record"/>
<title>Edit Student Record</title>
</head>
<body>
<span class="menuitem"><a href="admin_home.php">| &nbsp; Admin Home</a></span>
<br><br><br><br><br>
<?php
if($_POST["do"]=="update")
{
	$matric=$_POST["matric"];
	$sname=$_POST["sname"];
	$fname=$_POST["fname"];
	$mname=$_POST["mname"];
	$dept=$_POST["department"];
	$asession=$_POST["session"];
	$stateorigin=$_POST["state"];
	$lga=$_POST["lga"];
	$straddress=$_POST["address"];
	$phone=$_POST["phone"];
	$dob=$_POST["dob"];
	$email=$_POST["email"];
	$gender=$_POST["gender"];
	$stlevel=$_POST["stlevel"];
	$query="UPDATE students SET
	st_sname='$sname', st_fname='$fname', st_mname='$mname',
	st_matric='$matric', department='$dept', level='$stlevel', st_session='$asession',
	st_stateorigin='$stateorigin', st_lga='$lga', st_address='$straddress',
	st_telephone='$phone', st_dob='$dob', email='$email', st_gender='$gender'
	WHERE st_matric=$matric";
	mysql_query($query);
		echo "<center>Successfully Updated in DATABASE</center>";
		include("search_student.php");
}
?>
<?
$id=$_GET["id"];
$query= "SELECT * FROM students WHERE id='$id'";
$result=mysql_query($query);
while($id = mysql_fetch_array($result)){
?> 
<form name="update" method="post" action="edit.php">
	<table style="border:1px solid silver" cellpadding="5px" cellspacing="0px"
	align-"center" border="0">
	<tr>
	<td colspan="4"style="background:#0066ff; color:$ffffff; font-size
	:20px">ADD STUDENT RECORD</td>
	</tr>
	<tr>
	<td>Matric Number</td>
	<td><?echo $row[10];?>
	<input type="hidden"name="matric" size="20"value="<?echo $row[10];?>"></td>
	<td>Department</td>
	<td><input type="text" name="department" size="20" value="<?echo $row[13];?>"></td>
	<td>Level</td>
	<td><input type="text" name="stlevel" size="20" value="<?echo $row[12];?>"></td>
	<td>Session</td>
	<td><input type="text" name="session" size="20" value="<?echo $row[11];?>"></td>
	</tr>
	<tr>
	<td>Surname</td>
	<td><input type="text" name="sname"size="20" value="<?echo $row[1];?>"></td>
	<td>First Name</td>
	<td><input type="text" name="fname"size="20" value="<?echo $row[2];?>"></td>
	<td>Middle Name</td>
	<td><input type="text" name="mname"size="20" value="<?echo $row[3];?>"></td>
	</tr>
	<tr>
	<td>Gender</td>
	<td><input type="radio" name="gender" value="Male" checked="checked">
	Male
	<input type="radio" name="gender"value="Female">
	Female</td>
	<td>State of Origin</td>
	<td><input type="text" name="state" size="20" value="<?echo $row[7];?>"></td>
	<td>L.G.A</td>
	<td><input type="text" name="lga" size="20" value="<?echo $row[8];?>"></td>
	<td>Address</td>
	<td><input type="text" name="address" size="20" value="<?echo $row[6];?>"></td>
	</tr>
	<tr>
	<td>Telephone</td>
	<td><input type="text" name="phone" size="20" value="<?echo $row[9];?>"></td>
	<td>Email</td>
	<td><input type="text" name="email" size="20" value="<?echo $row[15];?>"></td>
	</tr>
	<tr>
	<td colspan="4" align="center"><input type="hidden" name="do"
	value="update">
	<input type="submit" value="UPDATE RECORD"></td>
	</tr>
	</table>
	</form>
	<?php}?>
	</body>
	</html>

This file is being called from another file named student_search.php which I don't have any problem with. The student_search.php is below if you need it to understand what I want to achieve.

<?php
	require_once('home_header.php');
	@include 'connection.php';
?>
<html>
<head>
<meta name="description" content="Edit Student Record"/>
<title>Edit Student Record</title>
</head>
<body>
<span class="menuitem"><a href="admin_home.php">| &nbsp; Admin Home</a></span>
<br><br><br><br><br>

<form name="search" method="post" action="search_student.php">
<table style="border:1px solid silver" cellpadding="5px" cellspacing="0px" align="center" border="0">
<tr>
<td colspan="3" style="background:#400040; color:#FFFFFF; font-size:20px; width:100%">Search</td></tr>
<tr>
<td>Enter Matric Number</td>
<td><input type="text" name="search" size="40"/></td>
<td><input type="submit" value="Search"/></td>
</tr>
<tr bgcolor="666666"style="color:#FFFFFF">
<td>Matric Number</td><td>Full Name</td><td>Gender</td>
<td>Department</td><td>Session</td><td>Level</td><td>&nbsp;</td>
<?php
$search=$_POST['search'];
$flag=0;
$query="SELECT * FROM students WHERE st_matric LIKE '%$search%'";
$result=mysql_query($query);
/** 0=id 			1=st_sname 	2=st_fname 	3=st_mname 	4=st_dob
 	5=st_gender 	6=st_address 	7=st_stateorigin 
	8=st_lga 	9=st_telephone 	10=st_matric 	11=st_session
 	12=level 	13=department 	14=passport 	15=email	**/			

	while($row = mysql_fetch_array($result)) {
	$flag=1;
	echo "<tr><td>".$row[10]."</td><td><a href='view.php?
	id=".$row[0]."'>".$row[1].", ".$row[2].
	" ".$row[3]."</td><td>".$row[5]."</td><td>".$row[13].
	"</td><td>".$row[11]."</td><td>".$row[12]."</td><td>
	<a href='edit.php?id=".
	$row[0]."'>Edit</a>|<a href='del.php?id=".
	$row[0]."'>Delete</a></td></tr>";
	}
	if($flag==0)
	echo "Record not found";
	?>
<tr>
<td colspan="3">&nbsp;</td></tr>
<tr bgcolor="#CCCCCC">

<tr>
</table>
</form>
</body>
</html>

Thanks.



#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 20 May 2014 - 09:31 PM

Welcome aboard!

 

What would be the error in the first place?



#3 hard1010lad

hard1010lad

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 21 May 2014 - 01:03 PM

It says of a syntax error on line 99.

What I am actually looking to do is to GET id of any student I'm editting from student_search.php and post it into a form through "edit.php" so as to edit that particular student's detail.

 

What I am getting now is that something about the "do" on line 14 at the same time instead of populating the form with with the content of the database, what it shows is the "echo row[10]" instead of showing the actual content of row[10] (which should be a matric number).

 

What I'm looking to do now is to split the edit.php file into two files where one will be used to insert contents into the form, the other will process the 'update' button.

 

Thanks



#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 21 May 2014 - 11:56 PM

Oh, the error said it all :D

 

just get rid of line 99 in edit.php

 

// this one
<?php}?>

 

That was the sintax error



#5 hard1010lad

hard1010lad

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 22 May 2014 - 05:15 PM   Best Answer

I finally figured a way about it. I divided the task into two files (edit.php and modify.php) and it worked. Look below:

 

EDIT.PHP

---------------

<?php
	require_once('home_header.php');
	@include 'connection.php';
?>
<html>
<head>
<meta name="description" content="Edit Student Record"/>
<title>Edit Student Record</title>
</head>
<body>
<span class="menuitem"><a href="admin_home.php">| &nbsp; 

Admin Home</a></span>
<br><br><br><br><br>
<?php
$id=$_GET["id"];
$order = "SELECT * FROM students where id='$id'";
	      $result = mysql_query($order);
	      $row = mysql_fetch_array($result);
	      ?>
<form name="update" method="post" action="modify.php">
	<input type="hidden" name="id" value="<?php echo $row[0];?>">
	<table style="border:1px solid silver" cellpadding="5px" cellspacing="0px"
	align-"center" border="0"><tr>
	<td colspan="4"style="background:#0066ff; color:$ffffff; font-size
	:20px">ADD STUDENT RECORD</td>
	</tr><tr>
	<td>Matric Number</td>
	<td><input type="text"name="matric" size="20"value="<?php echo $row[10];?>"></td>
	<td>Department</td><td><input type="text" name="department" size="20" value="<?php echo $row[13];?>"></td>
	<td>Level</td><td><input type="text" name="stlevel" size="20" value="<?php echo $row[12];?>"></td>
	<td>Session</td><td><input type="text" name="session" size="20" value="<?php echo $row[11];?>"></td>
	</tr>
	<tr><td>Surname</td>
	<td><input type="text" name="sname"size="20" value="<?php echo $row[1];?>"></td>
	<td>First Name</td><td><input type="text" name="fname"size="20" 
	value="<?php echo $row[2];?>"></td>
	<td>Middle Name</td>
	<td><input type="text" name="mname"size="20" value="<?php echo $row[3];?>"></td>
	</tr>
	<tr>
	<td>Gender</td>
	<td><input type="radio" name="gender" value="Male" checked="checked">
	Male<input type="radio" name="gender"value="Female">
	Female</td><td>State of Origin</td>
	<td><input type="text" name="state" size="20" value="<?php echo $row[7];?>"></td>
	<td>L.G.A</td>
	<td><input type="text" name="lga" size="20" value="<?php echo $row[8];?>"></td>
	<td>Address</td>
	<td><input type="text" name="address" size="20" value="<?php echo $row[6];?>"></td>
	</tr>
	<tr>
	<td>Telephone</td><td><input type="text" name="phone" size="20" value="<?php echo $row[9];?>"></td>
	<td>Email</td>
	<td><input type="text" name="email" size="20" value="<?php echo $row[15];?>"></td>
	<td>Date Of Birth</td>
	<td><input type="text" name="dob" size="20" value="<?php echo $row[4];?>"></td>
	</tr>
	<tr>
	<td colspan="4" align="center"><input type="hidden" name="do" value=1>
	<input type="submit" value="UPDATE RECORD"></td></tr>
	</table>
	</form>
	</body>
	</html>

=========================

AND HERE IS modify.php.

------------------------------------

<?php
require_once('home_header.php');
@include 'connection.php';
if($_POST["do"]>0);{
	$id2=$_POST["id"];
	$matric=$_POST["matric"];
	$sname=$_POST["sname"];
	$fname=$_POST["fname"];
	$mname=$_POST["mname"];
	$dept=$_POST["department"];
	$asession=$_POST["session"];
	$stateorigin=$_POST["state"];
	$lga=$_POST["lga"];
	$straddress=$_POST["address"];
	$phone=$_POST["phone"];
	$dob=$_POST["dob"];
	$email=$_POST["email"];
	$gender=$_POST["gender"];
	$stlevel=$_POST["stlevel"];
	$query="UPDATE students SET
	st_sname='$sname', st_fname='$fname', st_mname='$mname',
	st_matric='$matric', department='$dept', level='$stlevel', st_session='$asession',
	st_stateorigin='$stateorigin', st_lga='$lga', st_address='$straddress',
	st_telephone='$phone', st_dob='$dob', email='$email', st_gender='$gender'
	WHERE id='$id2'";
	mysql_query($query);
	echo "<br/><br/><br/><br/><br/><center class='confirmation'><h2>Record Successfully Updated in Database</h2></center>";
	echo "<center><h3><a href='find.php'>Return to Search</a></h3></center>";
}
?>

Though it gave me some real troubles especially seeing that I have actually been suffering from my version of php (5.4). with this version, I had some problem with <? ?> tag, it's not working until I change to <?php ?>. I don't know why it's so but only guessed it's the version of php I'm working with.

 

Thanks blackrabbit for taking your time to respond. :thumbup1:






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download