I want to explode a string with a space, check whether the word already exists. If not, insert each piece into multiple rows in mysql db. I've tried this before...
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
include("connect.php");
$counter = 0;
$counters = 0;
$string = mysql_real_escape_string($_POST['words']);
$arr = explode(" ",$string);
foreach($arr as $str) {
$sql = mysql_query("SELECT * FROM unicode WHERE word = '$str'") or die (mysql_error());
if (mysql_num_rows($sql) == 0) {
$sqli = mysql_query("INSERT INTO unicode (word) VALUES ('$str')") or die (mysql_error());
$counters++;
} elseif (mysql_num_rows($sql) > 0) {
$counter++;
}
}
header("Location: ../addspellwords?success=457394056369&entered=$counters&duplicates=$counter");
}
?>
This is too too too much slow....
Is there any other way to do this?
Thanks.
wordcolumn in tableunicodebe unique?}at the end. Is it intended?