1

i have html/php code with form standard desing that includes textarea item. i can't find the way to add textarea content to a table in mysql database.

html/php

<form action="this_file.php" method="POST">
    <textarea class="inputcat" type="text" cols="40" rows="5" name="content"></textarea>
    <input type="submit" value="upload text" name="submit">
</form>
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'user', 'pass') or die(mysql_error());
$db = mysql_select_db('dbname', $con) or die(mysql_error());
    if(isset($_POST['submit'])){
        //insert the row into the database
        $contenido = $_POST['content'];
        $SQL = "INSERT INTO `table1` (`ct`) VALUE('" .$contenido. "')"; // syntax corrected here
        $result = mysql_query($SQL) or die(mysql_error());

    }
?>

thank you very much.

greetings.

11
  • Corrected your syntax error ... does the above work for you now? Commented Feb 12, 2012 at 18:35
  • no it's not. i'll see slowly much better. i'll tell you somthing. Commented Feb 12, 2012 at 20:04
  • there should be another " before the semi-colon on the $SQL line - it is missing above, I tried editing it about an hour ago but the edit wasn't put it place - I've tried again but this is a note to say where the correction should go Commented Feb 12, 2012 at 20:13
  • i dont understand your answer Commented Feb 12, 2012 at 20:19
  • $SQL = "INSERT INTO 'table1' ('ct') VALUE('" .$contenido. "')"; ... also, did you try print_r($_POST); to see what is being sent through?? Commented Feb 12, 2012 at 20:21

2 Answers 2

1

Perhaps try changing:

<form>

To:

<form action="name_of_this_file.php" method="post">

Nothing else really springs to mind from what I can see...

You could always do:

<?php
print_r($_POST);
?>

At the very top to see what exactly is coming into the page upon submit....

Sign up to request clarification or add additional context in comments.

1 Comment

Deleted my answer, as this basically answers the question, and a little better too.
0

Also change your query line to this, there is a syntax error in your code:

$SQL = "INSERT INTO `table1` (`ct`) VALUE ('$contenido')";

Consider looking at escaping data before inserting it into the database, more information here: http://www.php.net/manual/en/book.filter.php

Edit: Maybe you should also look at how you debug PHP: http://www.ibm.com/developerworks/library/os-debug/ - This will definitely save you a lot of time in the future.

1 Comment

Yep - just to echo the above, make sure you sanitize data input - we don't want any nasty SQL injections now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.