Jump to content

I have a little problem in my UPDATE program.. please help...


tsuoshiro

Recommended Posts

Hello, i have a problem in my UPDATE program... At first it runs smoothly, when i will update it, there is a Parse error or "Parse error: parse error in C:\wamp\www\update ~orig~\update_student_process2.php on line 61" . Please, i really need your help. These are the the codes..

 

filename: update.php

<form action='update_student_process.php' method='post'>
      <tbody>
        <tr>
          <td height="2" colspan="6" align="left" bgcolor="#FFFFFF"> </td>
        </tr>
        <tr>
          <td width="111" bgcolor="#FFFFFF"><pan class="style10">Student_Number</span></td>
            <input name="student_number" maxlength="7" size="10" type="text" id="student_number" />
          </font></td>
    <td width="56"><input type="submit" name="Submit" id="button" value="Submit" /></td>
    <td width="56"><input type="reset" name="Reset" id="button" value="Reset" /></td>
   
      </tr>
    </table>
    </form>

 

filename: update_student_process.PHP

<?php
                   $connection = mysql_connect("localhost", "root","change");
                    if (!$connection)
                    {die("Database Connection failed!". mysql_error());}
                    $db_select = mysql_select_db("cpedb",$connection);

                    if(!$db_select)
                    {die("Database Connection failed!". mysql_error());}
?>
<?php
$student_number;
$student_number=$_POST['student_number'];
//Perform database query
if($student_number=$_POST['student_number'])
{
$result=mysql_query("SELECT * FROM student Where student_number ='$student_number' ",$connection);

if(!$result)
{
die("Database Connection failed!". mysql_error());
}
echo "<table border=0>";
$row=mysql_fetch_array($result);

	echo ("<form name='frm_details' action='update_student_process2.php' method='post'>");
	echo ("<input type='hidden' name='action' value='update'>");
	echo ("Student Number : <input type='text'   name='student_number' readonly value='".$row["student_number"]."'><br>");
	echo ("Last Name :   <input type='text'   name='last_name' readonly value='".$row["last_name"]."'><br>");
	echo ("First Name :  <input type='text'   name='first_name' readonly value='".$row["first_name"]."'><br>");
	echo ("Middle Name :  <input type='text'   name='middle_name' readonly value='".$row["middle_name"]."'><br>");
	echo ("Year Level:  <input type='text'   name='year_level' value='".$row["year_level"]."'><br>");
	echo ("Gender :  <input type='text'   name='gender' readonly value='".$row["gender"]."'><br>");
	echo ("Birthday :  <input type='text'   name='birthday_month'  readonly value='".$row["birthday_month"]."'>");
	echo ("<input type='text'   name='birthday_day'  readonly value='".$row["birthday_day"]."'>");
	echo ("<input type='text'   name='birthday_year'  readonly value='".$row["birthday_year"]."'><br>");
	echo ("Age:  <input type='text'   name='age' value='".$row["age"]."'><br>");
	echo ("Email :  <input type='text'   name='email' value='".$row["email"]."'><br>");
	echo ("Student PhoneNumber :  <input type='text'   name='student_phone_number' value='".$row["student_phone_number"]."'><br>");
	echo ("Student CellphoneNumber :  <input type='text'   name='student_cellphone_number' value='".$row["student_cellphone_number"]."'><br>");
	echo ("Student Address :  <input type='text' name='student_address' value='".$row["student_address"]."'><br>");
	echo ("Student ProvincialAddress :  <input type='text'   name='student_provincial_address' value='".$row["student_provincial_address"]."'><br>");
	echo ("Citizenship :  <input type='text'   name='citizenship' value='".$row["citizenship"]."'><br>");
	echo ("Civil Status:  <input type='text'   name='civil_status' value='".$row["civil_status"]."'><br>");
	echo ("Religion :  <input type='text'   name='religion' value='".$row["religion"]."'><br>");
	echo ("Mother Name :  <input type='text'   name='mother_name' value='".$row["mother_name"]."'><br>");
	echo ("Mother Occupation :  <input type='text'   name='mother_occupation' value='".$row["mother_occupation"]."'><br>");
	echo ("Father Name :  <input type='text'   name='father_name' value='".$row["father_name"]."'><br>");
	echo ("Father Occupation :  <input type='text'   name='father_occupation' value='".$row["father_occupation"]."'><br>");
	echo ("Guardian Name :  <input type='text'   name='guardian_name' value='".$row["guardian_name"]."'><br>");
	echo ("Guardian Relationship :  <input type='text'   name='guardian_relationship' value='".$row["guardian_relationship"]."'><br>");
	echo ("Guardian ContactNumber :  <input type='text'   name='guardian_contact_number' value='".$row["guardian_contact_number"]."'><br>");
	echo ("Guardian Address :  <input type='text'   name='guardian_address' value='".$row["guardian_address"]."'><br>");
	echo ("<input type='submit' name='f_submit' value='Update'>");
	echo ("</form>");
}


