PHP + MySQL Database Insert Each Line

52

I know I've seen this on Stack Overflow before, but not sure how I would put it to use for myself. So basically I'm creating a generator. All I need done, is to figure out how to insert a new row into my database.

So basically, I have a textbox & submit button, when I click the submit button each line in the textarea will be inserted as a whole new row in the database.

`

        <textarea rows="4" cols="50" name="insert">

        </textarea>
            <br />
            <input type="submit" value="Enter" name="submit" />

`

36

Answer

Solution:

Let's say you have a table calledtblname with columntext, and you're sending the form value to$_POST['insert']. Usingmysqli (andpdo is really similar):

//authenticate to $conn
$stmt = $conn->prepare("INSERT INTO tblname (text) VALUES (?)")
$arr = explode("\n", $_POST['insert']);
$stmt->bind_param("s", $sentence);
for ($arr as $sentence)
{
    $stmt->execute();
}

People are also looking for solutions to the problem: php - Identify if user has watched a video

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.