开发者

why when trying to inport to database more than 500 char i get error?

开发者 https://www.devze.com 2023-03-17 04:35 出处:网络
i have items in database but why when i am trying to import more than 500 char from a textarea i have error, the datatype of the field is TEXT

i have items in database but why when i am trying to import more than 500 char from a textarea i have error, the datatype of the field is TEXT

here is part of the the form

<?php 
//query to get the $ProductDesc and some other codes then
echo "<textarea name='p_desc' id='p_desc' class='input' rows='10' cols='53'>$ProductDesc</textarea>";
?>

then the form post in the same开发者_如何学Python page, then i get the value like this:

$a4 = $_REQUEST['p_desc'];

then i am trying to (update or add) the record,

i have error while importing, and it didn't take effect in updating

and this is my update query

mysql_query("UPDATE product SET ProductDesc='$a4' WHERE ProductID = $productID ");

please help and thanks in advanced, the error in PHP or what?

the form header:

<form name="myform" action="add-product.php" method="post" enctype="multipart/form-data">

am using enctype="multipart/form-data" because i upload images also every thing is good with exception of the textarea


Before your query add

$a4 = mysql_real_escape_string($a4);

In fact, you should call this function on any user-specified value going into a query. Not only can you produce errors such as what you have seen, but if were to specify the description as

'; DROP TABLE product; -- 

then you'd really be in trouble. This is known as SQL injection and is something you should be very careful of.


How do you have your ProductDesc field set up? is it varchar, mediumtext, longtext? I always use longtext and I have never had any problems with over 500 chars. Post your form, maybe you need to strip some characters out of the Description before it is submitted to the database.

and there was a little hiccup in there :D

instead of

<?php 
//query to get the $ProductDesc
<textarea name='p_desc' id='p_desc' class='input' rows='10' cols='53'>$ProductDesc</textarea>
?>

use

<?php 
//query to get the $ProductDesc
echo "<textarea name='p_desc' id='p_desc' class='input' rows='10' cols='53'>".$ProductDesc."</textarea>";
?>

and to fix the update or add function rewrite it so it checks if it is already there or not, then on a if statement add your query or update functions.

And when you hit submit on your form you have now what error does it tell you?!?

0

精彩评论

暂无评论...
验证码 换一张
取 消