I have been looking all over the internet for a tutorial or something.
here is my code, basically, it does this:
splits some information into an array, and inserts each seperate array value into a table on my database...
only problem is:
When im hitting submit... it just loads.. and loads... and loads... then finally it says that it ran out of time
help? or a snippet of code to shorten this? or a pointer in the right direction would be greatly appreciated.
here is my code, basically, it does this:
splits some information into an array, and inserts each seperate array value into a table on my database...
only problem is:
When im hitting submit... it just loads.. and loads... and loads... then finally it says that it ran out of time
PHP:
<?php
//array values form
$form = '<form method="post" action="splitstring.php">
<textarea name="textfield" cols="30" rows="20"></textarea>
<input type="submit"/>
</form>';
echo $form ;
//split form value into array
if($_POST["textfield"]!=""){
$keywords = $_POST["textfield"];
$keywords = split("[\n]+", $keywords);
// Connect to the database
$DB = mysql_connect("localhost", "root", "");
mysql_select_db("database", $DB);
// Create the qyery string
$query = "INSERT INTO table(word) VALUES";
// Loop through the array
for($i = 0, $c = count($keywords); $i < $c; $i + 1) {
// Add the next batch of values to the query string
$query .= "({$keywords[$i]})";
// Add a comma is this is not the last batch
if($i + 1 < $c) {
$query .= ", ";
}
}
// Execute the query
$RESULT = mysql_query($query, $DB);
// Check the results
if(!!$RESULT) {
echo "Query was successfull";
}
else {
echo "Query failed
<blockquote>". $query ."</blockquote>
<blockquote>". mysql_error($DB) ."</blockquote>";
}
}
?>
help? or a snippet of code to shorten this? or a pointer in the right direction would be greatly appreciated.