Jump to content

[SOLVED] What is the code to determine if a variable is holding anything? Null Empty


jlgray48

Recommended Posts

Can you help me with this code?

 

<?php

 

$Item1 = $_REQUEST[item 1];

$Item2 = $_REQUEST[item 2];

$Item3 = $_REQUEST[item 3];

 

$conn=mysql_connect("127.0.0.1", "odbc", "") ;

mysql_select_db("php012",$conn);

 

For ($i = 1; $i <=3 ; $i+=1) {

 

    While $Item.$i == " " {

 

$sql = "Update inventorytable set Itemquantity = Itemquantity -1 where ItemID = $Item.$i" ;

mysql_query($sql,$conn);

}

 

 

 

?>

 

Based on your previous question, you don't want to use that:

While $Item.$i == " " {

 

You would want to use:

While $Item.$i == "" {

 

The space tells php that as long as $Item.$i equals a space do this...

 

Or I suppose you could replace the "" with any of the above suggestions such as FALSE...

 

Edit:

Also, for your for loop:

For ($i = 1; $i <=3 ; $i+=1)

 

you could use

For ($i = 1; $i <=3 ; $i++)

 

Instead.

 

$i++ is the same as $i=+1..

Ooo.. I don't know how I missed this!

 

While $Item.$i == " " {

 

$sql = "Update inventorytable set Itemquantity = Itemquantity -1 where ItemID = $Item.$i" ;

mysql_query($sql,$conn);

}

 

should be this:

while ($Item.$i == "") {

 

$sql = "Update inventorytable set Itemquantity = Itemquantity -1 where ItemID = $Item.$i" ;

mysql_query($sql,$conn);

}

 

As far as the "$Item.$i" goes, I don't know what your trying to accomplish...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.