?>
<?php
//Closing database
mysql_close($connection);
?>

 

 

FILENAME: update_student_process2 ~this is where the error detected.. i dont know why there is a problem in the student number?? please help...

this is the error again.... Parse error: parse error in C:\wamp\www\update ~orig~\update_student_process2.php on line 61

 

<?php
                   $connection = mysql_connect("localhost", "root","change");
                    if (!$connection)
                    {die("Database Connection failed!". mysql_error());}
                    $db_select = mysql_select_db("cpedb",$connection);

                    if(!$db_select)
                    {die("Database Connection failed!". mysql_error());}
?>

<?php

        $last_name=$_POST['last_name'];
    	$first_name=$_POST['first_name'];
$middle_name=$_POST['middle_name'];
$year_level=$_POST['year_level'];
$gender=$_POST['gender'];
$age=$_POST['age'];
$email=$_POST['email'];
$student_phone_number=$_POST['student_phone_number'];
$student_cellphone_number=$_POST['student_cellphone_number'];
$student_address=$_POST['student_address'];
$student_provincial_address=$_POST['student_provincial_address'];
$citizenship=$_POST['citizenship'];
$civil_status=$_POST['civil_status'];
$religion=$_POST['religion'];
$mother_name=$_POST['mother_name'];
$mother_occupation=$_POST['mother_occupation'];
$father_name=$_POST['father_name'];
$father_occupation=$_POST['father_occupation'];
$guardian_name=$_POST['guardian_name'];
$guardian_relationship=$_POST['guardian_relationship'];
$guardian_contact_number=$_POST['guardian_contact_number'];
$guardian_address=$_POST['guardian_address'];
$student_number=$_POST['student_number'];
if (mysql_affected_rows()>0)
        {
$result=mysql_query("UPDATE student set " .
		" last_name = '$last_name'," .
		" middle_name = '$middle_name'," .
		" first_name = '$first_name'," .
		" year_level= '$year_level'," .
		" gender= '$gender'," .
		" age= '$age'," .
		" email= '$email'," .
		" student_phone_number= '$student_phone_number'," .
		" student_cellphone_number= '$student_cellphone_number'," .
		" student_address= '$student_address'," .
		" student_provincial_address= '$student_provincial_address'," .
		" citizenship= '$citizenship'," .
		" civil_status= '$civil_status'," .
		" religion= '$religion'," .
		" mother_name= '$mother_name'," .
		" mother_occupation= '$mother_occupation'," .
		" father_name= '$father_name'," .
		" father_occupation= '$father_occupation'," .
		" guardian_name= '$guardian_name'," .
		" guardian_relationship='$guardian_relationship'," .
		" guardian_contact_number= '$guardian_contact_number'," .
		" guardian_address= '$guardian_address'".
		" WHERE student_number='$student_number'";
                        )

if (mysql_affected_rows()>0)
{
echo "Record is updated";
}
else {
echo ("Unable to update record");
     }
                
}


