what is the problem that cant display table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
liyun88
Forum Commoner
Posts: 51
Joined: Thu Mar 31, 2011 12:18 pm

what is the problem that cant display table

Post by liyun88 »

hi,i face some problem that i want to edit profile but the edit profile page cant display table..i dont know these code should be placed at where??can anyone help us??thanks in advance..

Code: Select all

<?php

		  $id = $_GET['id'];
$query = 'SELECT * FROM register WHERE id = "' . mysql_real_escape_string($id) .'" LIMIT 1';   
    $result = mysql_query($query);

if ($data = mysql_fetch_object($result))
{


?>
this is editProfile.php

Code: Select all

<?php
session_start();
require_once 'config.php' ;

$id = $_GET['id'];
$query = 'SELECT * FROM register WHERE id = "' . mysql_real_escape_string($id) .'" LIMIT 1';   
    $result = mysql_query($query);

if ($data = mysql_fetch_object($result))
{

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css">
<title>::Edit Form::</title>  
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
</head>
<body>

<table  width="952px" border="0" cellspacing="0" cellpadding="0" valign="top" align="center">
  <tr>
    <td align="center"><?php include "header.php"; ?></td>
  </tr>
  <tr><td><img src="picture/purple_line.jpg" /></td></tr>
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td  width="300px" height="600px" valign="top" align="center"> <?php include "menu.php";?>
        </td>
        <td width="12px">&nbsp;</td>
        <td width="630px"background="picture/content1.png" style="background-repeat:no-repeat;" valign="top"><table width="100%" border="0">
          <tr>
            <td><table width="100%" border="0" align="right">
              <tr>
              <td width="28%">&nbsp;</td>
                <td width="38%"><img src="picture/icon_cart.jpg" /></td>
              </tr>
          </table></td>
          </tr>
          <tr>
            <td><p align="center"> <font size="+2"><strong><em><font color="#000000">Edit 
    Profile </font></em></strong></font></p>
	</td>
          </tr>
		  <tr><td><form action="save_editProfile.php" method="post" enctype="multipart/form-data" >
  
  <table>
      <tr> 
        <td><label for="name">Name<span class="info"><font size="0.2"><font color="#ffffff">4-20 chars</font></font></span></label></td>
        <td><input type="text" name="name" value="<?php echo $data->name ?>"></td>
      </tr>
      <tr> 
        <td><label for="username">Username<span class="info"><font size="0.2"><font color="#ffffff">3-10 chars</font></font></span></label></td>
        <td><input type="text" name="username" value="<?php echo $data->username ?>"></td>
      </tr>
      <tr> 
        <td><label for="password">New Password<span class="info"><font size="0.2"><font color="#ffffff">6-12 chars</font></font></span></label></td>
        <td><input type="password" name="password" value="" /></td>
        </tr>
     
		<tr> 
        <td><label for="gender">Gender</label></td>
		  <td><input type="radio" name="gender" value="male" <?php echo $data->gender == 1 ? "checked" : "" ?>>Male
			<input type="radio" name="gender" value="female" <?php echo $data->gender == 2 ? "checked" : "" ?>>Female
          </td>
      </tr>
	  <tr> 
        <td><label for="phone">Contact No</label></td>
        <td><input type="text" name="phone" value="<?php echo $data->phone ?>"></td>
      </tr>
	  <tr> 
        <td><label for="email">Email</label></td>
       <td><input type="text" name="email" value="<?php echo $data->email ?>"></td>
		</tr>
		<tr> 
        <td><label for="address">Address</label></td>
        <td><input type="text" name="address" value="<?php echo $data->address ?>"></td>
      </tr>
     
     
     
      

  
  </table>
  <label for="registerSubmit">&nbsp;</label>
        <input type="hidden" name="registerSubmit" id="registerSubmit" value="true" />
        <input name="submit2" type="submit" value="Edit" />
      
 </div>
   </form>   
 </td></tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
<?php } ?>
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: what is the problem that cant display table

Post by fugix »

what errors do you recieve?
liyun88
Forum Commoner
Posts: 51
Joined: Thu Mar 31, 2011 12:18 pm

Re: what is the problem that cant display table

Post by liyun88 »

fugix wrote:what errors do you recieve?
my error is when put these codes at the place i just post,when i click the link(editProfile.php),it shows blank..
when i put these coding before the form,it will show header and menu only,n the table for fill in the form not show at all..
i dont know what error but these coding is necessary because need to read them and edit the profile and update the profile..
what should i do??
can u help me??
thanks in advance..
Maq
Forum Newbie
Posts: 4
Joined: Thu Apr 16, 2009 10:34 am

Re: what is the problem that cant display table

Post by Maq »

Put these 2 lines directly after the opening <?php tag in the problematic script:

Code: Select all

ini_set ("display_errors", "1");
error_reporting(E_ALL);
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: what is the problem that cant display table

Post by fugix »

after you do what Maq said, please let us know what errors you are receiving so we can assist you
liyun88
Forum Commoner
Posts: 51
Joined: Thu Mar 31, 2011 12:18 pm

Re: what is the problem that cant display table

Post by liyun88 »

fugix wrote:after you do what Maq said, please let us know what errors you are receiving so we can assist you
after i follow what Maq said,the problem is not show errors at all n whole the page is blank n not hv anything at there...
but if i din put these code in the script,it will dispaly my header and the edit profile table..but i think not function because not retrieve any id to update their profile..

Code: Select all

<?php
 $id= $_GET['id'];
$query = 'SELECT * FROM register WHERE id = "'. mysql_real_escape_string($id) . '"LIMIT 1';   
    $result = mysql_query($query);


if ($data = mysql_fetch_object($result))
{
}?>
the one is the code after i put the code given by Maq

Code: Select all

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
 
 session_start();
require_once 'config.php' ;
 $id= $_GET['id'];
$query = 'SELECT * FROM register WHERE id = "'. mysql_real_escape_string($id) . '"LIMIT 1';   
    $result = mysql_query($query);


if ($data = mysql_fetch_object($result))
{

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css">
<title>::Register Form::</title>  
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
</head>
<body>
<table  width="952px" border="0" cellspacing="0" cellpadding="0" valign="top" align="center">
  <tr>
    <td align="center"><?php include "header.php"; ?></td>
  </tr>
  <tr><td><img src="picture/purple_line.jpg" /></td></tr>
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td  width="300px" height="600px" valign="top" align="center"> <?php include "menu.php";?>
        </td>
        <td width="12px">&nbsp;</td>
        <td width="630px"background="picture/content1.png" style="background-repeat:no-repeat;" valign="top"><table width="100%" border="0">
          <tr>
            <td><table width="100%" border="0" align="right">
              <tr>
              <td width="28%">&nbsp;</td>
                <td width="38%"><img src="picture/icon_cart.jpg" /></td>
              </tr>
          </table></td>
           <tr>
            <td><p align="center"> <font size="+2"><strong><em><font color="#000000">Edit
    Form </font></em></strong></font></p>
	</td>
          </tr>
		  <tr><td><form action="save_editProfile.php" method="post" >
  <input type="hidden" name="id" value="<?php echo $data->id ?>">
  <div align="left"> 
  <table>
    
	
  
      <tr> 
        <td><label for="name">Name<span class="info"><font size="0.2"><font color="#ffffff">4-20 chars</font></font></span></label></td>
        <td><input type="text" name="name" value="<?php echo $data->name ?>"></td>
      </tr>
      <tr> 
        <td><label for="username">Username<span class="info"><font size="0.2"><font color="#ffffff">3-10 chars</font></font></span></label></td>
        <td><input type="text" name="username" value="<?php echo $data->username ?>"></td>
      </tr>
      <tr> 
        <td><label for="password">New Password<span class="info"><font size="0.2"><font color="#ffffff">6-12 chars</font></font></span></label></td>
        <td><input type="password" name="password" value="" /></td>
        </tr>
     
		<tr> 
        <td><label for="gender">Gender</label></td>
		  <td><input type="radio" name="gender" value="male" <?php echo $data->gender == 1 ? "checked" : "" ?>>Male
			<input type="radio" name="gender" value="female" <?php echo $data->gender == 2 ? "checked" : "" ?>>Female
          </td>
      </tr>
	  <tr> 
        <td><label for="phone">Contact No</label></td>
        <td><input type="text" name="phone" value="<?php echo $data->phone ?>"></td>
      </tr>
	  <tr> 
        <td><label for="email">Email</label></td>
       <td><input type="text" name="email" value="<?php echo $data->email ?>"></td>
		</tr>
		<tr> 
        <td><label for="address">Address</label></td>
        <td><input type="text" name="address" value="<?php echo $data->address ?>"></td>
      </tr>
     
     
     
      

  
  </table>
  <input type="submit" name="submit" value="Edit">
 </div>
   </form> 
      
    

  
  
      
 
    
 </td></tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

        

		 
<?php } ?>
thanks in advance for help me to solve my problem..
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: what is the problem that cant display table

Post by fugix »

change...

Code: Select all

query = 'SELECT * FROM register WHERE id = "'. mysql_real_escape_string($id) . '"LIMIT 1';   
to...

Code: Select all

$escape_id = 'mysql_real_escape_string($id);
query = "SELECT * FROM register WHERE id = '$escape_id' LIMIT 1";   
liyun88
Forum Commoner
Posts: 51
Joined: Thu Mar 31, 2011 12:18 pm

Re: what is the problem that cant display table

Post by liyun88 »

fugix wrote:change...

Code: Select all

query = 'SELECT * FROM register WHERE id = "'. mysql_real_escape_string($id) . '"LIMIT 1';   
to...

Code: Select all

$escape_id = 'mysql_real_escape_string($id);
query = "SELECT * FROM register WHERE id = '$escape_id' LIMIT 1";   

hi,i already solve my problem..
i change this..

Code: Select all

$id= $_GET['id'];
to this..

Code: Select all

 $id = $_SESSION['id'];
but after i success display the edit profile tablewhen i try to edit new password and store in database..
it not change and update at all..still the same password in the database as previous....
i guess is my update query get problem because i also get the same problem that cant update session_id in the database..
can u help me to check n correct my error in update query..
thanks in advance..

the one is save_editProfile.php

Code: Select all

<?php
session_start();
require_once 'config.php' ;
require_once 'application.php' ;

$id = $_SESSION['id'];



$query = 'UPDATE register set name = "' . mysql_real_escape_string($_REQUEST['name']) . '", 
username = "' . mysql_real_escape_string($_REQUEST['username']) . '", 
gender = "' . mysql_real_escape_string($_REQUEST['gender']) . '", 
phone = "' . mysql_real_escape_string($_REQUEST['phone']) . '", 
email = "' . mysql_real_escape_string($_REQUEST['email']) . '" , 
address = "' . mysql_real_escape_string($_REQUEST['address']) . '" WHERE id = $id';
$result = mysql_query($query);

if(!empty($_REQUEST["password"]) )
{
  $query = 'UPDATE register set password = md5("' . mysql_real_escape_string($_REQUEST["password"]) . '") WHERE id = $id';
  $result = mysql_query($query);
}

   
    redirect("home.php?id=$id");

?>



the one is same problem as save_editProfile.php

Code: Select all

<?php
session_start();

include 'application.php';

$id = $_REQUEST['id'];
$username = $_REQUEST["username"];
$password = $_REQUEST["password"];

$query = 'SELECT * FROM register WHERE username = "'. mysql_real_escape_string($username) . '"';

    $result = mysql_query($query);  

if ($data = mysql_fetch_object($result))
{

$_SESSION['dbhash'] = $data->password;
$_SESSION['checkhash'] = md5($password);

  if(md5($password) == $data->password)
  {
   $_SESSION["login"] = true;
   $_SESSION["username"] = $data->username;
   $_SESSION["id"] = $data->id;
 
  if(mysql_num_rows($result) == 1){  
            $user = mysql_fetch_assoc($result);  
            $query_update = 'UPDATE register SET session_id = "' . session_id() . '" WHERE id = "' . $user['id'] . '" LIMIT 1';  
            mysql_query($query_update);  
  }
  }
}
redirect('home.php');

?>

i dont know what is wrong for update query..
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: what is the problem that cant display table

Post by fugix »

first off, whenever you have something like this...

mysql_real_escape_string($_REQUEST['username'])

store it inside a variable....

$real_escape = mysql_real_escape_string($_REQUEST['username'])

so you can insert that into the query and not the entire function... make things less messy and run smoother. that is most likely your issue

change username = "' . mysql_real_escape_string($_REQUEST['username']) . '",

to username = '$real_escape',

assuming you assing that function to a variable named $real_escape
Post Reply