MySQL

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

MySQL

Post by dwfait »

Hi. I was wondering, how would i create one MySQL database, with one table, with three headers? user ID, username and password, through Cpanel?

and then if you could tell me how to add new values to these headers / get the current user id? like, check how many ID's there are, if there are none create one like:
userid:"1"
name:"name"
password:"password"

but if there allready is one make the new userid "2"

Thanks, if you could answer either one of these questoins you would be a great help.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

you should really get phpmyadmin
Fanstop.tk
Forum Newbie
Posts: 17
Joined: Wed Jul 21, 2004 11:02 pm

Post by Fanstop.tk »

best way: Use PHP code.

Code: Select all

<?php
$sql = "create table Guests (id int not null auto_increment primary key, Username varchar(25), Password varchar(25))";
mysql_query($sql) or die("Unable to create table");
?>
To add info, do this:

Code: Select all

<?php
$sql = "insert into Guests (Username, Password) values ('Insert Username here','Insert Password here')";
mysql_query($sql) or die("Unable to add information");
?>
Hope this helps.

One more thing, I would use METHOD="POST" on any forms submitting this info, then use the $_POST variable to attain the info... also, encrypt any incriminating data (password) so if the db is hacked, the data is safe.
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

Wouldnt you need to connect to the MySQL server and database first?
I would need the code for that, as i am a complete noob at PHP :-\. and also, why Guest?
burzvingion
Forum Newbie
Posts: 11
Joined: Sun Apr 18, 2004 2:30 pm

Re: MySQL

Post by burzvingion »

dwfait wrote:Hi. I was wondering, how would i create one MySQL database, with one table, with three headers? user ID, username and password, through Cpanel?
cPanel doesn't have any support for doing anything with databases, but phpmyadmin is very nice and free.

but if you want to do it all in php, search for mysql at php.net...
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

I would need the full PHP code needed to open up an MySQL database, open up a table in there, and search for a value in the field 'user' which is the same as the _POST method text entry via form 'user'.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Why not learn it yourself?
Or would you like us to move this to Volunteer work/Job hunt (if you're willing to pay)

This community is about helping people learn, not coding it for them ;)

Sorry if I sound harsh, it's 1am and ive gotten 6 hours of sleep in the last 42 hours.
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

heh, i am trying to learn from PHP builder's php manual, but its a bit confusing, however i have made progress. I have connected to my database, selected my table, i just want to search the table now to see if the user has entered right user/pass.

im really stuck on this, so if someone could tell me how to:
search for the entered username in the table (entered by form)
then see if entered password matches the password in the row of the matching username, assuming $user is entered username, and $pass is entered pass. This would be a great help.
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

Nevermind, i have figured it out :). I am using:

<?php
$link = mysql_connect("localhost", "root", "")
or die("Could not connect");


mysql_select_db("stormst_sspp")
or exit("Could not select database");

$result = mysql_query("SELECT user AND pass FROM sspp WHERE user='one' AND pass='one'")

or die ("Invalid query");
$num_rows = mysql_num_rows($result);
echo "$num_rows";
mysql_close($link);
?>
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Cpanel HAS phpmyadmin in it...
Post Reply