I have an application where my users can create something like an article. Now, I wan’t to limit the amount of articles written by each user.
I just don’t know how to do this – I could imagine that I should use: mysql_count_num_rows or something like that.
In my database I have a table called: opslag, where I have userid_bywho and user_bywho. I imagine that I should count how many times in the table a users ID is found, and if it’s above 5 the user should not be able to create the article.
I have the users ID’s in a SESSION.
I hope you can help me how to count how many times an ID is shown.
if(isset($_POST['title']) && isset($_POST['daystart']) && isset($_POST['address']) && isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['website']) && isset($_POST['content']))
{
if($_POST['title'] === ''){
$errMsg = "Du skal udfylde titel";
}
elseif($_POST['daystart'] === ''){
$errMsg = "Du skal udfylde start dag";
}
elseif($_POST['address'] === ''){
$errMsg = "Du skal udfylde adresse";
}
elseif($_POST['phone'] === ''){
$errMsg = "Du skal udfylde telefon";
}
elseif($_POST['email'] === ''){
$errMsg = "Du skal udfylde email";
}
elseif($_POST['website'] === ''){
$errMsg = "Du skal udfylde website";
}
elseif($_POST['content'] === ''){
$errMsg = "Du skal udfylde beskrivelse";
} else {
$sql = mysql_query("INSERT INTO opslag (userid_bywho, user_bywho, title, category, link, daystart, address, phone, email, website, content)VALUES('$userid_bywho', '$user_bywho', '$title', '$category', '$link', '$daystart', '$address', '$phone', '$email', '$website', '$content')")or die(mysql_error());
$add_success = "Dit opslag er oprettet.";
}
}
1 Answer