Unable to update a field to null/empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

Unable to update a field to null/empty

Post 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
Last edited by Benjamin on Mon Apr 27, 2009 10:13 am, edited 1 time in total.
Reason: Added code tags, type = php
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: Unable to update a field to null/empty

Post 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
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Re: Unable to update a field to null/empty

Post 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.
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

Re: Unable to update a field to null/empty

Post 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.
Post Reply