Jump to content

Baffaling Problem!


GateGuardian

Recommended Posts

Now if someone finds that ive made really simple mistake im gonna laugh so much as me and my friends have been unable to work out why my queried data isnt been echo'd out!

 

Heres a link to my full code (including SQL for table setup)

 

http://www.mediafire.com/?z20w39ga1xw

 

Thanks alot

 

 

Link to comment
https://forums.phpfreaks.com/topic/111348-baffaling-problem/
Share on other sites

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
https://forums.phpfreaks.com/topic/111348-baffaling-problem/#findComment-571711
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
https://forums.phpfreaks.com/topic/111348-baffaling-problem/#findComment-571925
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.