?>
<?php
//Closing database
mysql_close($connection);
?>

 

 

hope that you can help me. its my project for software subject... i just cant figure it out... thanks in advance ^_^

 

Link to comment
Share on other sites

thanks for replying... after i remove the ";" another error occur "

Parse error: parse error in C:\wamp\www\update ~orig~\update_student_process2.php on line 64" same filename.....  i will show you the first program i made..

 

this is the first program i made, i separate it into 3 parts to make it easier ~i am doing a login system, w/ edit, delete, create a user, search a user and update.. i am halfway done but im stuck in the UPDATE part -_-.. hope you can help me again... anyway this is the first program..

 

<?php

class Database
{
var $config=Array();
var $link="";

function getConfig()
{
	$config['dbhost']="localhost";
	$config['dbuser']="root";
	$config['dbpass']="change";
	$config['dbname']="cpedb";

	return $config;
}

function openDB()
{

	$mydb=Database::getConfig();
	// Connect to the database
	$link = mysql_connect($mydb['dbhost'], $mydb['dbuser'], $mydb['dbpass'])
		or die("Unable to connect to database");
	mysql_select_db($mydb['dbname'],$link);

	return ($link);	
}

function setQuery($sql)
{
	return mysql_query($sql);
}

}

function showSearch()
{

echo ("<form name='frm_search' action='updateupdatelive.php' method='post'>");
echo ("<input type='hidden' name='action' value='detail'>");
echo ("Student Number : <input type='text' name='student_number'><br>");
echo ("<input type='submit' name='f_submit' value='Search'>");
echo ("<input type='reset' name='f_submit' value='Reset'>");
echo ("</form>");
}

function showRecord()
{

if (!$link=Database::openDB()){
	exit("Unable to connect to the database");
}

$sql="select * from student where student_number='".$_POST['student_number']."'";
$result=Database::setQuery($sql);

$row=mysql_fetch_array($result);

if (mysql_affected_rows()>0){

	echo ("<form name='frm_details' action='updateupdatelive.php' method='post'>");
	echo ("<input type='hidden' name='action' value='update'>");
	echo ("Student Number : <input type='int'   name='student_number' readonly value='".$row["student_number"]."'><br>");
	echo ("Last Name :   <input type='varchar'   name='last_name' readonly value='".$row["last_name"]."'><br>");
	echo ("First Name :  <input type='varchar'   name='first_name' readonly value='".$row["first_name"]."'><br>");
	echo ("Middle Name :  <input type='varchar'   name='middle_name' readonly value='".$row["middle_name"]."' ><br>");
	echo ("Year Level:  <input type='varchar'   name='year_level' value='".$row["year_level"]."'><br>");
	echo ("Gender :  <input type='text'   name='gender' readonly value='".$row["gender"]."'><br>");
	echo ("Birthday :  <input type='text'   name='birthday_month'  readonly value='".$row["birthday_month"]."'>");
	echo ("<input type='int'   name='birthday_date'   readonly value='".$row["birthday_day"]."'>");
	echo ("<input type='int'   name='birthday_year'   readonly value='".$row["birthday_year"]."'><br>");
	echo ("Age:  <input type='int'   name='age' value='".$row["age"]."'><br>");
	echo ("Email :  <input type='text'   name='email' value='".$row["email"]."'><br>");
	echo ("Student PhoneNumber :  <input type='int'   name='student_phone_number' value='".$row["student_phone_number"]."'><br>");
	echo ("Student CellphoneNumber :  <input type='int'   name='student_cellphone_number' value='".$row["student_cellphone_number"]."'><br>");
	echo ("Student Address :  <input type='varchar' name='student_address' value='".$row["student_address"]."'><br>");
	echo ("Student ProvincialAddress :  <input type='varchar'   name='student_provincial_address' value='".$row["student_provincial_address"]."'><br>");
	echo ("Citizenship :  <input type='text'   name='citizenship' value='".$row["citizenship"]."'><br>");
	echo ("Civil Status:  <input type='text'   name='civil_status'student_phone_number value='".$row["civil_status"]."'><br>");
	echo ("Religion :  <input type='text'   name='religion' value='".$row["religion"]."'><br>");
	echo ("Mother Name :  <input type='text'   name='mother_name' value='".$row["mother_name"]."'><br>");
	echo ("Mother Occupation :  <input type='text'   name='mother_occupation' value='".$row["mother_occupation"]."'><br>");
	echo ("Father Name :  <input type='text'   name='father_name' value='".$row["father_name"]."'><br>");
	echo ("Father Occupation :  <input type='text'   name='father_occupation' value='".$row["father_occupation"]."'><br>");
	echo ("Guardian Name :  <input type='text'   name='guardian_name' value='".$row["guardian_name"]."'><br>");
	echo ("Guardian Relationship :  <input type='text'   name='guardian_relationship' value='".$row["guardian_relationship"]."'><br>");
	echo ("Guardian ContactNumber :  <input type='int'   name='guardian_contact_number' value='".$row["guardian_contact_number"]."'><br>");
	echo ("Guardian Address :  <input type='varchar'   name='guardian_address' value='".$row["guardian_address"]."'><br>");
	echo ("<input type='submit' name='f_submit' value='Update'>");
	echo ("</form>");

}else{

	echo ("No record found");

}

mysql_close($link);

}

