Jump to content

PHP Edit Information


tpstudent

Recommended Posts

I had created a edit information page for user to edit their information. However, when I edit the information, the header of my php file did not change the information.

 

name.jpg

 

Can anyone help?

 

<?php
session_start();
?>


<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
-->
</style>
<table id="Table_01" width="800" height="136" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td rowspan="3"><a href="main.php"><img src="images/header_01.jpg" alt="" width="337" height="136" border="0" /></a></td>
  <td colspan="3" background="images/header_02.jpg" width="463" height="25">
        <table width="457" border="0">
          <tr>
            <td width="13"></td>
            <td width="434"><div align="right"><span class="header">
              <?php

		//TODO 1: Replace this with session value
		$name =$_SESSION['name'];

		//TODO 2: Display user's login id
		echo "<span class='header'>Logged in as ".$name."  | </span> <a href = 'logout.php'> <span class = 'header'>Logout</span></a>";

		?>
            </span></div>            </td>
          </tr>
      </table>      </td>
  </tr>
<tr>
	<td colspan="3">
		<img src="images/header_03.jpg" width="463" height="84" alt=""></td>
</tr>
<tr>
	<td>
		<img src="images/header_04.jpg" width="339" height="27" alt=""></td>
	<td>
		<a href="editProfile.php"><img src="images/header_05.jpg" alt="" width="58" height="27" border="0"></a></td>
  <td>
		<a href="editStatus.php"><img src="images/header_06.jpg" alt="" width="66" height="27" border="0"></a></td>
  </tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/124594-php-edit-information/
Share on other sites

Hi,

Thanks for replying.

How do you update the session?

 

This is what I did for the update information:

 

<?php 
session_start();
echo $name;
ob_start();
?>

<html>
<head>
<title>Staff Signage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">

<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
-->
</style></head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (main1.psd) -->
<table width="800" height="600" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
	<td width="800" height="136"><?php include("include/header.php") ?></td>
  </tr>
