Page 1 of 1

Unable to update a field to null/empty

Posted: Mon Apr 27, 2009 8:15 am
by Monopoly
Greetings, I use PHP and MySql. At first glance, the following lines seem to lack any problems, well actually they do. When I test them in my environment they work well, except when I try to "delete" the string, thus setting it to empty. When I set it to null/empty it doesn't change at all, I mean it remains the same. When I change it to another not empty string it works well.

Code: Select all

 
$sign = $_POST['sign'];
 
if ($sign != $_SESSION['sign']){
 
$instruct = "UPDATE $table SET sign='$sign' WHERE user='$user'";
$res = mysql_query($instruct);
  $alert_string = "<small>Signature has been updated</small>";
$_SESSION['sign'] = $sign;
 
and:

Code: Select all

 
<td height=40>Semn?tura:</td> <td><input class="red" name="sign" type="text" id="sign" MAXLENGTH=100 SIZE=70 value="<?php echo $_SESSION['sign'];?>"></td>
 
I'll be very thankful to the lad that helps me

Re: Unable to update a field to null/empty

Posted: Mon Apr 27, 2009 9:43 am
by jazz090
the method u r using is wrong:

i do not recomend using superglobals in the script, the best practice would be to assign them to a variabe and work with them instead. so in there isnetad of checking $sign against $_POST['sign'], before hand assign $_POST['sign'] to a var e.g. $incoming_sign = $_POST['sign'] and then in ur script check $sign against $incoming_sign then at the end assign $incoming_sign to $sign and output it in ur html but (unrealted really) make sure u take action against cross site scripting before u echo into html as echo $_POST['sign'] is just as good as website suicide!


peace out

Re: Unable to update a field to null/empty

Posted: Mon Apr 27, 2009 10:10 am
by user___
I seem to have misunderstood what are you trying to delete? I suppose it is the SESSION var. For that purpose there is
http://bg.php.net/manual/en/function.unset.php
You can either use session_destroy http://bg.php.net/session_destroy but it will destroy all the SESSION data.

Re: Unable to update a field to null/empty

Posted: Mon Apr 27, 2009 10:42 am
by Monopoly
I meant "delete" as in deleting the text that comes in the form, in order to set the variable to null or empty after submitting.