Author Topic: profile script problem  (Read 2373 times)

0 Members and 1 Guest are viewing this topic.

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
profile script problem
« on: March 17, 2013, 01:49:10 am »
Hello. I wanna display data from database but there is  nothing on the page. Take a look in the script. Btw i try with echo $id and nothing appends in browser.


user_profile.php
Code: [Select]
<?php
require 'core.inc.php';
require 
'connect.inc.php';
require 
'loginform.inc.php';




$id $_SESSION['user_id'];


$query "SELECT * FROM `users` WHERE `id` = '$id'";
$query_run mysql_query($query);
WHILE($row mysql_fetch_array($query_run)):
$ime $row['ime'];
$prezime $row['prezime'];
endwhile;




echo 
$id;
?>


loginform.inc.php




Code: [Select]
<?php
if (isset($_POST['username'])&&isset($_POST['password'])) {
 
$username $_POST['username'];
 
$password $_POST['password'];
 
 
$password_hash md5($password);
 
if (!empty($username)&&!empty($password)) {
$query "SELECT `id` FROM `users` WHERE `username` = '".mysql_real_escape_string($username)."' AND `password` = '".mysql_real_escape_string($password)."'";
if($query_run mysql_query($query)){
$query_num_rows mysql_num_rows($query_run);

if($query_num_rows==0){
echo 'invalid username/password combination';
}else if ($query_num_rows == 1){
$user_id mysql_result($query0'id');
$_SESSION['user_id']=$user_id;
header('Location: user_profile.php');
}

}
}else{
echo "<p id='warning'>'Moras popuniti sva polja'</p>";
}
}
?>




[size=78%]core.inc.php[[/size][size=78%]/b][/size]
Code: [Select]
<?php
error_reporting
(E_ALL E_NOTICE); 
ob_start();
session_start();
$current_file $_SERVER['SCRIPT_NAME'];
$http_referer $_SERVER['HTTP_REFERER'];


function 
loggedin() {
if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])){
return true;
}else{
return false;
}


}


function 
getuserfield($field){
$query "SELECT `$field` FROM `users` WHERE `id`='".$_SESSION['user_id']."' ";
if($query_run=mysql_query($query)){

if ($query_result mysql_result($query_run ,,$field)){
return $query_result;

}


}


}


?>
I am programmer and you are my source code

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: profile script problem
« Reply #1 on: March 17, 2013, 02:11:57 am »
your while loop should be like this
while(){


}
and you need a session_start(); before you call $_SESSION['user_id']
« Last Edit: March 17, 2013, 02:12:15 am by jeremy78 »

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: profile script problem
« Reply #2 on: March 17, 2013, 02:14:15 am »
I tryed but nothing....
I am programmer and you are my source code

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: profile script problem
« Reply #3 on: March 17, 2013, 02:17:50 am »
try putting an or die(mysql_error()) on the end of your queries if you get an error somethings wrong with them

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
Re: profile script problem
« Reply #4 on: March 17, 2013, 02:20:53 am »
Also, where do you connect to the database? Even if its in one of your includes, btw, you have to call the connection with each mysql query.
Eg: mysql_query($query, $con)or die(mysql_error());
with $con being the connection variable
EDIT: also, its good to know that unless your using indexed results, use mysql_fetch_assoc instead of fetching an array. Its faster.
« Last Edit: March 17, 2013, 02:23:15 am by Uriah »

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: profile script problem
« Reply #5 on: March 17, 2013, 02:31:55 am »
All working good with or die.. But i tried if i put in query `username` = me. Then display all my information. But when i put session['user_id']; there is nothing on page. when im tryed to echo my id also there are nothing on page
I am programmer and you are my source code

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: profile script problem
« Reply #6 on: March 17, 2013, 02:36:27 am »
try print_r($id); and see what you get

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: profile script problem
« Reply #7 on: March 17, 2013, 02:39:55 am »
Nothing on page...
I am programmer and you are my source code

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: profile script problem
« Reply #8 on: March 17, 2013, 02:48:51 am »
try this

Code: [Select]
<?php
require 'core.inc.php';
require 
'connect.inc.php';
require 
'loginform.inc.php';


if(isset(
$_SESSION['user_id'])){
   
$id $_SESSION['user_id'];
}else{
   die(
"session hasnt been started");
}




   
$query "SELECT * FROM `users` WHERE `id` = '$id'";
   
$query_run mysql_query($query){
   while(
$row mysql_fetch_array($query_run)):
   
$ime $row['ime'];
   
$prezime $row['prezime'];
   }



echo 
$id;
?>
« Last Edit: March 17, 2013, 02:50:02 am by jeremy78 »

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: profile script problem
« Reply #9 on: March 17, 2013, 02:57:00 am »
on page output "session hasnt been started"
I am programmer and you are my source code

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: profile script problem
« Reply #10 on: March 17, 2013, 02:58:46 am »
then you need to start the session session_start()
« Last Edit: March 17, 2013, 07:15:16 am by jeremy78 »

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: profile script problem
« Reply #11 on: March 17, 2013, 03:02:09 am »
i tried but nothing :O
I am programmer and you are my source code

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: profile script problem
« Reply #12 on: March 17, 2013, 03:03:35 am »
can you show me the updated code

Offline Ethereal

  • Serf
  • *
  • Posts: 32
  • Cookies: 3
    • View Profile
Re: profile script problem
« Reply #13 on: March 17, 2013, 03:05:31 am »
Code: [Select]
<?php
require 'core.inc.php';
require 
'connect.inc.php';
require 
'loginform.inc.php';
session_start();


if(isset(
$_SESSION['user_id'])){
   
$id $_SESSION['user_id'];
}else{
   die(
"session hasnt been started");
}








   
$query "SELECT * FROM `users` WHERE `id` = '$id'";
   
$query_run mysql_query($query);
   WHILE(
$row mysql_fetch_array($query_run)):
   
$ime $row['ime'];
   
$prezime $row['prezime'];
   endwhile;




echo 
$id;?>


i aslo tryed with session['session_id']; but nothing
I am programmer and you are my source code

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: profile script problem
« Reply #14 on: March 17, 2013, 05:03:11 am »
just do a
print_r($_SESSION);
to see if you even have anything in there

and remove
ob_start();

« Last Edit: March 17, 2013, 05:27:48 am by relax »