<tr>
  <td width="800" height="438" valign="top" bgcolor="#FFFFFF"><table width="795" height="429" border="0">
        <tr>
          <td width="10" height="5"></td>
          <td width="762"></td>
          <td width="10"></td>
        </tr>
        <tr>
          <td height="409"></td>
          <td valign="top" bgcolor="#FFFFFF">
          <!--HERE-->
          
          <form name="form1" method="post" action="editProfile.php">	
           
            <?php

				$staffid = $_SESSION['staffid'];

				//$staffid = $_GET['staffidid'];
				// read the value of the hidden field & check whether it has been set
				$submitted = isset($_POST['formSubmitted']);

				require_once('staffSql.php');
					// connect to the mysql database server.
				mysql_select_db($dbname); 
				$query = "Select name, email, contactNo, ext, position from staff where staffid = '$staffid'";

				$result = mysql_query($query);	



			$success = FALSE; //success to store value that is false

			// check $submitted and blank fields
			if ($submitted) {					//$image = $_POST['image'];
				// check if $_POST['title'] is empty and strip any slashes if not
				if (!empty($_POST['name'])) {
					$name=$_POST['name'];
				} else {
					$name=NULL;
					echo '<span class= "contentText"><font color="red"><b>You forgot to enter your name.</b></font><br><br><span>';
				}

				// check if $_POST['title'] is empty and strip any slashes if not
				if (!empty($_POST['contactNo'])) {
					$contactNo=$_POST['contactNo'];
				} else {
					$contactNo=NULL;
					echo '<span class= "contentText"><font color="red"><b>You forgot to enter your contact number.</b></font><br><br><span>';
				}

				if (!empty($_POST['email'])) {
					$email=$_POST['email'];
				} else {
					$email=NULL;
					echo '<span class= "contentText"><font color="red"><b>You forgot to enter your email.</b></font><br><br><span>';
				}


				if (!empty($_POST['ext'])) {
					$ext=$_POST['ext'];
				} else {
					$ext=NULL;
					echo '<span class= "contentText"><font color="red"><b>You forgot to enter your extension number.</b></font><br><br><span>';
				}

				if (!empty($_POST['position'])) {
					$position=$_POST['position'];
				} else {
					$position=NULL;
					echo '<span class= "contentText"><font color="red"><b>You forgot to enter your position.</b></font><br><br><span>';
				}

				// if all data entered, display a message


					if ($name && $email && $contactNo && $ext && $position) {
						$success = TRUE;
						$staffid = $_POST['staffid'];

						$name = mysql_real_escape_string($_POST["name"]);
						$email = mysql_real_escape_string($_POST["email"]);
						$contactNo = mysql_real_escape_string($_POST["contactNo"]);
						$ext = mysql_real_escape_string($_POST["ext"]);
						$position = mysql_real_escape_string($_POST["position"]);

						require_once('staffSql.php');

						mysql_select_db($dbname); 					//assign the data passed from Flex to variables

						//Query the database to see if the given username/password combination is valid.
						$query = "UPDATE staff set name='$name', email='$email', contactNo='$contactNo', ext='$ext', position='$position' where staffid='$staffid'";

						$result = mysql_query($query);	

					if($result)

					{



					echo'	 <table width="100%" border="0" cellspacing="3">';
					echo'		<tr>';
					echo'		<span class="headerText">Your information is updated successfully.</span><br/><br/>';
					echo'		  <td width="16%"><span class="text"><b>Name: </b></span></td>';
					echo'		  <td width="84%"><span class="contentText">'.$name.'</span></td>';
					echo'		</tr>';
					echo'		<tr>';
					echo'		  <td><strong><span class="text">Email:</span></strong></td>';
					echo'		  <td><span class="contentText">'.$email.'</span></td>';
					echo'		</tr>';
					echo'		<tr>';
					echo'		  <td><b><span class="text">Contact Number:</span></b></td>';
					echo'		  <td><span class="contentText">'.$contactNo.'</span></td>';
					echo'		</tr>';
					echo'		<tr>';
					echo'		  <td><b><span class="text">Extension Number:</span></b></td>';
					echo'		  <td><span class="contentText">'.$ext.'</span></td>';
					echo'		</tr>';

					echo'		<tr>';
					echo'		  <td><b><span class="text">Postion:</span></b></td>';
					echo'		  <td><span class="contentText">'.$position.'</span></td>';
					echo'		</tr>';

					echo' <tr>';
					echo'         <td colspan="2"><br><span class = "text">Click <a href=main.php>here</a> to go back to main.</span></td>';
					echo' </tr>';
					echo'	 </table>';

					}

					else {
						echo '<p>Message not updated';	
					}
          	}
          }
          ?>
          
          
          <?php if($success==FALSE) { 
	    while ($row = mysql_fetch_array ($result)) {
		$name=$row['name'];
		$contactNo=$row['contactNo'];
		$ext=$row['ext'];
		$position=$row['position'];
		$email=$row['email'];
	  ?>
          
          <table width="100%" border="0" cellspacing="3">
            <tr>
		<span class="headerText">Edit Your Information</span><br/><br/>
              <td width="16%"><span class="text"><b>Name: </b></span></td>
              <td width="84%"><input type="text" name="name" size="40" maxlength="40" value="<?php echo $name;?>"/>              </td>
            </tr>
            <tr>
              <td><strong><span class="text">Email:</span></strong></td>
              <td><input type="text" name="email" size="40" maxlength="40" value="<?php echo $email;?>"/></td>
            </tr>
            <tr>
              <td><b><span class="text">Contact Number:</span></b></td>
              <td><input type="text" name="contactNo" size="40" maxlength="40" value="<?php echo $contactNo;?>"/></td>
            </tr>
            <tr>
              <td><b><span class="text">Extension Number:</span></b></td>
              <td><input type="text" name="ext" size="40" maxlength="40" value="<?php echo $ext;?>"/></td>
            </tr>

            <tr>
              <td><b><span class="text">Postion:</span></b></td>
              <td><input type="text" name="position" size="40" maxlength="40" value="<?php echo $position;?>"/></td>
            </tr>
            <tr>
              <td> </td>
              <td> </td>
            </tr>
          </table>
          <div align="center"><br>
            <!-- TODO insert a hidden field -->
           <!-- <input type="hidden" name="formSubmitted" value="TRUE" />
            <input name="submit" type="submit" onClick="MM_validateForm('email','','NisEmail','contactno','','NisNum');return document.MM_returnValue" value="Register me!" />
            <input type="reset" value="Reset" />-->
            <input type="hidden" name="staffid" value="<?php echo $staffid;?>"/>
		<input type="hidden" name="formSubmitted" value="TRUE" />
		<input type="submit" name="submit" value="Update" onClick="MM_validateForm('email','','NisEmail','contactNo','','NisNum');return document.MM_returnValue"  />
		<input type="reset" name="reset" value="Reset">
            
          </div>
          <?php } }?></form>
          </p></td>
          <td></td>
        </tr>
      </table>      </td>
</tr>
<tr>
	<td width="800" height="26">	<?php include("include/footer.php") ?>		</td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
<?php ob_flush(); ?>

Link to comment
https://forums.phpfreaks.com/topic/124594-php-edit-information/#findComment-643531
Share on other sites

I did that already for the header.php

 

This are the codes:

 <?php

		//TODO 1: Replace this with session value
		$name =$_SESSION['name'];

		//TODO 2: Display user's login id
		echo "<span class='header'>Logged in as ".$name."  | </span> <a href = 'logout.php'> <span class = 'header'>Logout</span></a>";

		?>

 

However, when i edit the information, it does not update the session. I do not know what is the reason.

