There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Please Help Me My SQL


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
dudeking's Avatar
Computer Specs
Senior Member with 350 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: I'm Pro...
11-Jul-2007, 09:14 AM #1
Please Help Me My SQL
Right I need to use mysql.

If some one would please post a PHP script that connected to a sql database, stored a value in the database then echo the value back out of the database.

If I saw a script that did that I would be able to start using my sql with my site. I just have no clue where to start at the moment.


Thank you soooo much any one who does this for me
__________________
Thanks, Eddie
www.dudeking.co.uk
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
11-Jul-2007, 11:37 AM #2
Put together from http://www.w3schools.com/php/php_mysql_intro.asp
You can learn almost all there is to know there.
PHP Code:
<?php
$con 
mysql_connect("localhost","dbuser","dbpass");
if (!
$con)
    die(
'Could not connect: ' mysql_error());

mysql_query("CREATE DATABASE my_db",$con);
mysql_select_db("my_db"$con);
$sql "CREATE TABLE person 
(
FirstName varchar(15),
LastName varchar(15),
Age int
)"
;
mysql_query($sql,$con);
mysql_query("INSERT INTO person (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");
mysql_query("INSERT INTO person (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')");
$result mysql_query("SELECT * FROM person");
echo
"<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>"
;

while(
$row mysql_fetch_array($result))
{
    echo 
"<tr>";
    echo 
"<td>" $row['FirstName'] . "</td>";
    echo 
"<td>" $row['LastName'] . "</td>";
    echo 
"</tr>";
}
echo 
"</table>";
mysql_close($con);
?>
In this code I create a db, a table, and two rows.

You should only have to do that once.
dudeking's Avatar
Computer Specs
Senior Member with 350 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: I'm Pro...
11-Jul-2007, 06:20 PM #3
thank you sooo much

I owe you one mate!!
dudeking's Avatar
Computer Specs
Senior Member with 350 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: I'm Pro...
12-Jul-2007, 06:27 AM #4
so do i have to have some code to check if the table and rows are already there?
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
12-Jul-2007, 07:01 AM #5
Add IF NOT EXISTS

Example:

PHP Code:
$sql "CREATE TABLE IF NOT EXISTS person 
(
FirstName varchar(15),
LastName varchar(15),
Age int
)"

dudeking's Avatar
Computer Specs
Senior Member with 350 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: I'm Pro...
12-Jul-2007, 10:13 AM #6
Okay, so right, I want to create user account for my site.

Do I have a separate row for each member then. So a registration form people enter info and its exported to a row on the members table. Some one comes to the site, it sees there is no cookie for the site, so it says login instead of saying welcome 'Your Name'. Then people click login enter there username and password, now this is the bit im stuck on. Do i need to seach the database for that username then see if the password matches up? Or is there some other more secure way to do this?
__________________
Thanks, Eddie
www.dudeking.co.uk
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
12-Jul-2007, 12:52 PM #7
You will do something like mysql_query("SELECT * FROM users WHERE username = $_POST['username'] AND password = $_POST['password']")

Don't use that code though, it might be incorrect and will definitely be a security risk.

There are hundreds of tutorials on the net about this issue. Google is your friend!
JRWalker's Avatar
Computer Specs
Member with 43 posts.
 
Join Date: May 2007
Location: Cache Valley
Experience: Intermediate
15-Jul-2007, 11:10 PM #8
Yes, you will need a row for each member. In the database you will have a username and password field. The password field should be varchar, 32 characters long. To be more secure, you will want to encrypt what the user enters into the password text box using md5 encryption. This encrypted password will be stored as a 32 character long hash. When you check to see if the username and password match up, you compare the md5 hash from the password field with the md5 hash in the database, that way no plain text password will be stored. It might also be wise to use session variables that are persistent across pages, start your pages with <?php $session_start; ?>. You can store variables in the session with the following:
<?php $username = $_SESSION['username']; ?> With this method you can access the username from different pages.
__________________
The Striding Man
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
15-Jul-2007, 11:43 PM #9
That would be session_start(), and $_SESSION['username'] = $username.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:24 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.