Jump to content

Baffaling Problem!


GateGuardian

Recommended Posts

Ok code:

 

Its suppose to query for data on the members.php page, store them as varaible using the extract() function, then echo them out later in the page into a table

 

Problem is i keep ending up with a blank HTML table with no data being echoed in it

 

 

checklogin.php

 

<?php
//Includes
include 'Libary/opendb.php';

//Get user posted info
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$encrypted_mypassword=md5($mypassword);

// To protect MySQL injection
$myusername = stripslashes($myusername);
$myusername = mysql_real_escape_string($myusername);

$sql="SELECT * FROM usersinfo WHERE Username='$myusername' AND Password='$mypassword'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting rows returned
$count=mysql_num_rows($result) or die(mysql_error());  ;

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "members.php"
session_start();
session_register("myusername");
session_register("mypassword");
$_SESSION['Username']=$myusername;
header("location:members.php");
}
else {
echo "Wrong Username or Password";
}
include 'Libary/closedb.php';
?>

 

members.php

 

<?php
error_reporting(E_ALL);  
//session name grab and page auth
session_start();
$usernamesession = $_SESSION['Username'];
if(!session_is_registered(myusername)){
header("location:index.html");
}

?>
<!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" />
<title>Members Page</title>
<style type="text/css">
<!--
body {
background-color: #666666;
}
-->
</style></head>

<body>
<p>
<?php
//Includes
include 'Libary/opendb.php';


//Main query for user info
$query  = "SELECT Username, Age, Sex, Location, Picture FROM usersinfo WHERE Username ='$usernamesession'";
$result = mysql_query($query) or die(mysql_error());  
//Place query data into variables
$row = mysql_fetch_array($result) or die(mysql_error());
extract($row, EXTR_PREFIX_SAME, "prefix123");  
?>
</p>
<table width="257" border="1">
  <tr>
    <td colspan="2"><img src="<?php echo $Picture; ?>"/></td>
  </tr>
  <tr>
    <td width="133">Username</td>
    <td width="108"><?php echo $Username; ?> </td>
  </tr>
  <tr>
    <td>Age:</td>
    <td><?php echo $Age; ?> </td>
  </tr>
  <tr>
    <td>Sex:</td>
    <td><?php echo $Sex; ?> </td>
  </tr>
  <tr>
    <td>Location:</td>
    <td><?php echo $Location; ?> </td>
  </tr>
</table>
<?php
include 'Libary/closedb.php';
?>
<p> </p>
</body>
</html>

 

opendb.php

 

<?php
$conn = mysql_connect("localhost", "testdatabase", "test") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("testdatabase") or die(mysql_error());
echo "Connected to Database<br />";
?> 

 

closedb.php

 

<?php
mysql_close($conn) or die(mysql_error());
echo "<p><b>Database Closed</b>";
?>

Link to comment
Share on other sites

I think you should change this

<?php
error_reporting(E_ALL);  
//session name grab and page auth
session_start();
$usernamesession = $_SESSION['Username'];
if(!session_is_registered(myusername)){
header("location:index.html");
}

?>
<!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" />
<title>Members Page</title>
<style type="text/css">
<!--
body {
background-color: #666666;
}
-->
</style></head>

<body>
<p>
<?php
//Includes
include 'Libary/opendb.php';


//Main query for user info
$query  = "SELECT Username, Age, Sex, Location, Picture FROM usersinfo WHERE Username ='$usernamesession'";
$result = mysql_query($query) or die(mysql_error());  
//Place query data into variables
$row = mysql_fetch_assoc($result) or die(mysql_error()); //changed//
extract($row, EXTR_PREFIX_SAME, "prefix123");  
?>
</p>
<table width="257" border="1">
  <tr>
    <td colspan="2"><img src="<?php echo $Picture; ?>"/></td>
  </tr>
  <tr>
    <td width="133">Username</td>
    <td width="108"><?php echo $row['Username']; ?> </td><!-- This should echo out like this, and not a variable like before as the variable wasn't set-->
  </tr>
  <tr>
    <td>Age:</td>
    <td><?php echo $Age; ?> </td>
  </tr>
  <tr>
    <td>Sex:</td>
    <td><?php echo $Sex; ?> </td>
  </tr>
  <tr>
    <td>Location:</td>
    <td><?php echo $Location; ?> </td>
  </tr>
</table>
<?php
include 'Libary/closedb.php';
?>
<p> </p>
</body>
</html>

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.