I am trying to insert data into the database. It is a text area from html which looks like this where is says description. Everything else works fine.

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
        <form name="form2" method="post" action="uploadmachine.php" enctype="multipart/form-data">
        <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
        <td colspan="3"><strong> Upload New Machine </strong></td>
        <td width="300">Name the machine</td>
        <td width="100"><input name="machinename" type="text" id="machinename"></td>
        //This is the only issue
        <td> Description </td>
        <td><TEXTAREA NAME="Descrpition" ROWS=3 COLS=30 maxlength=100 ></TEXTAREA></td>
        <td> Upload picture </td>
        <td><input id="infile" name="infile[]" type="file" onBlur="submit();" multiple><td>
        <td><input type="submit" name="Submit" value="Upload"></td>

It take the description input to a php page called uploadmachine.php. From there the code looks like this,

$description = mysql_real_escape_string($_POST['Descrpition']);

//I echo $description to make sure the value is being carried over and it is.

echo $description;

//I am connected to the database

mysql_select_db("db", $con);
    mysql_query("INSERT INTO machinelist
    VALUES ('$fPath','$description','$machinename')");

Only the first row is of the description is put into the database. The descrption is being put into a column which is set to longtext. How can I save everthing the user types and how many spaces and enters he has typed?

Dear 'garyjohnson', I think you are talking about something like this:
The user enters:
hello this is

When echoing this, it will be displayed on one line only:
hello this isamirbwb

to fix this, you should use the function nl2br();

echo nl2br($description);

Hope this respond to your question.
NB: Same thing if you want to retrieve this from the database, save as $description, but echo it using nl2br()

Good Luck :)

I see what you mean by doing that, and im glad you showed me that cause I wouldn't have known that for the future. But I havent gotten that far yet.
The user enters:
Hello this is

its saved to $description in one line, but when its inserted into the database it only saves the first line, so it will only save 'Hello this is' The rest doesnt go into the database.

Thanks for your help!

Did you check if the description field in databse is set to Text and not varchar ?

Member Avatar

Can you show the code for retrieving the value from the DB?

I dont have a code to retrieve the value from the database, I have just been looking at the database directly to see if the data is in there. Will the database not show all of the data unless its called?

Member Avatar

Try displaying your DB values via php/mysql before you do anything else. phpMyAdmin should display the whole thing, but just try it to see what you get.

BTW - using 'multiple' parameter may be a bad idea - not compatible with IE. If it was, life would be easy :(

Wow thanks for that lol. Mysqlbuddy wasnt showing all the data but phpmyadmin was. But there is one problem. I put the data through the function nl2br() and it spaced it out correctly, but there is a " in the persons writing and when its saved to the database it is saved as â€.

Member Avatar

Ensure that your page encoding and DB collation / charset are utf-8 and utf8_unicode_ci / utf-8 respectively.

If you have php doing 'stuff' with the DB before the encoding meta tag in the head area, I'd set a header:

header('Content-Type: text/html; charset=utf-8');

Before any processing. It may help.

Your choice as to the encoding - but utf-8 / utf8_unicode_ci tends to be a good combo.

Thanks so much! That worked perfectly!