php mysql problems
Moderator: General Moderators
- cheatboy00
- Forum Contributor
- Posts: 151
- Joined: Sat Jun 29, 2002 10:36 am
- Location: canada
- Contact:
php mysql problems
I'm creating a script that allows you to become a member of my site. the problem is my id colum doesnt count the number of members. now i'll bet i'm the person with the least amount of experience in php and mysql. but ould you help me out. my script looks like this:
$a = mysql_query("SELECT MAX(id) FROM users");
$c .= $a +1;
(note: $c is the variable that goes into the id coloum)
I've tried many different ways but none of them work they dont count each person, like sometimes it'll be 0 when i go look at the table or 1 but it doesnt go futher than that.
i know theres other ways to do it i just dont know how, theres somethign to do with the auto_increment but i got no idea how to do that....
any help you can give would be greatly apreciated
note: oops i just realized that this should be in the database forum, oh well...
$a = mysql_query("SELECT MAX(id) FROM users");
$c .= $a +1;
(note: $c is the variable that goes into the id coloum)
I've tried many different ways but none of them work they dont count each person, like sometimes it'll be 0 when i go look at the table or 1 but it doesnt go futher than that.
i know theres other ways to do it i just dont know how, theres somethign to do with the auto_increment but i got no idea how to do that....
any help you can give would be greatly apreciated
note: oops i just realized that this should be in the database forum, oh well...
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
CREATE TABLE users (
fid TINYINT not null AUTO_INCREMENT,
username varchar(20) UNIQUE NOT NULL,
password varchar(20) NOT NULL,
email varchar(20) NOT NULL,
aim varchar(16) NOT NULL,
profile varchar(255) NOT NULL,
PRIMARY KEY (fid)
);so then you could do that and then try...
$query = mysql_query("SELECT * FROM users ORDER BY fid DESC LIMIT 1");
and that would return the whole row of the latest user
...
Code: Select all
$a = mysql_query("SELECT COUNT(id) FROM users");
$c .= $a +1;But this is realy not the best way to work with MySQL. Why don't you try a "program" (script) like phpMyAdmin.
Than you can simply add auto_increment on id field in your table, and you won't have to run extra querys for id field...
BTW: If you are interested in learning SQL, try this link:
http://www.w3schools.com/sql/
- cheatboy00
- Forum Contributor
- Posts: 151
- Joined: Sat Jun 29, 2002 10:36 am
- Location: canada
- Contact:
thats where i learned what little mysql i know i think i should go back and see what i missed...
to bad i cant try any of these ideas out my host is down... this amazese me the host that i use like never goes down i've heard of it going down but i guess this is the first time in a long time it acutally went down meah
thanks for all the help
to bad i cant try any of these ideas out my host is down... this amazese me the host that i use like never goes down i've heard of it going down but i guess this is the first time in a long time it acutally went down meah
thanks for all the help
...
O, and why don't you write SQL querys like this:
It's better becaose you get error message if there is an error in your syntax...
Code: Select all
$a = mysql_query("SELECT COUNT(id) FROM users") or die ("Error:<br />" . mysql_error() );
$c .= $a +1;- cheatboy00
- Forum Contributor
- Posts: 151
- Joined: Sat Jun 29, 2002 10:36 am
- Location: canada
- Contact:
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- cheatboy00
- Forum Contributor
- Posts: 151
- Joined: Sat Jun 29, 2002 10:36 am
- Location: canada
- Contact:
well i do have one.
its on my online control panel from my host. the control panel they give you is on a different server which is cool that way i can still work somewhat on my site if they go down.
so i just went there and did your version of the answer (hob goblin). and i inserted a few new rows and it worked thanks
its on my online control panel from my host. the control panel they give you is on a different server which is cool that way i can still work somewhat on my site if they go down.
so i just went there and did your version of the answer (hob goblin). and i inserted a few new rows and it worked thanks
...
Yes, it is to tell where you went wrong...see that alot, i was going through some things on php.net in their manul and i see they have an "or die" after every line they produce whats with that. is that to tell where you went wrong in the code?
yes, for information, but for creating databases nad tables I use phpMyAdmin... but for inserting, updating, the information in these tables I use SQL. Of course I won't insert informations manual... waste of time ...also personally, i use phpmyadmin just for creating tables and overviewing them. and i let my scripts handle the information.