Jump to content

Update


garyit

Recommended Posts

Dear all Friends,

 

I have already cracked my head..

I have tried many times in order to update the existing record in my database, but it didn't works.

 

My php script basically got 3 pages.

 

First Page: which is display the general info of record when user click on update. (*Every row got an update img button)

 

Second Page: which is to display details information for particular row of record they selected, and allow them to edit the information as well at this page. When they click on the update button it then will execute THIRD PAGE.

 

Third Page: This page will be execute mssql query.

 

First Page Name: Updaterec.php

Second Page Name: updatedetails.php

Third Page name: testupdatedetails.php

 

Thanks in advance and very appreciate for help!!!

 

First Page Code Start:

 

<?php

header("Expires: Sun, 4 May 2008 10:11:11 GMT");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("Cache-Control: no-cache, must-revalidate");

header("Pragma: no-cache");

 

session_start();

 

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<!-- Creation Date: <?=Date("d/m/Y")?> -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Generator" content="Dev-PHP 1.9.4">

<title>Regent Kuala Lumpur - Guest Service Log:Delete  Record</title>

</head>

 

<style type="text/css">

<!--

#Layer1 {

position:absolute;

width:125px;

height:27px;

z-:1;

left: 135px;

top: 191px;

}

.style1 {

color: #999999;

font-family: "Times New Roman", Times, serif;

font-size: 24px;

font-style: italic;

font-weight: bold;

}

.style2 {

color: #000000;

font-family: "Times New Roman", Times, serif;

font-size: 12px;

font-weight: bold;

}

-->

</style>

 

<body>

<?php

if(session_is_registered('user_name'))

{

  echo '<blockquote><p align="center"><img src="img/TopBanner02.jpg" width="1024" height="100" />

  <p></p>

 

  <table width="200" border="0" align="center">

    <tr>

      <td><a href="newrec.php"><img src="img/addnewbtn.jpg" width="146" height="38" border="0" /></a></td>

      <td><a href="delrec.php"><img src="img/deletebtn.jpg" width="146" height="39" border="0" /></a></td>

      <td><img src="img/updatebtn.jpg" width="146" height="39" /></td>

      <td><a href="searchrec.php"><img src="img/searchbtn.jpg" width="146" height="39" border="0" /></a></td>

    </tr>

  </table>

 

  <p align="center" class="style1"><u>Delete Record</u></br>

  <p></p></blockquote>';

 

define ('DB_USER', '');

define ('DB_PASSWORD', '');

define ('DB_HOST', 'localhost');

define ('DB_NAME', 'regent');

 

    $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not

connect to MySQL: ' . mysql_error() );

mysql_select_db (DB_NAME) OR die ('Could not select database: ' .

mysql_error() );

 

$result = mysql_query("SELECT * FROM guest order by record_id desc");

 

echo "<table width='963' border='1' cellpadding='0' align='center' bgcolor='FFFFCC' bordercolor='808080' style='border-collapse: collapse'>

    <tr>

 

      <td width='80'><div align='center' class='style2'>Record ID </div></td>

      <td width='80'><div align='center' class='style2'>Guest room </div></td>

      <td width='145'><div align='center' class='style2'>Date</div></td>

      <td width='135'><div align='center' class='style2'>Time</div></td>

      <td width='90'><div align='center' class='style2'>Follow up </div></td>

      <td width='100'><div align='center' class='style2'>Assigned to </div></td>

      <td width='145'><div align='center' class='style2'>Date resolved </div></td>

      <td width='55'><div align='center' class='style2'>Update</div></td>

      <td width='55'><div align='center' class='style2'>Delete</div></td>

    </tr>";

 

while($row = mysql_fetch_array($result))

  {

 

    //getting each variable from the table

    $record_id = $row['record_id'];

    $self = $_SERVER['PHP_SELF'];

 

  echo "<tr>";

      echo "<td><div align='center'>" . $row['record_id'] . "</div></td>";

      echo "<td><div align='center'>" . $row['guest_room'] . "</div></td>";

      echo "<td><div align='center'>" . $row['date'] ."</div></td>";

      echo "<td><div align='center'>" . $row['time'] ,  $row['ampm'] ."</div></td>";

      echo "<td><div align='center'>" . $row['follow_up'] ."</div></td>";

      echo "<td><div align='center'>" . $row['assigned_to'] ."</div></td>";

      echo "<td><div align='center'>" . $row['date_resolved'] ."</td>";

      echo "<td><div align='center'><a href='http://localhost/phpadmin/updatedetails.php?record_id=$record_id'><image src='img/Update.jpg' width='25' height='25' border='0'></a></div></td>";

      echo "<td><div align='center'><a href='$self?record_id=$record_id'><image src='img/Delete.jpg' width='25' height='25' border='0'></div></td>";

  echo "</tr>";

  }echo "</table>";

  }

 

  else

