Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page Talking with a data base using PHP
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 12-22-2003   #1 (permalink)
bignester
Linux User
 
Join Date: Apr 2003
Location: TEXAS
Posts: 314
Send a message via AIM to bignester Send a message via MSN to bignester
Talking with a data base using PHP

I'm starting a project where I'll be making a Movie database. I want it to be accessable over the web. How would I communicate with the database using PHP.

Also what would be the best method to implement user login.
__________________
The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
\"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)
bignester is offline   Reply With Quote
Old 12-22-2003   #2 (permalink)
andutt
Linux Engineer
 
Join Date: Apr 2003
Location: Sweden
Posts: 796
You have a much functional API in PHP to communicate with many kind of databases. The best way to se the syntax of what kind of database you shall use is to look at the php manual.. look here http://se2.php.net/manual/en/... To connect to a mysql-database, you do like this for example...

Code:
$link = mysql_connect("$HOST", "$USER","$PASS") or die ("Could not connect to DB");
mysql_select_db("$DB") or die ("Could not select database:$DB check username or password or if database are up and running\n");

$query = "select * from my supertable";
$result   = mysql_query($query) or die ("Failed to execute SQl-query\n");
Fo user authentication you can write your own in php if you like or use apache:s authentication if you are using an apache-webbserver.

Good luck...just post if you get in to trouble..
__________________
Regards

Andutt
andutt is offline   Reply With Quote
Old 12-24-2003   #3 (permalink)
bignester
Linux User
 
Join Date: Apr 2003
Location: TEXAS
Posts: 314
Send a message via AIM to bignester Send a message via MSN to bignester
Alright thanx for the direction now I have a question about sessions and cookies. I want to have users log into the web page. So should I just use a users table that will have a users name and password. How would I check to make sure they loged in with the right pass and name. Also How can I make it so that when they leave and come back They will still be logged in.
__________________
The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
\"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)
bignester is offline   Reply With Quote
Old 12-25-2003   #4 (permalink)
Dolda2000
Linux Guru
 
Join Date: Oct 2001
Location: Täby, Sweden
Posts: 7,575
The easiest approach is indeed to create a table which stores usernames and (optionally encrypted) passwords. When authenticating users, just compare what they gave in the login form with what is in the database. Then create a session using something like the following:
Code:
session_start();
$_SESSION["username"] = $_POST["username"];
After that, you can check the existence of a valid session by checking the value of $_SESSION["username"]. Remember that you must call session_start() on each page that wants to use the session data.
See http://www.php.net/manual/en/function.session-start.php for more info.
Dolda2000 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:44 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0