function updateRecord()
{
$last_name=$_POST['last_name'];
$first_name=$_POST['first_name'];
$middle_name=$_POST['middle_name'];
$student_number=$_POST['student_number'];
$year_level=$_POST['year_level'];
$gender=$_POST['gender'];
$age=$_POST['age'];
$email=$_POST['email'];
$student_phone_number=$_POST['student_phone_number'];
$student_cellphone_number=$_POST['student_cellphone_number'];
$student_address=$_POST['student_address'];
$student_provincial_address =$_POST['student_provincial_address'];
$citizenship=$_POST['citizenship'];
$civil_status=$_POST['civil_status'];
$religion=$_POST['religion'];
$mother_name=$_POST['mother_name'];
$mother_occupation=$_POST['mother_occupation'];
$father_name=$_POST['father_name'];
$father_occupation=$_POST['father_occupation'];
$guardian_name=$_POST['guardian_name'];
$guardian_relationship=$_POST['guardian_relationship'];
$guardian_contact_number =$_POST['guardian_contact_number'];
$guardian_address=$_POST['guardian_address'];

if (!$link=Database::openDB()){
	exit("Unable to connect to the database");
}

$sql="update student set " .

		" last_name = '$last_name'," .
		" middle_name = '$middle_name'," .
		" first_name = '$first_name'," .
		" year_level= '$year_level'," .
		" age= '$age'," .
		" email= '$email'," .
		" student_phone_number= '$student_phone_number'," .
		" gender= '$gender'," .
		" student_cellphone_number= '$student_cellphone_number'," .
		" student_address= '$student_address'," .
		" student_provincial_address = '$student_provincial_address '," .
		" citizenship= '$citizenship'," .
		" civil_status= '$civil_status'," .
		" religion= '$religion'," .
		" mother_name= '$mother_name'," .
		" mother_occupation= '$mother_occupation'," .
		" father_name= '$father_name'," .
		" father_occupation= '$father_occupation'," .
		" guardian_name= '$guardian_name'," .
		" guardian_relationship='$guardian_relationship'," .
		" guardian_contact_number = '$guardian_contact_number '," .
		" guardian_address= '$guardian_address',".
		" student_number= '$student_number'";

$result=Database::setQuery($sql);

if (mysql_affected_rows()>0){
	echo "Record is updated";
}else {
	echo ("Unable to update record");
}

mysql_close($link);

unset($_POST);

?>


    <?php



}

