SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    echo from database

    Hi there,

    Im trying to echo a number from my database and trying to show on page.
    This is a test page I wa trying it on:
    PHP Code:
    <?php include("function.php"); ?>

    <?php 

            $myUser 
    $_SESSION["user"];

            
    $myPoints mysqli_query($con"SELECT points FROM balances WHERE userId = '$myUser'");
            
    $row mysqli_fetch_array($myPoints);
            
    $tempScore $row['points'];


            
    ?>
            
            points here..<?php   echo $tempScore;   ?>......here
    Here is the function file:

    PHP Code:
    <?php 
    $con 
    mysqli_connect("localhost""db""password""user_db"); 
    init($con);

    function 
    init($con){

        
        
    session_start();
        if (isset(
    $_SESSION['active']) != true) {
            
    $_SESSION['active'] = true;
        } 
        
    $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
        
        if(isset(
    $_GET['logout'])){
            
    session_destroy();
            
    header'Location: /index.php' ) ;
        
        }    
        
        if (
    mysqli_connect_errno())
          {
            echo 
    mysqli_connect_error();
            exit();
          }
    $result =  mysqli_query($con"SELECT name, email, url FROM admin LIMIT 1");
    $row mysqli_fetch_array($result);

     
    $adminEmail $row['email'];
     
    $siteUrl $row['url'];
     
    $siteName $row['name'];
    }

    if(!isset(
    $_SESSION["ref"])){
            if(isset(
    $_GET["ref"])){
            
    $_SESSION["ref"] =     mysqli_real_escape_string($con$_GET["ref"]);
            } else {
            
    $_SESSION["ref"] = "";    
            }
        
        } else {
        if(isset(
    $_GET["ref"])){
            
    $_SESSION["ref"] =     mysqli_real_escape_string($con$_GET["ref"]);
            }    
        }

    ?>
    Its not showing any errors or numbers at all when page is loaded.
    What might be wrong with it?

    Chad

  2. #2
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,255
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Hi Chad,

    Have you tried checking $myUser to be sure that it actually contains a value?

  3. #3
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    Hi Chad,

    Have you tried checking $myUser to be sure that it actually contains a value?
    How would you check that? With mysqli_error?




    Chad

  4. #4
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,255
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    You can just do echo $myUser; and see what it spits out.

  5. #5
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    You can just do echo $myUser; and see what it spits out.
    It seems it is spitting out an array. The word that came up was "Array".

    Why is that?


    chad

  6. #6
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,255
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    The code you posted doesn't show $_SESSION["user"] being set, so you'd have to look at the rest of your code to see what value you're assigning.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •