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);
?>