if (!$_POST){
showSearch();
} elseif ($_POST['action']=='detail'){
showRecord();
} elseif ($_POST['action']=='update'){
updateRecord();
}	

?>

 

this is the program again ~current program where the error occur "

Parse error: parse error in C:\wamp\www\update ~orig~\update_student_process2.php on line 64"

 

<?php
                   $connection = mysql_connect("localhost", "root","change");
                    if (!$connection)
                    {die("Database Connection failed!". mysql_error());}
                    $db_select = mysql_select_db("cpedb",$connection);

                    if(!$db_select)
                    {die("Database Connection failed!". mysql_error());}
?>

<?php

        $last_name=$_POST['last_name'];
    	$first_name=$_POST['first_name'];
$middle_name=$_POST['middle_name'];
$year_level=$_POST['year_level'];
$gender=$_POST['gender'];
$age=$_POST['age'];
$email=$_POST['email'];
$student_phone_number=$_POST['student_phone_number'];
$student_cellphone_number=$_POST['student_cellphone_number'];
$student_address=$_POST['student_address'];
$student_provincial_address=$_POST['student_provincial_address'];
$citizenship=$_POST['citizenship'];
$civil_status=$_POST['civil_status'];
$religion=$_POST['religion'];
$mother_name=$_POST['mother_name'];
$mother_occupation=$_POST['mother_occupation'];
$father_name=$_POST['father_name'];
$father_occupation=$_POST['father_occupation'];
$guardian_name=$_POST['guardian_name'];
$guardian_relationship=$_POST['guardian_relationship'];
$guardian_contact_number=$_POST['guardian_contact_number'];
$guardian_address=$_POST['guardian_address'];
$student_number=$_POST['student_number'];
if (mysql_affected_rows()>0)
        {
$result=mysql_query("UPDATE student set " .
		" last_name = '$last_name'," .
		" middle_name = '$middle_name'," .
		" first_name = '$first_name'," .
		" year_level= '$year_level'," .
		" gender= '$gender'," .
		" age= '$age'," .
		" email= '$email'," .
		" student_phone_number= '$student_phone_number'," .
		" student_cellphone_number= '$student_cellphone_number'," .
		" student_address= '$student_address'," .
		" student_provincial_address= '$student_provincial_address'," .
		" citizenship= '$citizenship'," .
		" civil_status= '$civil_status'," .
		" religion= '$religion'," .
		" mother_name= '$mother_name'," .
		" mother_occupation= '$mother_occupation'," .
		" father_name= '$father_name'," .
		" father_occupation= '$father_occupation'," .
		" guardian_name= '$guardian_name'," .
		" guardian_relationship='$guardian_relationship'," .
		" guardian_contact_number= '$guardian_contact_number'," .
		" guardian_address= '$guardian_address'".
		" WHERE student_number='$student_number'"
                        )

if (mysql_affected_rows()>0)
{
echo "Record is updated";
}
else {
echo ("Unable to update record");
     }
                
}


?>
<?php
//Closing database
mysql_close($connection);
?>

 

do i need to edit it all or it can be fix by changing some codes in this part if the program??? thanks in advance... hope you can help me again ^_^

 

Link to comment
Share on other sites

Thanks :D!! No errors after that code... unfortunately... it doesnt UPDATE  :'(... I just want to ask if the if

(mysql_affected_rows()>0)
{
echo "Record is updated";
}
else {
echo ("Unable to update record");
     }
                
}

 

will be the one who will confirm if an update occur?

 

and also.. why does it not update.... is there something wrong with the codes or it is not connected it the database thats why it doesnt update??

 

sorry for asking so many questions... i really need your help... hope you help me again.. thanks in advance ^_^

Link to comment
Share on other sites

This would be a good way to check if an update occurred or not. Since you have no PHP error, it seems you query is not good.

Echo the query you try to run (do not write it yourself, it is important you echo it) just before the call to mysql, and see why it does not update anything.

Link to comment
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.