How to limit a user to entering 10 keywords or less using PHP & MySQL?
Posted
by G4TV
on Stack Overflow
See other posts from Stack Overflow
or by G4TV
Published on 2010-06-14T20:10:22Z
Indexed on
2010/06/14
20:12 UTC
Read the original article
Hit count: 132
I'm trying to limit my users to entering at least 10 keywords and was wondering how would I be able to do this using PHP & MySQL with my current Keyword script?
Here is the add keywords PHP MySQL code.
if (isset($_POST['tag']) && trim($_POST['tag'])!=='') {
$tags = explode(",", $_POST['tag']);
for ($x = 0; $x < count($tags); $x++){
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$query1 = "INSERT INTO tags (tag) VALUES ('" . mysqli_real_escape_string($mysqli, strtolower(htmlentities(trim(strip_tags($tags[$x]))))) . "')";
if (!mysqli_query($mysqli, $query1)) {
print mysqli_error($mysqli);
return;
}
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT id FROM tags WHERE tag='" . mysqli_real_escape_string($mysqli, strtolower(htmlentities(trim(strip_tags($tags[$x]))))) . "'");
if (!$dbc) {
print mysqli_error($mysqli);
} else {
while($row = mysqli_fetch_array($dbc)){
$id = $row["id"];
}
}
$query2 = "INSERT INTO question_tags (tag_id, question_id, user_id, date_created) VALUES ('$id', '$question', '$user', NOW())";
if (!mysqli_query($mysqli, $query2)) {
print mysqli_error($mysqli);
return;
}
}
}
© Stack Overflow or respective owner