Jump to content

[SOLVED] echo/mysql


imdead

Recommended Posts

Hey Guys, Whats Wrong With This, I Cant Spot The Error. It's Not Echo'ing Anything Out >

<?php
if(session_is_registered('username')){
$sql = mysql_query("SELECT * FROM users");
	if (mysql_num_rows($sql) == 1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
if ($userlevel === '1'){
echo"<a href='admin.php'>Admin Panel</a> // ";
}
}}
?><a href="http://jigsaw.w3.org/css-validator/check/referer">Valid CSS</a>

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/
Share on other sites

I am not sure whether it will solve Or not:

change your session like:

And add mysql error reporting.

<?php
if($_SESSION('username')){
$sql = mysql_query("SELECT * FROM users") or die (mysql_error());
	if (mysql_num_rows($sql) == 1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
if ($userlevel == '1'){
echo"<a href='admin.php'>Admin Panel</a> // ";
}
}}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568002
Share on other sites

Fatal error: Function name must be a string in C:\xampp\htdocs\footer.php on line 3

 

Also If I Add This

 

<?php
if(session_is_registered('username')){
$sql = mysql_query("SELECT * FROM users");
	if (mysql_num_rows($sql) == 1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
if ($userlevel == '1'){
echo"<a href='admin.php'>Admin Panel</a> // ";
}
}
}else{
echo 'blah blah not logged in';
}
?>

 

When Your Not logged in, you get blah blah not logged in

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568006
Share on other sites

Did you try this:

<?php
if($_SESSION['username']){
$sql = mysql_query("SELECT * FROM users") or die (mysql_error());
	if (mysql_num_rows($sql) == 1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
if ($userlevel == '1'){
echo"<a href='admin.php'>Admin Panel</a> // ";
}
else
{
echo "Error: not loged in";
}
}}
?>

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568008
Share on other sites

It mean that session is not registered.

try this:

and post output.

<?php
if($_SESSION['username']){
$sql = mysql_query("SELECT * FROM users") or die (mysql_error());
	if (mysql_num_rows($sql) == 1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
if ($userlevel == '1'){
echo"<a href='admin.php'>Admin Panel</a> // ";
}
else
{
echo "Error: not loged in";
}
}}
else {
echo "session not registered";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568013
Share on other sites

You need to call session_start() prior to using the $_SESSION array.

 

<?php

session_start();
if (isset($_SESSION['username'])) {
  if ($result = mysql_query("SELECT userlevel FROM users WHERE username = '{$_SESSION['username']}'")) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($sql);
      $userlevel = $row['userlevel'];
      if ($userlevel == 1) {
        echo"<a href='admin.php'>Admin Panel</a> // ";
      }
    } else {
      echo "Error: not loged in";
    }
  }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568032
Share on other sites

<?php

if($_SESSION['username']){

$sql = mysql_query("SELECT * FROM users") or die (mysql_error());

if (mysql_num_rows($sql) == 1){

$row = mysql_fetch_assoc($sql);

$userlevel = $row['userlevel'];

if ($userlevel == '1'){

echo"<a href='admin.php'>Admin Panel</a> // ";

}else{

echo "Error: not loged in";

}

}

}else {

echo "session not registered";

}

?>

 

Suggestions:

1.) you need a where statement in your sql query in order to get one user;

2.) do a var_dump of $userlevel to see if its a string or an integer this will help you in choosing =="1" or ==1 in your if statement

3.) Are you sure you have called session_start(); on the pages that make use of this footer

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568033
Share on other sites

yes session start is called in the header.php

 

if i use a where

 

<?php
if($_SESSION['username']){
$sql = mysql_query("SELECT * FROM users WHERE username={$_SESSION['username']}") or die (mysql_error());
	if (mysql_num_rows($sql) == 1){
	$row = mysql_fetch_assoc($sql);
	$userlevel = $row['userlevel'];
if ($userlevel == '1'){
echo"<a href='admin.php'>Admin Panel</a> // ";
}
else
{
echo "Error: not loged in";
}
}}
else {
echo "session not registered";
}
?>

 

I Get Unknown column 'kevski' in 'where clause'

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568035
Share on other sites

I use sprintf when formulating a sql query thats my preference

http://www.php.net/sprintf have a read

<?php
if($_SESSION['username']){
$query = sprintf("SELECT * FROM users WHERE username='%s'", $_SESSION['username']);
$sql = mysql_query($query) or die (mysql_error());
	if (mysql_num_rows($sql) == 1){
		$row = mysql_fetch_assoc($sql);
		$userlevel = $row['userlevel'];
		if ($userlevel == '1'){
			echo"<a href='admin.php'>Admin Panel</a> // ";
		}else{
			echo "Error: not loged in";
		}
	}
}
else {
echo "session not registered";
}
?>

 

Im not sure about the line " if ($userlevel == '1'){ " because I dont know if the $userlevel variable is storing a int or string, do a var_dump($userlevel) to find this out.

 

Link to comment
https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568043
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.