HTML / PHP problem .. pls help ?? thanks!!

  Mary_S 16:15 14 Nov 2006

Dear All,

I have an html form which posts inputted data to a php script which updates accordingly to a mysql database.

My problem is as follows;

A have a text box 'z' in the form.
In the PHP script I have an update statement which will add 1 to the total in column 'y' if theres a value given in text box 'z'.

I have tried two methods to achieve this but neither worked as I wish.

My first method was to simply set a condition ;

if ($z) { // mysql update column 'y'

If I use a number 1 or above in $z it will carry out the bracket statements , if i leave it empty it will not do so, which is wat i want.

BUT , if i was to submit 0 in the text box i want it to carry out the nested staements but it doesnt.

I also tried ,
if ($isset($z)) { // mysql update column 'y'
However , this doesnt work as i wish because regardless of what i enter in text box 'z' ... ( a number , 0 , empty) it will carry out the curly brackets.

Basically, i wish to write the code so for any value entered including 0 it will implement the brackets , but if left empty it will not do so.

Sorry for going on , but i wanted to write clearly what my problem is to save everybodys time lol.

Thanks in advance


  beynac 17:13 14 Nov 2006

Try this. It's a bit clumsy because you have to make sure that $z is null not just empty(e.g. not "").

$z = 0;
if (is_null($z) == false) {
print ("It's there!\n");
} else {
print ("It's NOT there!\n");

  beynac 17:44 14 Nov 2006

I missed a line out. You have to set the variable to 'NULL' if it's empty:

After $z = whatever;
if ($z == "") {
$z = NULL;

  harristweed 08:33 15 Nov 2006

I'd do it like this....

//do the update;

  Mary_S 14:25 15 Nov 2006


thanks for the replies guys

I tried and yoru suggestion harristweed and it worked.

cnt believe i didnt think of that myself , just shows hw lazy i can be sumtimes :P lol

thanks alot much appreciated !!!


This thread is now locked and can not be replied to.

Elsewhere on IDG sites

WPA2 Hack Latest News: How Secure is your Wi-Fi?

Photoshop CC 2018 released with new Curvature Pen and better brush tools

Best kids apps for iPhone & iPad

Comment utiliser Twitter ?