Help making a table with PHP
Ok I am new to php and need a little help. I want to make a script to rate an article and let someone leave comments. When the script is called with and article ID# I want to check if the file fileID# exists and if not create it. The database fields would basicly be rating, userID, and comment. With userID being the Primary key. How would I test for existence of the database and create it if necessary? (also if I allow anon users would IP address make a good key? would IP address be a unique value?) Thanks!
Todd Sampson
www.Royal7Casinos.com - bringing
you the top online casinos
Mark Hensler posted this at 04:29 — 15th April 2001.
He has: 4,048 posts
Joined: Aug 2000
userID being the Primary key
I would recommend agains this. I always use ID as the primary key, and I never make a table withouth ID.
To check to see if something exists, and create if not, you will need two queries.
$query = "SELECT * FROM table_name WHERE field_name=value";
$result = mysql_query($query);
if (!$result) {
$query = "INSERT INTO table_name (field_names) VALUES(values)";
mysql_query($query)
}
No, IP would not make a good UNIQUE field. I am behind a router... the internet only see's 1 IP, but there are actually 3 PCs on the network, all online. Again, I would advise using ID as a UNIQUE field.
Mark Hensler
If there is no answer on Google, then there is no question.
Mark Hensler posted this at 04:06 — 17th April 2001.
He has: 4,048 posts
Joined: Aug 2000
BTW, welcome to TWF!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.