#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    661
    Rep Power
    0

    Angry Fatal error: Only variables can be passed by reference in ....


    Php Experts,

    I dont know what is wrong here.
    My line 53 looked like this:

    PHP Code:
    <title><?php echo $site_name; echo $user"; ?> User's Notices in <?php echo $server_time; ?> time.</title>
    And line 140:
    PHP Code:
        <center><span style="font-weight: bold;"><?php echo $site_name; echo $user?> User's Notices in <?php echo $server_time?> time.</span></center>
    Don't worry about the outdated html. I will fix that later. But first things first.
    On both lines, I shortened the code by replacing 2 echo with 1. Like so:

    PHP Code:
    echo $site_name $user"; 
    And then I started getting an error. before this change no error was given. I get an error related to another thing but the funny thing is I never got that error before fiddling with the echoes.
    I get error:

    Fatal error: Only variables can be passed by reference in C:\xampp\htdocs\test\notices.php on line 70

    Note line 70 looks like the following and I have included variables. And so, I don't understand the error.

    PHP Code:
    $result_2 mysqli_stmt_bind_result($stmt,$id,$date_&_time,$recipient_username,$sender_username,$notice); 
    Note that, on my NotePad++, the "time" is coloured black while the rest of the text that is part of the variable name is shown blue. Why is that ?
    $date_&_time

    My column name is: date_&_time.
    Few days earlier, I was getting error that the column name is unrecognised and so I switched the column name in mysql tbl to: date_and_time.
    And the error was gone.
    But the funny thing is, I have other php files that reference likewise to other tbles and they too have the column name: $date_&_time.
    But, I never get shown any errors on those php file and these php files do manage to dump data to these other tbles and these $date_&_time columns do show the current date & time.
    But, when I deal with this particular php file then for some reason it does not like the $date_&_time mention in the php file and I started getting errors that the column name is unknown even though the column name for that particular tbl was "$date_&_time".
    And now, NotePad++ colours the "time" part black while the rest of the variable name "$date_&_" blue. Why is that ?
    very very strange!

    Anyway, here's the full code. It is not complete so ignore the other variables names such as $result_2. And in this thread, let's concentrate on this single issue.

    PHP Code:
    <?php 

    //Required PHP Files. 
    include 'config.php'
    include 
    'header.php'

    //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. 
    if (login_check() === FALSE

        
    //Redirect User to Log-in Page after 2 secs. 
        
    header("refresh:2; url=login.php"); 
        exit(); 

    else 

        
    //Grab User details from Session Variables and echo them. 
        
    $user $_SESSION["user"]; 
        
        
    $id $_SESSION["id"]; 
        
    $account_activation_status $_SESSION["account_activation_status"]; 
        
    $id_video_verification_status $_SESSION["id_video_verification_status"]; 
        
    $id_video_verification_url $_SESSION["id_video_verification_url"]; 
        
    $sponsor_username $_SESSION["sponsor_username"]; 
        
    $recruits_number $_SESSION["recruits_number"]; 
        
    $on_day_number_on_7_days_wish_list $_SESSION["on_day_number_on_7_days_wish_list"]; 
        
    $primary_website_domain $_SESSION["primary_website_domain"]; 
        
    $primary_website_email $_SESSION["primary_website_email"]; 
        
    $username $_SESSION["username"]; 
        
    $first_name $_SESSION["first_name"]; 
        
    $middle_name $_SESSION["middle_name"]; 
        
    $surname $_SESSION["surname"]; 
        
    $gender $_SESSION["gender"]; 
        
    $date_of_birth $_SESSION["date_of_birth"]; 
        
    $age_range $_SESSION["age_range"]; 
        
    $religion $_SESSION["religion"]; 
        
    $marital_status $_SESSION["marital_status"]; 
        
    $working_status $_SESSION["working_status"]; 
        
    $profession $_SESSION["profession"]; 
        
    $home_town $_SESSION["home_town"]; 
        
    $home_borough $_SESSION["home_borough"]; 
        
    $home_city $_SESSION["home_city"]; 
        
    $home_county $_SESSION["home_county"]; 
        
    $home_region $_SESSION["home_region"]; 
        
    $home_state $_SESSION["home_state"]; 
        
    $home_country $_SESSION["home_country"]; 
        
        
    $recipient_username $user
        
    ?> 
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"> 
        <html> 
        <head> 
        <meta content="text/html; charset=ISO-8859-1"  http-equiv="content-type"> 
        <title><?php echo "$site_name "; echo "$user "?> User's Notices in <?php echo $server_time?> time.</title> 
        </head> 
        <body> 
        <br> 
        <center><span style="font-weight: bold;"><?php echo "$site_name "; echo "$user "?> User's Notices in <?php echo $server_time?> time.</span></center> 
        <br> 
        <br> 
        <?php 
        $query 
    "SELECT id,date_&_time,recipient_username,sender_username,notice FROM notices WHERE recipient_username = ?"
        
        if (
    $stmt mysqli_prepare($conn,$query)) 
        {     
            
    //Bind Parameter 
            
    mysqli_stmt_bind_param($stmt,'s',$recipient_username);     
            
    //Execute Statement 
            
    mysqli_stmt_execute($stmt);     
            
    //Bind Result Variables     
            
    $result_2 mysqli_stmt_bind_result($stmt,$id,$date_&_time,$recipient_username,$sender_username,$notice); 
            
    $result mysqli_stmt_store_result($stmt); 
            
    $rows_num mysqli_stmt_num_rows($stmt);     
            
    printf("Result set has %d rows.\n",$rows_num); 
        } 
        
        
    $page_count 10
        
    $page_size ceil($rows_num $page_count); 
        
    //Get the Page Number, Default is 1 (First Page).     
        
    $page_number $_GET["page_number"]; 
        if (
    $page_number == ""$page_number 1
            
    $offset = ($page_number -1) * $page_size
            
            
    $query .= " limit {$offset},{$page_size}"
            
    //$result = mysqli_query($conn,$query); 
            
    $result_2 mysqli_stmt_bind_result($stmt,$id,$date_and_time,$recipient_username,$sender_username,$notice); 
            
    $result mysqli_stmt_store_result($stmt); 
        
    ?>     
        <table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"> 
        <?php if($rows_num) {?> 
        <tr name="headings"> 
        <td bgcolor="#FFFFFF" name="column-heading_submission-number">Submission Number</td> 
        <td bgcolor="#FFFFFF" name="column-heading_logging-server-date=&-time">Date & Time in <?php echo $server_time ?></td> 
        <td bgcolor="#FFFFFF" name="column-heading_to">To</td> 
        <td bgcolor="#FFFFFF" name="column-heading_from">From</td> 
        <td bgcolor="#FFFFFF" name="column-heading_notice">Notice</td> 
        </tr>     
        <?php while($row mysqli_stmt_fetch($stmt)) 
        { 
            
    ?> 
            <tr name="user-details"> 
            <td bgcolor="#FFFFFF" name="submission-number"><?php echo $row['id']; ?></td> 
            <td bgcolor="#FFFFFF" name="logging-server-date-&-time"><?php echo $row['date_&_time']; ?></td> 
            <td bgcolor="#FFFFFF" name="recipient_username"><?php echo $row['recipient_username']; ?></td> 
            <td bgcolor="#FFFFFF" name="sender_username"><?php echo $row['sender_username']; ?></td> 
            <td bgcolor="#FFFFFF" name="notice"><?php echo $row['message']; ?></td>  
            </tr> 
            <?php 
        

        
    ?> 
        <tr name="pagination"> 
        <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
        <?php 
        $rows_num 
    mysqli_stmt_num_rows($stmt); 
        if(
    $rows_num <= $page_size
        { 
            echo 
    "Page 1"
        } 
        else 
        { 
            for(
    $i=1;$i<=$page_count;$i++) 
            echo 
    "<a href=\"{$_SERVER['PHP_SELF']}?page_number={$i}\">{$i}</a>  "
        } 
        
    ?> 
        </td> 
        </tr> 
        <?php 
        

        else 
        { 
            
    ?> 
            <tr> 
            <td bgcolor="FFFFFF">No record found! Try another time.</td> 
            </tr> 
            <?php 
        

        
    ?> 
        </table> 
        <br> 
        <br> 
        <center><span style="font-weight: bold;"><?php echo "$site_name "; echo "$user "?> User's Notices in <?php echo $server_time?> time.</span></center> 
        <br> 
        <br> 
    </div> 
    <br> 
    </body> 
    </html> 
    <?php 

    //Free Result Set 
    mysqli_stmt_free_result($stmt); 

    //Close Database Connection 
    mysqli_stmt_close($stmt); 
    ?>
    Fatal error: Only variables can be passed by reference in C:\xampp\htdocs\test\notices.php on line 70

    Line 70:
    PHP Code:
    $result_2 mysqli_stmt_bind_result($stmt,$id,$date_&_time,$recipient_username,$sender_username,$notice); 
    Full context line 60-87:
    PHP Code:
    <?php 
        $query 
    "SELECT id,date_&_time,recipient_username,sender_username,notice FROM notices WHERE recipient_username = ?"
        
        if (
    $stmt mysqli_prepare($conn,$query)) 
        {     
            
    //Bind Parameter 
            
    mysqli_stmt_bind_param($stmt,'s',$recipient_username);     
            
    //Execute Statement 
            
    mysqli_stmt_execute($stmt);     
            
    //Bind Result Variables     
            
    $result_2 mysqli_stmt_bind_result($stmt,$id,$date_&_time,$recipient_username,$sender_username,$notice); 
            
    $result mysqli_stmt_store_result($stmt); 
            
    $rows_num mysqli_stmt_num_rows($stmt);     
            
    printf("Result set has %d rows.\n",$rows_num); 
        } 
        
        
    $page_count 10
        
    $page_size ceil($rows_num $page_count); 
        
    //Get the Page Number, Default is 1 (First Page).     
        
    $page_number $_GET["page_number"]; 
        if (
    $page_number == ""$page_number 1
            
    $offset = ($page_number -1) * $page_size
            
            
    $query .= " limit {$offset},{$page_size}"
            
    //$result = mysqli_query($conn,$query); 
            
    $result_2 mysqli_stmt_bind_result($stmt,$id,$date_and_time,$recipient_username,$sender_username,$notice); 
            
    $result mysqli_stmt_store_result($stmt); 
        
    ?>

    Last edited by UniqueIdeaMan; March 11th, 2018 at 10:11 AM.
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,920
    Rep Power
    4554
    -- Cigars, whiskey and wild, wild women. --
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    661
    Rep Power
    0
    Originally Posted by Sepodati
    I already know the basics of $variable.
    The very moment, I remove the column "date_&_time" from here:

    Line 62
    PHP Code:
    $query "SELECT id,recipient_username,sender_username,notice FROM notices WHERE recipient_username = ?"
    and from here:

    Line 70:
    PHP Code:
    $result_2 mysqli_stmt_bind_result($stmt,$id,$recipient_username,$sender_username,$notice); 
    Then the error disappears. I am suspecting either php or mysql has an issue with the "&" from column and variable: date_&_time.
    Anyway, let me investigate and experiment if "&" is forbidden to be part of a variable name.
    Thanks for the hint.
    Oh btw, you actually did not mean to swear in your last post. You did it as a joke. But I took it as the wrong way and reported you. Oopps!

    PHP: mysqli_stmt::bind_result - Manual

    I notice the following from your link:
    To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which is being assigned (the source variable).
    Guessing the "&" is reserved for another purpose in a variable. Just had a quick glance at your link and did a CTRL+F and came across the sentence.
    Gonna have to look more into this.
    Last edited by UniqueIdeaMan; March 11th, 2018 at 10:12 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,418
    Rep Power
    631
    Originally Posted by UniqueIdeaMan
    I already know the basics of $variable.

    Obviously not.

    Originally Posted by UniqueIdeaMan
    Anyeay, let me investigate and experiment if "&" is forbidden to be part of a variable name.
    Like I said.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    661
    Rep Power
    0
    Originally Posted by gw1500se
    Obviously not.



    Like I said.
    Frankly, had enough and so just renamed my column names and variable to:

    date_and_time.
    Got rid of:
    date_&_time.
  10. #6
  11. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,226
    Rep Power
    4149
    A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores
    Do you see amperstand in that list anywhere? No? Guess that means you cannot use it in variables names.

    Bitwise Operators
    $a & $b And Bits that are set in both $a and $b are set.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    661
    Rep Power
    0
    Originally Posted by kicken
    Do you see amperstand in that list anywhere? No? Guess that means you cannot use it in variables names.

    Bitwise Operators
    Thanks for the link.
    I'm not much of a techie guy. They say: "You can't teach an old dog new tricks!" and I say: "You can't teach a layman too much techie stuffs". I'm the layman here. So, having a quick look at your link tells my layman head that I should not use "&" in the middle of a variable name as it is reserved for things like this:
    $a & $b And Bits that are set in both $a and $b are set.
    PHP: Bitwise Operators - Manual
    But do correct me if my understanding is flawed.
    Else tell me I understood correct and I'll close the thread.
    Again, thanks for the link.

    @Requinix, if I understood Kicken correct then comment and close this thread by making a comment handy for all future newbies.
    Last edited by UniqueIdeaMan; March 11th, 2018 at 10:51 AM.

IMN logo majestic logo threadwatch logo seochat tools logo