Forum Moderators: coopster

Message Too Old, No Replies

modifying MySQL database with PHP

new guy seeks more help

         

coolo

7:58 am on Feb 17, 2004 (gmt 0)

10+ Year Member



ok, thanks to the friendly help of the people who frequent this forum, I can now pull info from MySQL databases using PHP. My next question is how would one use PHP and forms to add to or edit info in the same MySQL databases. If anyone knows of any good reading or tutorials, it would be much appreciated. Thanks in advance.

twist

9:22 am on Feb 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When I wanted to learn php/mysql I bought this book,

PHP fast&easy web development by Julie C. Meloni

(I would give you the ISBN but the price tag is covering it up.)

Anyway, it's not a advanced book and doesn't teach any really complicated stuff but it covered all the basic php mysql stuff I needed. Now I just use php.com and phpmyadmin.com to look up specifics, or here.

coolo

5:28 am on Feb 18, 2004 (gmt 0)

10+ Year Member


ok ok ok,
I figured out how to add, delete, and edit records in MySQL. Here is my more specific question than the previous post. I can delete records with no problem. However, I am having trouble adding posts as I'm having trouble automatically generating a primary key id. I have done a couple different things that work, but only if I never delete any records. Lets say for instance, if I have 6 records with id numbers 0-5, and I delete record #2. Then lets say I want to add another record. The id number that is generated automatically is #7, but MySQL puts it in the #2 spot, so the records are now numbered like this: 1, 7, 3, 4, 5, 6. This is throwing off my add record script which says to add 1 to the id number of the last record (in this case 6) in order to generate a new id number. But, this leaves me with a second id number of 7 and the second record doesn't get added to the table.

Does that make sense? Would it be easier if I posted my code? Any help is appreciated.

superpower

5:51 am on Feb 18, 2004 (gmt 0)

10+ Year Member



ID field should be primary key and auto-incremented. It sounds like you are not auto-incrementing.

[edit: misspelling]

coolo

6:34 am on Feb 18, 2004 (gmt 0)

10+ Year Member


ok, id is primary key, and I thought it was supposed to be auto incremented at first, but couldn't find/figure out how to do it, so I set about trying other ways around the problem. Can anyone point me in the right direction on how to auto increment the primary key id. thanks.

RonPK

8:58 am on Feb 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The mysql command would be like
ALTER TABLE `table_name` CHANGE `id` `id` AUTO_INCREMENT

I recommend using phpmyadmin for this kind of database administration tasks. It's great.

slade7

3:15 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



I would definitely suggest trying phpmyadmin. Makes much of the basic stuff easy.

Once you get your column set as auto-increment, always insert the primary key value as '0' and it will give you the next number automatically.

coolo

7:14 pm on Feb 19, 2004 (gmt 0)

10+ Year Member



When you create the table, is it possible to specify that the primary key should be auto incremented or do you have to use the ALTER TABLE command to do that.

jatar_k

7:25 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



CREATE TABLE [mysql.com] sometable (
tbl_id int(4) PRIMARY KEY AUTO_INCREMENT,
etc ....

coolo

7:52 pm on Feb 19, 2004 (gmt 0)

10+ Year Member



thank you much.