Jump to content

[SOLVED] Problems with index.php code


JoelRocks

Recommended Posts

Despite help, still having issues with this code, can anyone help me...

 

Gives an error i think its the SQL PHP functions...

 

<?php

$hostname= "localhost";
$user= "remotepa_framewo";
$password = "-";

$conn = @mysql_connect(  $hostname, $user, $password )
or die ("Could not connect to server");

$db = @mysql_select_db("remotepa_framework", $conn)
or die ("Could not connect to database");

$sql = "SELECT * FROM users WHERE username=\"$_SESSION['username']\"";

$result = @mysql_query( $sql, $conn)
or die ("Could not execute query");

$output = mysql_fetch_assoc($sql);
session_start();
session_id($_GET['PHPSESSID']);//set php session id from URL
if(isset($_SESSION['username']))
{	
if($output['active'] < 1)	
{		
echo ("Please reset your details");
echo ("Hello " .$_SESSION['username']);
echo ("<br />");
echo ("You are logged in successfully");
}
}
else
{
echo ("Sorry you are not logged in");
exit;
}
?>

Link to comment
Share on other sites

Though it is best if you post the error so people know what to look for, I don't think you should be using double quotes in the sql query.

Change:

$sql = "SELECT * FROM users WHERE username=\"$_SESSION['username']\"";
[code]

to:
[code]
$sql = "SELECT * FROM users WHERE username='$_SESSION['username']'";

[/code][/code]

Link to comment
Share on other sites

Further errors:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/remotepa/public_html/Joel/index.php on line 16

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/remotepa/public_html/Joel/index.php:16) in /home/remotepa/public_html/Joel/index.php on line 25

Link to comment
Share on other sites

Try:

 

<?php
session_start();
session_id($_GET['PHPSESSID']);//set php session id from URL
$hostname= "localhost";
$user= "remotepa_framewo";
$password = "-";

$conn = @mysql_connect(  $hostname, $user, $password )
or die ("Could not connect to server");

$db = @mysql_select_db("remotepa_framework", $conn)
or die ("Could not connect to database");

$sql = "SELECT * FROM users WHERE username='".$_SESSION['username']."'";

$result = mysql_query( $sql, $conn) or die ("Could not execute query");

$output = mysql_fetch_assoc($result);
if(isset($_SESSION['username']))
{	
if($output['active'] < 1)	
{		
echo ("Please reset your details");
echo ("Hello " .$_SESSION['username']);
echo ("<br />");
echo ("You are logged in successfully");
}
}
else
{
echo ("Sorry you are not logged in");
exit;
}
?>

 

You need to start the session before any output. You also need to start it before making use of the $_SESSION array.

 

The reason for the mysql_fetch_assoc error is because there are no results being returned by your query, because $_SESSION['username'] is undefined without starting the session previously

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.