{

echo '<blockquote><p align="center">Your login session is expired.</br>Please <a href="gsl.htm">LOGIN</a> again</p></blockquote>';

}

 

if(isset ($_GET['record_id']))

  {

    $record_id = $_GET['record_id'];

    // --------- here code to connect to mysql and select database -----------

 

    $query= mysql_query("Delete FROM guest WHERE record_id =$record_id")or die(mysql_error());

 

  }

 

 

  /*************************************************************************

  alert box popup confimation message function

  *************************************************************************/

  function confirm($msg)

  {

    echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";

  }//end function

 

?>

</form>

</body>

</html>

 

Second Page code start:

<?php

header("Expires: Sun, 4 May 2008 10:11:11 GMT");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("Cache-Control: no-cache, must-revalidate");

header("Pragma: no-cache");

 

session_start();

 

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<!-- Creation Date: <?=Date("d/m/Y")?> -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Generator" content="Dev-PHP 1.9.4">

<title>Regent Kuala Lumpur - Guest Service Log:View Record Details</title>

 

<style type="text/css">

<!--

#Layer1 {

position:absolute;

width:125px;

height:27px;

z-:1;

left: 135px;

top: 191px;

}

.style1 {

color: #999999;

font-family: "Times New Roman", Times, serif;

font-size: 24px;

font-style: italic;

font-weight: bold;

}

-->

</style>

</head>

<body>

//<form id="update" name="update" method="POST" action="testupdatedetails.php">

<?php

if(session_is_registered('user_name'))

{

  echo '<blockquote><p align="center"><img src="img/TopBanner02.jpg" width="1024" height="100" />

  <p></p>

 

  <table width="200" border="0" align="center">

    <tr>

      <td><a href="newrec.php"><img src="img/addnewbtn.jpg" width="146" height="38" border="0" /></a></td>

      <td><a href="delrec.php"><img src="img/deletebtn.jpg" width="146" height="39" border="0" /></a></td>

      <td><a href="updaterec.php"><img src="img/updatebtn.jpg" width="146" height="39" border="0" /></a></td>

      <td><a href="searchrec.php"><img src="img/searchbtn.jpg" width="146" height="39" border="0" /></a></td>

    </tr>

  </table>

 

 

 

  <p align="center" class="style1"><u>Records Detail</u>

  <p></p></blockquote>';

 

 

  define ('DB_USER', '');

define ('DB_PASSWORD', '');

define ('DB_HOST', 'localhost');

define ('DB_NAME', 'regent');

 

    $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not

connect to MySQL: ' . mysql_error() );

mysql_select_db (DB_NAME) OR die ('Could not select database: ' .

mysql_error() );

 

    $result = mysql_query("SELECT * FROM guest WHERE record_id=$record_id");

 

 

  while($row = mysql_fetch_array($result))

  {

 

    echo "<table width='61.5%' height='496' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#808080' bgcolor='#FFFFCC' id='AutoNumber1' style='border-collapse: collapse'>

    <tr>

      <td width='17%' height='33'><div align='center'><font size='2'><b>Guest room #:</b></font>

      </div></td>

      <td width='83%' height='33' align='left'>  

          <input name='guest_room' type='text' size='4' value=". $row['guest_room'] ." maxlength='4' tab='1' />

    </tr>";

 

    echo "

    <tr>

      <td width='17%' height='34'><div align='center'><b><font size='2'>Date: </font> </b></div></td>

      <td width='83%' height='34'>

        <div align='left'>  

          <input name='date' type='text' id='date' size='10' value=" . $row['date'] ."  >

    </tr>";

 

    echo "

    <tr>

      <td width='17%' height='36'><div align='center'><b><font size='2'>Time: </font> </b></div></td>

      <td width='83%' height='36'><div align='left'>  

        <input name='time' type='text' id='time' value=" . $row['time'] ,  $row['ampm'] ." size='10'>

         </div></td>

    </tr>";

 

    echo "

    <tr>

      <td width='17%' height='141'><div align='center'><b><font size='2'>Issue:  </font></b></div></td>

      <td width='83%' height='141'>  

          <textarea name='issue' cols='55' rows='8' tab='8'>". $row['issue'] ."</textarea>

      </td>

    </tr>";

 

    echo "

    <tr>

      <td width='17%' height='142'><div align='center'><b><font size='2'>Remark:   </font></b></div></td>

      <td width='83%' height='142'>  

          <textarea name='remark' cols='55' rows='8' tab='9'>". $row['remark'] ."</textarea>

      </td>

    </tr> ";

 

    echo "

    <tr>

      <td width='17%' height='38'><div align='center'><b><font size='2'>Follow up:</font></b></div></td>

      <td width='83%' height='38'>  

      <input name='follow_up' type='text' id='follow_up' value=". $row['follow_up'] ." size='4'></td>

    </tr>";

 

    echo"

    <tr>

      <td height='35'><div align='center'><b><font size='2'>Assigned to:</font></b></div></td>

      <td height='35' colspan='2'>   <input name='assigned_to' type='text' id='assigned_to' value=". $row['assigned_to'] ." size='15' tab='11' /></td>

    </tr>";

 

    echo"

    <tr>

      <td height='35'><div align='center'><b><font size='2'>Date Resolved:</font></b></div></td>

      <td height='35' colspan='2'>  

        <input name='date_resolved' type='text' id='date_resolved' size='10' value=". $row['date_resolved'] ." >

      </td>

    </tr>";

    echo "<p></p><p></p>";

  echo "</table>";

  echo '<a href="testupdatedetails.php?id='.$row['record_id'].'">Update</a>';

  }

  mysql_close();

  }

 

 