You can see the below image, the top appear as 'Yam Wai Ho George' but the bottom appear as 'Yam Wai Ho'

It only change when I relogin the a/c again.

 

name.jpg

 

 

Link to comment
https://forums.phpfreaks.com/topic/124594-php-edit-information/#findComment-643610
Share on other sites

mysql_select_db($dbname); 					//assign the data passed from Flex to variables

						//Query the database to see if the given username/password combination is valid.
						$query = "UPDATE staff set name='$name', email='$email', contactNo='$contactNo', ext='$ext', position='$position' where staffid='$staffid'";

$_SESSION['name'] = $name;

						$result = mysql_query($query);	

					if($result)

					{



					echo'	 <table width="100%" border="0" cellspacing="3">';
					echo'		<tr>';
					echo'		<span class="headerText">Your information is updated successfully.</span><br/><br/>';
					echo'		  <td width="16%"><span class="text"><b>Name: </b></span></td>';
					echo'		  <td width="84%"><span class="contentText">'.$name.'</span></td>';
					echo'		</tr>';
					echo'		<tr>';
					echo'		  <td><strong><span class="text">Email:</span></strong></td>';
					echo'		  <td><span class="contentText">'.$email.'</span></td>';
					echo'		</tr>';
					echo'		<tr>';
					echo'		  <td><b><span class="text">Contact Number:</span></b></td>';
					echo'		  <td><span class="contentText">'.$contactNo.'</span></td>';
					echo'		</tr>';
					echo'		<tr>';
					echo'		  <td><b><span class="text">Extension Number:</span></b></td>';
					echo'		  <td><span class="contentText">'.$ext.'</span></td>';
					echo'		</tr>';

					echo'		<tr>';
					echo'		  <td><b><span class="text">Postion:</span></b></td>';
					echo'		  <td><span class="contentText">'.$position.'</span></td>';
					echo'		</tr>';

					echo' <tr>';
					echo'         <td colspan="2"><br><span class = "text">Click <a href=main.php>here</a> to go back to main.</span></td>';
					echo' </tr>';
					echo'	 </table>';

					}

					else {
						echo '<p>Message not updated';	
					}
          	}
          }
          ?>
          
          
          <?php if($success==FALSE) { 
	    while ($row = mysql_fetch_array ($result)) {
		$name=$row['name'];
		$contactNo=$row['contactNo'];
		$ext=$row['ext'];
		$position=$row['position'];
		$email=$row['email'];
	  ?>
          
          <table width="100%" border="0" cellspacing="3">
            <tr>
		<span class="headerText">Edit Your Information</span><br/><br/>
              <td width="16%"><span class="text"><b>Name: </b></span></td>
              <td width="84%"><input type="text" name="name" size="40" maxlength="40" value="<?php echo $name;?>"/>              </td>
            </tr>
            <tr>
              <td><strong><span class="text">Email:</span></strong></td>
              <td><input type="text" name="email" size="40" maxlength="40" value="<?php echo $email;?>"/></td>
            </tr>
            <tr>
              <td><b><span class="text">Contact Number:</span></b></td>
              <td><input type="text" name="contactNo" size="40" maxlength="40" value="<?php echo $contactNo;?>"/></td>
            </tr>
            <tr>
              <td><b><span class="text">Extension Number:</span></b></td>
              <td><input type="text" name="ext" size="40" maxlength="40" value="<?php echo $ext;?>"/></td>
            </tr>

            <tr>
              <td><b><span class="text">Postion:</span></b></td>
              <td><input type="text" name="position" size="40" maxlength="40" value="<?php echo $position;?>"/></td>
            </tr>
            <tr>
              <td> </td>
              <td> </td>
            </tr>
          </table>
          <div align="center"><br>
            <!-- TODO insert a hidden field -->
           <!-- <input type="hidden" name="formSubmitted" value="TRUE" />
            <input name="submit" type="submit" onClick="MM_validateForm('email','','NisEmail','contactno','','NisNum');return document.MM_returnValue" value="Register me!" />
            <input type="reset" value="Reset" />-->
            <input type="hidden" name="staffid" value="<?php echo $staffid;?>"/>
		<input type="hidden" name="formSubmitted" value="TRUE" />
		<input type="submit" name="submit" value="Update" onClick="MM_validateForm('email','','NisEmail','contactNo','','NisNum');return document.MM_returnValue"  />
		<input type="reset" name="reset" value="Reset">
            
          </div>
          <?php } }?></form>
          </p></td>
          <td></td>
        </tr>
      </table>      </td>
</tr>
<tr>
	<td width="800" height="26">	<?php include("include/footer.php") ?>		</td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
<?php ob_flush(); ?>

 

Try that

Link to comment
https://forums.phpfreaks.com/topic/124594-php-edit-information/#findComment-643613
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.