Jump to content

Recommended Posts

I have tried using the code below which i found in another post however nothing writes to the database.

 

if ($_POST['submit'])
{
$values = $_POST['textarea_name'];
$array = split("\r\n", $values);
foreach($array as $line)
{
	mysql_query("INSERT INTO table_name('field_name') VALUES($line)");
}
}

Field identifiers are not strings (are not surrounded by quotes) in SQL.

 

You should also enable error reporting when developing and always attempt to catch errors in your code, you have done nothing to check if your query succeeded or to indicate why it has failed.

split

From manual> Warning

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

 

 

Doesn't mean it won't work. It's as thorpe stated, quoting the wrong value and no error catching.

 

if (isset($_POST['submit'])) {
    $lines = split("\r\n", $_POST['textarea_name']);
    if(!empty($lines)) {
        foreach($lines as $line) {
            mysql_query("INSERT INTO table_name(field_name) VALUES('".mysql_real_escape_string($line)."')") or trigger_error('MySQL: '.mysql_error(), E_USER_ERROR);
        }
    }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.