i am fairly new to php and have recently encountered a problem.
I have created a comment box on my website using PHP and MySQL and it works fine but there is one major issue. The comment is only rendered on the website/stored in the database when it fits into one row of the html comment box. Whenever i enter longer text it simply won't save anything.
Here is the code i used:
<?php
mysql_connect("localhost","x","x");
mysql_select_db("fendersh_cdreviews");
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
$dbLink = mysql_connect("localhost", "x", "x");
mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
if($submit)
{
if($name&&$comment)
{
$insert=mysql_query("INSERT INTO cdreviews (name,comment) VALUES ('$name','$comment') ");
}
else
{
echo "please fill out all fields";
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form action="cds.php" method="POST">
<table style="margin-left:15px; background-color:none; border-top: 1px dotted black; border-bottom: 1px dotted black; padding-bottom:5px;">
<tr><td><p style="margin-bottom:-20px;">Name:</p> <br><input type="text" name="name"/></tr>
<tr><td colspan="2"><p style="margin-bottom:-5px;">Comment:</p> </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="3" cols="50"></textarea>
<tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr>
</table>
</form>
<?php
$dbLink = mysql_connect("localhost", "x", "x");
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
$getquery=mysql_query("SELECT * FROM cdreviews ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
echo "<p><b>$name</b>; $comment </p>"
;}
?>
I have replaced the user_name and password with an X for security reasons.
That's the code i'm using and it works fine.
It connects to the database alright; I have set my column parameter into TEXT.
Is there anything I should change there?
Hope someone can help me further with this.
Regards
Jack