I have just polished the code little bit.
index.php
: Here you will show the notifications.
<?php
$dbc = mysqli_connect('localhost','root','','dashboard') or die(mysqli_connect_error(''));
function notification(){
global $dbc;
$query = "SELECT `customer_id`, `customer_name` FROM `customer` WHERE `confirmation`IS NULL LIMIT 0, 30 ";
$result = mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result))
{
echo "<a href='CusRegReport.php?id=" . $row['customer_id'] . "'><i class='fa fa-users text-red'> " . $row['customer_name'] . " needs to register</i></a>";
}
}
?>
<!doctype html>
<html>
<body>
<?php notification(); ?>
</body>
</html>
CusRegReport.php
: Here you will show the details of the Customer with the particular id.
<?php
$dbc = mysqli_connect('localhost','root','','dashboard') or die(mysqli_connect_error(''));
function details(){
global $dbc; // we need this in all our functions. Then only we will be able to do the db operations within the function
$id = $_GET['id']; // we are using the id that was passed in the URL
$id = $mysqli->real_escape_string( $id ); // clean the id that the user passed via url, so that we could use it in our SQL query. Otherwise it is unsafe to use directly because it can lead to SQL injections
$sql = "SELECT * FROM `customer` WHERE `customer_id` = '$id'";
$r = mysqli_query($dbc,$sql);
while($line=mysqli_fetch_array($r))
{
echo "<br/>" . $line['customer_name'] . "<br/>" . $line['ad_line_one'] . "</a>";
}
}
?>
<!doctype html>
<html>
<body>
<?php details(); ?>
</body>
</html>
Things to remember:
You have declared the mysqli object $dbc
at the very top of the page. So if you want to use that object to access the db, from inside a function, you need to use the global
keyword like this: global $dbc;
Avoid excessive use of the keyword global
. You were using it to declare each variable! That's not needed.
When you echo the <a>
links to the customer details page, include the customer_id
in the url after a ?
. The data we pass like that, will be available in the $_GET
array at the resulting page.
Always try to use an integer value to identify the customer. Because more than one customer can have the same name! Since you are already having the details of the customer in your db, I believe you have used a PRIMARY KEY
for that table, which might be customer_id
, I guess. So use that.
Avoid unwanted concatenations. It could give confusions to you later. In your first echo
line, you have used lots of concatenations even though you were concatenating just the strings.
Try to escape the data that you accept from the user, before using it in your SQL queries. Because the data that the user provides may cause sql injection attacks. So always clean the user input.
These are just quick basic things for you.
Hope it will help.
NOTE: I only polished your code a little bit. No testing or anything done.