Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,163,417 members, 7,853,820 topics. Date: Saturday, 08 June 2024 at 04:55 AM

Php: How To Display A Message To A Specific User ID Or User Name - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Php: How To Display A Message To A Specific User ID Or User Name (2514 Views)

[PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? / How Can I Get IP Of A Specific Hop For Traceroute In Python / PHP - How Does Nairaland's Frontpage Works (2) (3) (4)

(1) (Reply) (Go Down)

Php: How To Display A Message To A Specific User ID Or User Name by Markydave: 8:38pm On Feb 15, 2017
Gud day, am a newbie in php am trying to display a message to a specific user ID but don't know how to go about it I have tried

<?php
if
{
$user_id ==7
{
echo "hello there";
?>
But it not displaying anything and not giving any error. Please help me
Re: Php: How To Display A Message To A Specific User ID Or User Name by silento(m): 8:51pm On Feb 15, 2017
use the start_session()

and assign a new variable to $_SESSION[] arary
Re: Php: How To Display A Message To A Specific User ID Or User Name by CodeHouse: 8:55pm On Feb 15, 2017
Markydave:
Gud day, am a newbie in php am trying to display a message to a specific user ID but don't know how to go about it I have tried

<?php
if
{
$user_id ==7
{
echo "hello there";
?>
But it not displaying anything and not giving any error. Please help me

Of course this code won't display anything cos no condition has been met, besides you will need a session or fetch the user id from the database first and then you can check if the condition is met. Look at the post above by silento, that's what you should do first at user login, you can also read on php sessions
Re: Php: How To Display A Message To A Specific User ID Or User Name by Markydave: 11:04pm On Feb 15, 2017
silento:
use the start_session()

and assign a new variable to $_SESSION[] arary
thanks but I would prefer fetching from db can you help me with that
Re: Php: How To Display A Message To A Specific User ID Or User Name by Markydave: 11:12pm On Feb 15, 2017
CodeHouse:


Of course this code won't display anything cos no condition has been met, besides you will need a session or fetch the user id from the database first and then you can check if the condition is met. Look at the post above by silento, that's what you should do first at user login, you can also read on php sessions
thanks can you please help me on how to fetch from the db and display the message to only that user with id 7..abeg help me d tin dey turn my head am really new in this stuff
Re: Php: How To Display A Message To A Specific User ID Or User Name by silento(m): 2:18am On Feb 16, 2017
Markydave:
thanks but I would prefer fetching from db can you help me with that


what happened to reading tutorial before coding on a language

anyway

search this on Google

php tutorial filetype:pdf download the one from tutorialspoint.com read it well
after 2weeks come back and buy me. a beer
Re: Php: How To Display A Message To A Specific User ID Or User Name by CodeHouse: 8:17am On Feb 16, 2017
Markydave:
thanks can you please help me on how to fetch from the db and display the message to only that user with id 7..abeg help me d tin dey turn my head am really new in this stuff

Markydave glad to know that you are interested in programming and you might want to follow the advice given above, try to read on tutorials online so you can get a hang on it but below is what you need and I hope it is not too complex for you to understand. Note that I assume that you have included your database connection, hence the need for "$con" in the sample.

cheers

Re: Php: How To Display A Message To A Specific User ID Or User Name by trytillmake(m): 10:24am On Feb 16, 2017
Markydave:
Gud day, am a newbie in php am trying to display a message to a specific user ID but don't know how to go about it I have tried

<?php
if
{
$user_id ==7
{
echo "hello there";
?>
But it not displaying anything and not giving any error. Please help me



Simple yr code is all wrong: let me help small

<?php

$user_id = $_POST['userid']; // get id from form and pass to variable

if($user_id == "markydave"wink // compare variable

{
echo "hello markydave";

}


else if($user_id == "seun"wink // compare variable

{
echo "hello seun"; }


else { echo "hello User";} // default output

?>


PHP was my first language i learnr't so i always fall back to it when i wanna do a fast job no time to waste.
Re: Php: How To Display A Message To A Specific User ID Or User Name by CodeHouse: 11:07am On Feb 16, 2017
trytillmake:
Simple ye code is all wrong: let me help small

<?php

$user_id = $_POST['userid']; // get id from form and pass to variable

if($user_id == "markydave"wink // compare variable

{
echo "hello markydave";

}


else if($user_id == "seun"wink // compare variable

{
echo "hello seun"; }


else { echo "hello User";} // default output

?>


PHP was my first language i learnr't so i always fall back to it when i wanna do a fast job no time to waste.

Sorry, I didn't catch that, are you saying my code is wrong?
Re: Php: How To Display A Message To A Specific User ID Or User Name by trytillmake(m): 11:16am On Feb 16, 2017
CodeHouse:


Sorry, I didn't catch that, are you saying my code is wrong?

Hey bro, not yr code referring to the OP,
Re: Php: How To Display A Message To A Specific User ID Or User Name by CodeHouse: 11:28am On Feb 16, 2017
trytillmake:


Hey bro, not yr code referring to the OP,

cheers
Re: Php: How To Display A Message To A Specific User ID Or User Name by 0luwatope(m): 3:19pm On Feb 16, 2017
Youre going to need a working database for this. and a logged session. is google not working in ur area? better make a research my guy, it gon be lyk this
<?php

//lets say i have connfcted the sql. pl
$id=$_SESSION['USER'];

//this will get id of the user stored in a session dpdp

// a db to select n*me from user where id="$id"
this will fetch only name, then rep the name with $name

//then replace the hello user with hello $name

Pardon my typing and bad syntax, i am typing with a small tecno phone that has no clear button
Re: Php: How To Display A Message To A Specific User ID Or User Name by Nobody: 11:51pm On Feb 16, 2017
You need to paste your codes here, enough codes that can help someone easily identity the problem... I can't only assume a whole lot of things here....

However, assuming u already have a table in your database, and that the user login is through a form...

Hence, using simplified codes, without considering security, no PDO, etc...

<?php
//Check if login details was submitted and proceed
if(isset(POST['username']) && isset($_POST['password'])){
$username = trim(POST['username']);
$password = trim(POST['password']);

//Check for the login details in your database
$sql = "SELECT * FROM yourTable WHERE username = '$username' AND password = '$password' LIMIT 1 ";
$result = $db_conn->query($sql);

//Check if the sql query returned any row
if($result->num_rows>0){
//Assign the returned data to an associate array
$row = $result->fetch_assoc();

//get db id and assign it to $id
$id = $row['id'];

//Check if $id is 7?
if($id == 7){
echo "Welcome Mr. 7 <br>";
}else{
echo "Your id is not 7, get out! <br>";
}
}
}
?>

Note: I just typed away from my phone... I didn't run to check if any error...

cool

(1) (Reply)

Introduction To Crm Application Development Using Remedy / List Of Freely Available And Downloadable Programming Books From The Internet / Is Data Science Worth It In Nigeria

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.