ikkyino Posted February 6, 2008 Share Posted February 6, 2008 Heylo, wondering if this would work..? i want an id so if i want to delete a row i can do it by id vs. names where i'll have duplicates... $sql="INSERT INTO movies (Title, Rate, Length)VALUES('$_POST[title]','$_POST[rate]','$_POST[length]')";$sql2 = "INSERT INTO movies (Id)VALUES ('mysql_insert_id()')"; i'm sure there's a better way, but i don't know it .. so help on how to do it would be great -Ikky Link to comment Share on other sites More sharing options...
Ingolme Posted February 6, 2008 Share Posted February 6, 2008 Heylo, wondering if this would work..? i want an id so if i want to delete a row i can do it by id vs. names where i'll have duplicates... $sql="INSERT INTO movies (Title, Rate, Length)VALUES('$_POST[title]','$_POST[rate]','$_POST[length]')";$sql2 = "INSERT INTO movies (Id)VALUES ('mysql_insert_id()')"; i'm sure there's a better way, but i don't know it .. so help on how to do it would be great -Ikky The way you're doing it, it will create two registers: one without an ID and one that only has an ID.If you want an ID for registers of the table you just need to add an ID field to it and give it the AUTO_INCREMENT feature. Link to comment Share on other sites More sharing options...
jhecht Posted February 7, 2008 Share Posted February 7, 2008 you just create a column in the table that is int unique not null auto_increment. USually you call this "id" Link to comment Share on other sites More sharing options...
ikkyino Posted February 7, 2008 Author Share Posted February 7, 2008 ahh, thank you very much! Link to comment Share on other sites More sharing options...
Synook Posted February 7, 2008 Share Posted February 7, 2008 The id field can also benefit from being PRIMARY KEY (speeds up table processing).id INT(6) NOT NULL PRIMARY KEY AUTO_INCREMENT Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.