Jump to content

mysql id..?


ikkyino
 Share

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...