Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

HOW TO FETCH VALUES?

Featured Replies

IM USING PHP and mysql DB

and i have a logon page but i want it to logon then display a value of a column for that user

MY DB STRUCTURE

 

USER | AMMNT.

 

john 589146

phlip 456477

dabcde 77777

 

I want it so that when i click logon JOHN it will display the certain ammnt. in the ammnt. column for that user TIA~

Assuming you already have your logon script, something along these lines should generate what I think you mean:

(Note this script will not log you in - this script is assuming you already have logged in and you're on some kind of "welcome" page). If you don't have a logon script yet, i'll be happy to give you some advice on writing one too.

 

<?php

$dbhost='localhost';
$dbusername='YOUR_USERNAME';
$dbpassword='YOUR_PASSWORD';
$dbname='YOUR_DATABASE_NAME';

global $user // Assuming that the user variable has been sent from the login page in one way or another, or possibly selected from the session ID. If you need this explaining or need to know how to do this, just ask :).

$Link=mysql_connect($dbhost,$dbusername,$dbpassword) or die ("Couldn't connect to server.");
$Connection=mysql_select_db($dbname,$Link); 
	$Query ="SELECT USER,AMMNT FROM TABLE_NAME WHERE USER='$user'";
	$Result=mysql_query($Query) OR die("Sorry, Could Not Check For User."); 
$Num = mysql_num_rows($Result); 

If ($Num=1)
{

while($Row = mysql_fetch_array($Query))
 {
 echo $row['USER'] . " " . $row['AMMNT'];
 echo "<br />";
 }
}
else
{
echo "No such user found!";
}
mysql_close($Link);
?>

 

:)

 

B.

  • Author

tnx can you also help me for a logon script

the logon screen only needs acct.ID to be entered no password

thanx can you teach me step by step on what to do with these scripts?

in the while loop you need to change '$query' for '$result'.

 

I always do that myself, its a pain in the ass haha

Assuming you already have your logon script, something along these lines should generate what I think you mean:

(Note this script will not log you in - this script is assuming you already have logged in and you're on some kind of "welcome" page). If you don't have a logon script yet, i'll be happy to give you some advice on writing one too.

 

<?php

$dbhost='localhost';
$dbusername='YOUR_USERNAME';
$dbpassword='YOUR_PASSWORD';
$dbname='YOUR_DATABASE_NAME';

global $user // Assuming that the user variable has been sent from the login page in one way or another, or possibly selected from the session ID. If you need this explaining or need to know how to do this, just ask :).

$Link=mysql_connect($dbhost,$dbusername,$dbpassword) or die ("Couldn't connect to server.");
$Connection=mysql_select_db($dbname,$Link); 
	$Query ="SELECT USER,AMMNT FROM TABLE_NAME WHERE USER='$user'";
	$Result=mysql_query($Query) OR die("Sorry, Could Not Check For User."); 
$Num = mysql_num_rows($Result); 

If ($Num=1)
{

while($Row = mysql_fetch_array($Query))
 {
 echo $row['USER'] . " " . $row['AMMNT'];
 echo "<br />";
 }
}
else
{
echo "No such user found!";
}
mysql_close($Link);
?>

 

:)

 

B.

 

What a mess...

 

<?php

$dbhost='localhost';
$dbusername='YOUR_USERNAME';
$dbpassword='YOUR_PASSWORD';
$dbname='YOUR_DATABASE_NAME';

global $user // Assuming that the user variable has been sent from the login page in one way or another, or possibly selected from the session ID. If you need this explaining or need to know how to do this, just ask :).

$Link = mysql_connect($dbhost,$dbusername,$dbpassword) or die ("Couldn't connect to server.");
$Connection = mysql_select_db($dbname,$Link);
$Query = "SELECT USER,AMMNT FROM TABLE_NAME WHERE USER='$user'";
$Result = mysql_query($Query) OR die("Sorry, Could Not Check For User.");
$Num = mysql_num_rows($Result);

if ($Num==1){

while($Row = mysql_fetch_array($Result)){
  echo $Row['USER'] . " " . $Row['AMMNT'];
  echo "<br />";
}

}else{
echo "No such user found!";
}

mysql_close($Link);
?>

haha I couldn't have put it better myself.

 

I can't believe some one posted code a) that bad and B) that doesn't actually work!

Seen as you've tripped me up on a few things, i'm going to put you straight;

Just to point out, that code was typed quickly as an example. As such, I did not check for errors, flaws, mistakes ect.

I also did not check to see whether it worked, I was in a rush.

 

It was not intended for use, it was intended as a demonstration. That's why it was a mess ;) - However, Yes, Good layout in code is important.

Feel free to point out the errors in it, but there's no need to criticise the poster - especially if they were not commited to the task (But hey, I suppose that could be my fault for helping in the first place without checking what I had written -_- ). But from what I can see, you've done nothing more than change one or two lines and some capital letters on some variables. I noticed you also did abit of moving, but to point out again, the moving you did would have no effect at all. Moving "{" onto the same line as the "if" for example, rather than below it makes no difference at all. If its a personal habbit of yours, go ahead, but don't fault me on it.