?>

<p></p>

<p></p>

//</form>

</body>

</html>

 

Third Page Code Start:

<html>

<body>

<?php

 

    define ('DB_USER', '');

define ('DB_PASSWORD', '');

define ('DB_HOST', 'localhost');

define ('DB_NAME', 'regent');

 

//Make connection and then select database

$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not

connect to MySQL: ' . mysql_error() );

mysql_select_db (DB_NAME) OR die ('Could not select database: ' .

mysql_error() );

 

// only validate form when form is submitted

if($_POST['update'])

{

//Database access information

  $record_id = $_POST['record_id'];

$guest_room = $_POST['guest_room'];

$date = $_POST['date'];

    $time = $_POST['time'];

    //$ampm = $_POST['ampm'];

    $issue = $_POST['issue'];

    $remark = $_POST['remark'];

    $follow_up = $_POST['follow_up'];

    $assigned_to = $_POST['assigned_to'];

    $date_resolved = $_POST['date_resolved'];

 

// mysql_query("update guest set guest_room='$guest_room' where record_id='$record_id'");

 

//if($record_id && $guest_room && $date && $time && $issue && $remark && $follow_up && $assigned_to && $date_resolved)

//{

$query = "UPDATE guest SET guest_room='$guest_room' WHERE record_id='$record_id'";

 

  $result = @mysql_query ($query);

exit;

    }

    mysql_close();

 

 

 

 

?>

<p align="center"><a href="http://localhost/phpadmin/updaterec.php"><input type="button" value="OK" name="ok"></a></p>

</body>

 

</html>

 

---END---

 

Thank You EVery Much my dear helper!!

Link to comment
https://forums.phpfreaks.com/topic/37889-update/
Share on other sites

dear friend,

 

I have tried as what you mentioned, to change the code.

 

this is the error msg return after i changed the code.

 

Parse error: parse error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\phpadmin\testupdatedetails.php on line 37

 

which is the line i changed

from: $result = @mysql_query ($query);

to: $result = mysql_query($query) or die("Error: mysql_error(). " with query ". $query)

 

Thank You.

Link to comment
https://forums.phpfreaks.com/topic/37889-update/#findComment-181775
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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