Hi Guys,
I am trying to create a php script that inputs the HTTP links pasted into a textarea into a separated row in a database. More exactly:
First page is where the textarea (name=textarea-linkfield)
is, links are going to be pasted here
http://www.stackoverflow.com
http://www.yahoo.com
....
http://google.com
The links are being carried over into the php script with $linkfield=$_POST['textarea-linkfield'];
and I would like the links to be inserted into the database, each http link per row. Database name: site, table name plow, columns: id, url, ...
L.E. I tried just as proof of concept:
$linkfield=$_POST['textarea-linkfield'];
$strip=explode("\n",$linkfield);
echo $strip[1];
but I get 500 INTERNAL SERVER ERROR
L.E.2
The answer:
// Split the string into pieces
$pieces = explode("\n", str_replace(array("\n", "\r\n"), "\n", trim($linkfield)));
// Build the top of the INSERT query
$sql = "INSERT INTO `plow`(`url`) VALUES\n";
// Build the rest of the ;INSERT query by re-assembling the
// pieces.
$sql .= "('";
$sql .= implode("'), ('", $pieces);
$sql .= "')";
mysql_query($sql) or die ('Error: ' . mysql_error());
mysql_close();
Thanks to all for their help. Chris.