while($Row = mysql_fetch_array($Query))
{

You were right to change it to "$Result", I'd made a mistake with the variable I'd saved on the clipboard and pasted it in by accident. It was also probably not the best idea to use a while loop in such a program since there should only be (or atleast I assume there should be) one entry, but in this instance I included it because I am unaware if how the webmasters (Philipc) system will work.

 

Good Day.

Seen as you've tripped me up on a few things, i'm going to put you straight;

Just to point out, that code was typed quickly as an example. As such, I did not check for errors, flaws, mistakes ect.

I also did not check to see whether it worked, I was in a rush.

 

It was not intended for use, it was intended as a demonstration. That's why it was a mess ;) - However, Yes, Good layout in code is important.

Feel free to point out the errors in it, but there's no need to criticise the poster - especially if they were not commited to the task (But hey, I suppose that could be my fault for helping in the first place without checking what I had written -_- ). But from what I can see, you've done nothing more than change one or two lines and some capital letters on some variables. I noticed you also did abit of moving, but to point out again, the moving you did would have no effect at all. Moving "{" onto the same line as the "if" for example, rather than below it makes no difference at all. If its a personal habbit of yours, go ahead, but don't fault me on it.

while($Row = mysql_fetch_array($Query))
{

You were right to change it to "$Result", I'd made a mistake with the variable I'd saved on the clipboard and pasted it in by accident. It was also probably not the best idea to use a while loop in such a program since there should only be (or atleast I assume there should be) one entry, but in this instance I included it because I am unaware if how the webmasters (Philipc) system will work.

 

Good Day.

 

I appreciate what your saying but (IMO) it's never a good idea to post code that doesn't work, irrelevant of whether it's a demo or not.. I only moved the curlies whilst I was tidying it up so I could read it better when I was making ammends; as mentioned above white space in php is irrelevant!

touchey touchey

I'm not being touchey - I'm defending myself.

 

I appreciate what your saying but (IMO) it's never a good idea to post code that doesn't work, irrelevant of whether it's a demo or not.. I only moved the curlies whilst I was tidying it up so I could read it better when I was making ammends; as mentioned above white space in php is irrelevant!

 

Yeah, No problem. I understand the point you've made. Like said, I was in a rush and it was my own fault that I didn't check it worked, I probably should of saved it for later, tested it then posted it. Oh btw, I have just noticed I did miss an "=" sign out of the "if" execution, so thanks for placing that back in :blush1: . I was still in HN mode when I typed it, where it only requires one "=" :lol:

 

Thanks for your input Skidz.

Sorry If I came across in the way I did.

No doubt I and PhilipC appreciate it. :)

I'm not being touchey - I'm defending myself.

 

 

 

Yeah, No problem. I understand the point you've made. Like said, I was in a rush and it was my own fault that I didn't check it worked, I probably should of saved it for later, tested it then posted it. Oh btw, I have just noticed I did miss an "=" sign out of the "if" execution, so thanks for placing that back in :blush1: . I was still in HN mode when I typed it, where it only requires one "=" :lol:

 

Thanks for your input Skidz.

Sorry If I came across in the way I did.

No doubt I and PhilipC appreciate it. :)

 

 

Your if() was "If()" which didn't work too... I wasn't having a personal dig at you or anything... Glad we cleared it up!

touchey touchey

 

Well at least SLGWN2P took the time to write it! It says more than most people on this forum, myself included. It's hardly fair to run him down for helping. One can only try.

 

Man, what is it with forums! You wouldn't treat people like this in real life, so why abolish manners and people skills just because it's the internet!

Your if() was "If()" which didn't work too... I wasn't having a personal dig at you or anything... Glad we cleared it up!

 

Oh I know you weren't having a personal dig :lol: Don't worry.

Yeah, the "if()" was "If()" because like I said, I was still in HN mode (Incase you weren't aware that's another language). Any programmer will tell you, And i'm sure you've experienced this too, you some times make stupid mistakes like putting the totally wrong language into the wrong program. So my reasoning was I only did one "=" and did "if" the way I did because I was still thinking HN lol. Never mind though, the mistakes were minor and easily corrected. I'm glad we sorted it out. :)

whats hn? Never heard of it before and can't get much off google...

 

I often make the mistake of putting asp/c# into my php and vice versa... Nasty habit to have... Always check thoroughly is my advice ;)

HN, It's a sort of HyperCard language (Similar to it anyway).

 

It's called "HyperNext". I tend to build prototypes in it before I write them in C++. Good for Cross-Platform demonstrations too. It's a good visual aid ect. We also used it to create dummy training applications for awhile but not so much anymore. :lol:

It's very good.

  • Author

Sorry for the late reply guys been busy. . .

 

I appreciate all your replies and cleaning the code

but i eed a detailed step by step tutorial

and i would also appreciat it if someone could teach me how to make a login page

not asking for much are you ? haha

 

Use sessions for your login page, theres loads of tutorials about them on the internet just google it.

 

Basically you have your login form, when someone fills it in and presses send this will send the entered details to a login script that will check the user and password against a stored one. If its correct you start a session using some random value. You then check for this session value every time you do something that requires the user to be logged in.

 

Heres a basic tutorial:

 

http://www.tizag.com/phpT/phpsessions.php

 

Just dive in and try it, its really not that difficult

  • Author

Thanx for the reply but i dont know what to save these codes as

could you please post the codes here and what to do with them

 

TIA~PHILIPC

perhaps you should look into the basics of PHP / forms rather than just relying on forum members to do the work for you?

  • Author

I do actually have several training videos on PHP

I was just hoping someone could further explain it bec. its a bit confusing

I am starting to understand it a bit now though. . .

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.