Jump to content

Recommended Posts

Hey guys - me again!

 

I have a discount box, where i wish to check two "if" queries.  These are i) the 'uniquecode' and ii) the 'uses' - so a code can only be used a set amount of times.

 

1) How do i state that question in php, bearing in mind the "if uses > 0" needs to relate to the same row as the unique code entered?

 

2) Also, i have stored the session price in $_SESSION['sessionprice'] - is this the best way to do this, and if not how should i store the current price. 

 

3) Lastly, and how do I do the php mathematics of "$_SESSION['sessionprice'] minus the discount" - again bearing in mind the "discount" needs to relate to the same row as the unique code entered? (as different codes will have different discounts).

 

 

This is how far i've gotten:

 

<?php
//connection settings bla bla bla

$uniquecode = $_POST['discountcode'];

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$discountcodecheck = mysql_query("SELECT uniquecode FROM discounttable WHERE uniquecode = '".$uniquecode."'");
$remainingusescheck = mysql_query("SELECT uses FROM discounttable WHERE uniquecode = '".$uniquecode."'");

if (mysql_num_rows($discountcodecheck) > 0) and if (mysql_num_rows($remainingusescheck) > 0)  // <-- this "and if" doesn't work
	{
		// discount calculation:
			// session price minus the unique code's corresponding discount
			// update $_session['discountammount']

	}
else
	{
		?><script type="text/javascript">
		alert("Discount Code Entered Is Either Not Valid Or Has Been Previously Used.");
        	history.back();
      		</script><?php
	}

// rest of code and close connection
?>

 

 

Any help or comments will, as always be politely welcomed and appreciated :)

 

Cheers,

 

Tom.

 

Link to comment
https://forums.phpfreaks.com/topic/231879-two-if-queries-php-if-and-if/
Share on other sites

"and if" is not a valid expression. Use "&&" to represent AND

 

<?php 
if (($a==1) && ($b==2) ) { 
    // code 
} 
?> 

 

---->

 

<?php
if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0))
?>

 

Should work, not sure if I've got the brackets wrong though

if (mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0) {

 

I don't think there is a need for another when one if can accomplish the task.

 

1) How do i state that question in php, bearing in mind the "if uses > 0" needs to relate to the same row as the unique code entered?

You could dump the information returned from the database for the correct code and then compare that code to the code the user entered. Your if statement

above will check to see if the code is found and then continue on.

 

2) Also, i have stored the session price in $_SESSION['sessionprice'] - is this the best way to do this, and if not how should i store the current price.

While this will work it would leave the price vulnerable to anyone savy enough to influence the variable. If you wish to keep that you may consider securing it

by hasing it using MD5 then applying SHA1 using some formula you come up with. Then you can decode it and compare it to final values before checkout. If I'm

understanding you correctly.

 

3) Lastly, and how do I do the php mathematics of "$_SESSION['sessionprice'] minus the discount" - again bearing in mind the "discount" needs to relate to the same row as the unique code entered? (as different codes will have different discounts).

Dump the discount into a variable like:

 $row = mysql_fetch_array($results);

Then:

$discount = $row['discount'];
$newprice = $_SESSION['sessionprice'] - $discount;

 

Like I said above you would want to add security to anything dealing with money.

 

Hope this helps!

"and if" is not a valid expression. Use "&&" to represent AND

 

<?php 
if (($a==1) && ($b==2) ) { 
    // code 
} 
?> 

 

---->

 

<?php
if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0))
?>

 

Should work, not sure if I've got the brackets wrong though

 

You Sir/Ma'am, are a gentleman/gentlewoman and a Saint ;D

 

Much appreciated.

 

That's number 1) above solved, just two more to go!

 

2) Also, i have stored the session price in $_SESSION['sessionprice'] - is this the best way to do this, and if not how should i store the current price. 

 

3) Lastly, and how do I do the php mathematics of "$_SESSION['sessionprice'] minus the discount" - again bearing in mind the "discount" needs to relate to the same row as the unique code entered? (as different codes will have different discounts).

 

Thanks!

 

Tom.

 

Thanks for taking the time to reply.

 

You could dump the information returned from the database for the correct code and then compare that code to the code the user entered. Your if statement above will check to see if the code is found and then continue on.

 

How do i 'dump' this information?  (i'm new to php but not to coding so i'm a very quick study).

 

Dump the discount into a variable like:

 $row = mysql_fetch_array($results);

Then:

$discount = $row['discount'];
$newprice = $_SESSION['sessionprice'] - $discount;

 

 

How do i combine this with what i've already written?  I've been looking at this code for the last half hour and simply do not know where to start in incorporating your code...

 

 

Also this line:

 

if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0))

 

seems to be ignoring if the 'uses' is > 0 when i try it out.  I have a code with 0 uses and i still seems to accept it with the success message...

 

I will secure once the code is working - but thanks for checking  :-)

 

Cheers, I really appreciate the support from you / the php freaks community.

 

Tom.

 

 

 

 

 

 

I was just using your if statement and correcting the AND if part of it just like JakkyD except I didn't really give you an explanation as to the change.

 

As for your code as it stands your just returning if the code and uses are found and not checking either:

 

if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0)) {

 

So hey it found the code and there are uses so we're okay to continue on...

 

This could be your first step and then you could move onto error checking and then relaying errors to the end user. I was give you examples for how to place the information into an array so that you could assign it to variables to work with for comparision.  I don't know how you plan on checking which users have used a discount code so all I could do was provide a generic example.

 

So for an example let's do this:

 

<?php
// Clean up the code the user entered
$uniquecode = mysql_real_escape_string($_POST['uniquecode']); // OR whatever the name of the input is

$discountcodecheck = mysql_query("SELECT uniquecode FROM discounttable WHERE uniquecode = '".$uniquecode."'");
$row = mysql_fetch_array($discountcodecheck,  MYSQL_BOTH); // MYSQL_BOTH incase it's alphanumeric, and establish the $row array with the codes

$dcode = $row['uniquecode'];

$remainingusescheck = mysql_query("SELECT uses FROM discounttable WHERE uniquecode = '".$uniquecode."'");
$row1 = mysql_fetch_array($remainingusescheck, MYSQL_NUM); // MYSQL_NUM since the uses should be a number value, establish $row1 array with the uses

$uses = $row1['uses'];

// You could probably drop this now since the IF statement below will check the codes and uses
//if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0)) {

// Add your checking here
    // Check the code vr the code the user entered, and let's make sure the user hasn't used it over 2 uses
   if ($dcode = $uniquecode) && ($uses <= 2) {

     // Since they check out we can do our discount
   $discount = $_SESSION['sessionprice'] - $row['discountamt']; // Or whatever column in the database holds the discount amount

   } else {

    // Let them know the code or the uses have been reached, you could seperate the if statement above to give an error for uses
    echo "Sorry but you've used $dcode twice already.";

  } // close our if for checking the code and the uses

?>

 

I haven't tested this so I don't know if it will work 100% but hopefully give you an example you can work with.

I was just using your if statement and correcting the AND if part of it just like JakkyD except I didn't really give you an explanation as to the change.

 

As for your code as it stands your just returning if the code and uses are found and not checking either:

 

if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0)) {

 

So hey it found the code and there are uses so we're okay to continue on...

 

This could be your first step and then you could move onto error checking and then relaying errors to the end user. I was give you examples for how to place the information into an array so that you could assign it to variables to work with for comparision.  I don't know how you plan on checking which users have used a discount code so all I could do was provide a generic example.

 

So for an example let's do this:

 

<?php
// Clean up the code the user entered
$uniquecode = mysql_real_escape_string($_POST['uniquecode']); // OR whatever the name of the input is

$discountcodecheck = mysql_query("SELECT uniquecode FROM discounttable WHERE uniquecode = '".$uniquecode."'");
$row = mysql_fetch_array($discountcodecheck,  MYSQL_BOTH); // MYSQL_BOTH incase it's alphanumeric, and establish the $row array with the codes

$dcode = $row['uniquecode'];

$remainingusescheck = mysql_query("SELECT uses FROM discounttable WHERE uniquecode = '".$uniquecode."'");
$row1 = mysql_fetch_array($remainingusescheck, MYSQL_NUM); // MYSQL_NUM since the uses should be a number value, establish $row1 array with the uses

$uses = $row1['uses'];

// You could probably drop this now since the IF statement below will check the codes and uses
//if ((mysql_num_rows($discountcodecheck) > 0) && (mysql_num_rows($remainingusescheck) > 0)) {

// Add your checking here
    // Check the code vr the code the user entered, and let's make sure the user hasn't used it over 2 uses
   if ($dcode = $uniquecode) && ($uses <= 2) {

     // Since they check out we can do our discount
   $discount = $_SESSION['sessionprice'] - $row['discountamt']; // Or whatever column in the database holds the discount amount

   } else {

    // Let them know the code or the uses have been reached, you could seperate the if statement above to give an error for uses
    echo "Sorry but you've used $dcode twice already.";

  } // close our if for checking the code and the uses

?>

 

I haven't tested this so I don't know if it will work 100% but hopefully give you an example you can work with.

 

Thanks - I feel like i owe you a drink with this help  :intoxicated: :intoxicated:

 

I get the following error:

 

Parse error: syntax error, unexpected T_BOOLEAN_AND in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 26

 

What does a T_boolean_and error mean?  Not sure how to correct this as i don't understand the error...

 

Thanks again,

 

Tom.

 

 if ($dcode = $uniquecode) && ($uses <= 2) {

should have been :

 

 if (($dcode = $uniquecode) && ($uses <= 2)) {

 

Usually I think that just means you have an error with your  parentheses

 

Thanks.

 

Error message now changed to many many more:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 9

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 9

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 11

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 11

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 12

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 16

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 16

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 17
Sorry but you've used twice already.
Warning: Cannot modify header information - headers already sent by (output started at D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php:9) in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 40

Warning: mysql_close(): no MySQL-Link resource supplied in D:\vhosts\ntillo.com\httpdocs\newsite\discountcode.php on line 42

 

I feel bad continually asking for help - but do appreciate it  :thumb-up:

 

That's all spewed out because the database connection isn't established:

 

//connection settings bla bla bla
$uniquecode = $_POST['discountcode'];
mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

 

If your including a file say connect.php that holds those $localhost, $username, $password variables check to make sure they are correct.

 

If not then make sure you define them prior to connecting to the database.

 

EDIT:

Don't feel bad asking for help that's why we're all here! :)

 

Also I left them out of the example I gave you so you'll have to put that in the script.

Sorry I couldn't edit my last post again but not all of the errors are from a bad connection to the database.

 

I'm used to using mysqli statements since that's what I was taught dunno why, but anywho mysql_fetch_array syntax may be incorrect and you can check that out in the php manual.

 

mysql_real_escape_string holds this case also but you should establish a connection to the database before this action is preformed.

 

 

That's all spewed out because the database connection isn't established:

 

//connection settings bla bla bla
$uniquecode = $_POST['discountcode'];
mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

 

If your including a file say connect.php that holds those $localhost, $username, $password variables check to make sure they are correct.

 

If not then make sure you define them prior to connecting to the database.

 

EDIT:

Don't feel bad asking for help that's why we're all here! :)

 

Also I left them out of the example I gave you so you'll have to put that in the script.

 

Thanks for your kindness.

 

Sweet - it's almost working, so close now i can taste it.  (It was me being a dumb *** - your instinct as to the cause of the error was dead on.  Sometimes i surprise myself with utter stupidity).

 

No errors now, but the successful 'if' doesn't seem to alter the session price, it still displays the original full price after a valid discount code is entered.

 

// Since they check out we can do our discount

  $discount = $_SESSION['sessionprice'] - $row['discount']; // Or whatever column in the database holds the discount amount

  echo $discount;

 

I added the "echo $discount;" line and sure enough it shows the full price - what's not happening with the calculation?

 

Thanks buddy

 

Tom.

 

Well atleast the syntax wasn't off I never use mysql statments yay!

 

So the discount portion may be off because I just placed a value I made up in the IF statement.

 

Here:

 

 $discount = $_SESSION['sessionprice'] - $row['discount']; //Or whatever column in the database holds the discount amount

 

$row['discount'] should be whatever the column name from your database is for it to work properly if not it's just a NULL value because I made it up lol.

so replace discount with that column name

 

EDIT: for clarification

Well atleast the syntax wasn't off I never use mysql statments yay!

 

So the discount portion may be off because I just placed a value I made up in the IF statement.

 

Here:

 

 $discount = $_SESSION['sessionprice'] - $row['discount']; // [b]Or whatever column in the database holds the discount amount[/b]

 

$row['discount'] should be whatever the column name from your database is for it to work properly if not it's just a NULL value because I made it up lol.

 

Yeh - i changed that, the amended code is:

 

$discount = $_SESSION['sessionprice'] - $row['discount'] (my amended code)
$discount = $_SESSION['sessionprice'] - $row['discountamt']; (your original code - replaced by the above line)

 

So our naming logic is very similar!  However, this is not the issue.  The column is a decimal, as that's supposed to be the 'best' data type in MYSQL for monetary values - if that makes a difference?  If not, what else could it be?  I've read and re-read your code and it makes sense to me, but it's just not doing that final calculation. 

 

The 'false' part works a-ok and I've customized that so it falls in line with how the rest of the error messages have been previously displayed.

 

I'm determined to get this before i go to sleep!

 

Thanks again,

 

Tom.

 

 

Let's make some adjustments:

 

$discount = ($_SESSION['sessionprice'] - $row['discount']);
echo 'I took the session price: ' . $_SESSION['sessionprice'] . ' and subtracted our discount: ' . $row['discount'] . ' to come up with a total price of $discount';

 

Let's see what we get from that... I'm still here and will try to help you reach your goal :)

Let's make some adjustments:

 

$discount = ($_SESSION['sessionprice'] - $row['discount']);
echo 'I took the session price: ' . $_SESSION['sessionprice'] . ' and subtracted our discount: ' . $row['discount'] . ' to come up with a total price of $discount';

 

Let's see what we get from that... I'm still here and will try to help you reach your goal :)

 

:D  You're a legend.

 

Message received:

 

I took the session price: 39.99 and subtracted our discount: to come up with a total price of $discount

 

:shrug:

 

 

I took the session price: 39.99 and subtracted our discount: to come up with a total price of $discount

 

$row['discount'] is the culprit and the output for $discount would have read 39.99 because we're subtracting by 0. Now to find out why.

 

(AND I messed up on the echo but that's all good!) should've been:

echo 'I took the session price: ' . $_SESSION['sessionprice'] . ' and subtracted our discount: ' . $row['discount'] . ' to come up with a total price of ' . $discount;

 

Looking back over the code we are missing a key element. Where are we pulling the discount row from? Nowhere... We're only selecting the uniquecode in one query then the uses in another query. So, which of the tables also holds the discount table?

 

If it's this one:

 

$discountcodecheck = mysql_query("SELECT uniquecode FROM discounttable WHERE uniquecode = '".$uniquecode."'");

 

Then we change to this:

 

$discountcodecheck = mysql_query("SELECT uniquecode, discount FROM discounttable WHERE uniquecode = '".$uniquecode."'");

 

And by doing that we'll be giving our $row['discount'] a value to subtract from our sessionprice! :)

I took the session price: 39.99 and subtracted our discount: to come up with a total price of $discount

 

$row['discount'] is the culprit and the output for $discount would have read 39.99 because we're subtracting by 0. Now to find out why.

 

(AND I messed up on the echo but that's all good!) should've been:

echo 'I took the session price: ' . $_SESSION['sessionprice'] . ' and subtracted our discount: ' . $row['discount'] . ' to come up with a total price of ' . $discount;

 

Looking back over the code we are missing a key element. Where are we pulling the discount row from? Nowhere... We're only selecting the uniquecode in one query then the uses in another query. So, which of the tables also holds the discount table?

 

If it's this one:

 

$discountcodecheck = mysql_query("SELECT uniquecode FROM discounttable WHERE uniquecode = '".$uniquecode."'");

 

Then we change to this:

 

$discountcodecheck = mysql_query("SELECT uniquecode, discount FROM discounttable WHERE uniquecode = '".$uniquecode."'");

 

And by doing that we'll be giving our $row['discount'] a value to subtract from our sessionprice! :)

 

Awesome,

 

I took the session price: 39.99 and subtracted our discount: 39.00 to come up with a total price of 0.99

 

Which is correct as the test discount code was 39.00.

 

I can't see (though i may be wrong) the code which is then updating $_SESSION['sessionprice'] with this new price - how do we add this?

 

I tried simply deleting the echo, and the screen just refreshes but the price doesnt change - so i'm assuming the $_SESSION['sessionprice'] hasn't been updated as it's echoing correctly when that line of code is included.

 

Finally, i also have a 'uses' column (which we checked earlier in the if statement)...how do we 'minus one' from this column once it's been searched?  Otherwise the code would have infinite uses  :P

 

Thanks for all your help!

 

Tom.

 

I can't see (though i may be wrong) the code which is then updating $_SESSION['sessionprice'] with this new price - how do we add this?

 

$discount is the new price.  :)  --- Remember we are taking the session price and then applying the discount by subtracting it from $row['discount'] and then we just show the new price by echoing $discount.

 

I tried simply deleting the echo, and the screen just refreshes but the price doesnt change - so i'm assuming the $_SESSION['sessionprice'] hasn't been updated as it's echoing correctly when that line of code is included.

 

There are a few ways to do this. You could simply update the $_SESSION['sessionprice'] with the $discount value by setting the session variable again.

 

$_SESSION['sessionprice'] = $discount;

 

You could also just use $discount as that is the new total cost for the customer right?

 

Finally, i also have a 'uses' column (which we checked earlier in the if statement)...how do we 'minus one' from this column once it's been searched?  Otherwise the code would have infinite uses 

 

That is correct so you'd have to track the customer by either a $_SESSION variable or something like a login username that won't change. So let's say for the uses table we have 2 columns  (Custname, uses).

Now when we go to compare the uses we have something to pull it from ( WHERE username = '" . $_SESSION['username'] . "'";) and we could tac that onto our query. Like so:

$remainingusescheck = mysql_query("SELECT uses FROM discounttable WHERE uniquecode = '".$uniquecode."' && username = '" . $_SESSION['username'] . "'");

 

 

so after the first validation let's say they have used the code once already so in the database the value will be 1. We'll have to have another query for updating that value. So we'll add a query after the discount is applied to show that the user has used it again.

 

$adduse = mysql_query("UPDATE discounttable SET uses=uses+1 WHERE uniquecode = '".$uniquecode."' && username = '" . $_SESSION['username'] . "'");

 

NOTE: this will only work if that user has a value established in that table, you could add this function to your registration script so that when the user registers the name is placed into that table and uses is defaulted to 0.

 

I hope this is helping you out and not confusing you! Also I'm glad we we're able to get your script working layout wise, now you just need to add more functionallity.

$row = mysql_fetch_array($discountcodecheck,  MYSQL_BOTH); // MYSQL_BOTH incase it's alphanumeric, and establish the $row array with the codes

$row1 = mysql_fetch_array($remainingusescheck, MYSQL_NUM); // MYSQL_NUM since the uses should be a number value, establish $row1 array with the uses

 

WHAT???

Setting the second argument in mysql_fetch_array() has no bearing on what the expected data should return.  Rather, it tells the function to return it in an ASSOCiative array, a NUMerical array, or BOTH.

$row = mysql_fetch_array($discountcodecheck,  MYSQL_BOTH); // MYSQL_BOTH incase it's alphanumeric, and establish the $row array with the codes

$row1 = mysql_fetch_array($remainingusescheck, MYSQL_NUM); // MYSQL_NUM since the uses should be a number value, establish $row1 array with the uses

 

WHAT???

Setting the second argument in mysql_fetch_array() has no bearing on what the expected data should return.  Rather, it tells the function to return it in an ASSOCiative array, a NUMerical array, or BOTH.

 

First thanks for the clarification.

 

2nd to answer your WHAT???

I said in a post a few back in this thread that I don't use mysql statments much and had learned to use the mysqli statments. So I had to read mysql syntax so I misunderstood it but now I see what your talking about.

 

I can't see (though i may be wrong) the code which is then updating $_SESSION['sessionprice'] with this new price - how do we add this?

 

$discount is the new price.  :)  --- Remember we are taking the session price and then applying the discount by subtracting it from $row['discount'] and then we just show the new price by echoing $discount.

 

I tried simply deleting the echo, and the screen just refreshes but the price doesnt change - so i'm assuming the $_SESSION['sessionprice'] hasn't been updated as it's echoing correctly when that line of code is included.

 

There are a few ways to do this. You could simply update the $_SESSION['sessionprice'] with the $discount value by setting the session variable again.

 

$_SESSION['sessionprice'] = $discount;

 

You could also just use $discount as that is the new total cost for the customer right?

 

Finally, i also have a 'uses' column (which we checked earlier in the if statement)...how do we 'minus one' from this column once it's been searched?  Otherwise the code would have infinite uses 

 

That is correct so you'd have to track the customer by either a $_SESSION variable or something like a login username that won't change. So let's say for the uses table we have 2 columns  (Custname, uses).

Now when we go to compare the uses we have something to pull it from ( WHERE username = '" . $_SESSION['username'] . "'";) and we could tac that onto our query. Like so:

$remainingusescheck = mysql_query("SELECT uses FROM discounttable WHERE uniquecode = '".$uniquecode."' && username = '" . $_SESSION['username'] . "'");

 

 

so after the first validation let's say they have used the code once already so in the database the value will be 1. We'll have to have another query for updating that value. So we'll add a query after the discount is applied to show that the user has used it again.

 

$adduse = mysql_query("UPDATE discounttable SET uses=uses+1 WHERE uniquecode = '".$uniquecode."' && username = '" . $_SESSION['username'] . "'");

 

NOTE: this will only work if that user has a value established in that table, you could add this function to your registration script so that when the user registers the name is placed into that table and uses is defaulted to 0.

 

I hope this is helping you out and not confusing you! Also I'm glad we we're able to get your script working layout wise, now you just need to add more functionallity.

 

You are awesome and deserve a medal - you have effectively built me a discount code engine  :thumb-up:

 

The final bug ("just one more thing" - like columbo if you watch it) is that...

 

if (($dcode = $uniquecode) && ($uses <= 2)) {

 

...is accepting a test code which has '0' zero uses remaining.  In fact, now it has minus 2 uses remaining! lol.  I believe this is the last bug to iron out - you've been a great help and i've genuinely learnt more in the last few hours than i have in a long while.

 

Tom.

 

Your most welcome!

 

$uses <= 2 is going to make sure the value is less then 2.

 

The query I gave you was adding to uses but your subtracting starting with 2 uses.

 

This may do the trick:

 

if (($dcode = $uniquecode) && ($uses <= 2 && $uses > 0)) {

 

Remember your telling it that you want $uses to be less then or equal to 2 but greater then 0 in order for the user to use the code.

 

I'm beat been doing php work all day but give that  a try and see if it's working how you want and if not we'll take another look!

Your most welcome!

 

$uses <= 2 is going to make sure the value is less then 2.

 

The query I gave you was adding to uses but your subtracting starting with 2 uses.

 

This may do the trick:

 

if (($dcode = $uniquecode) && ($uses <= 2 && $uses > 0)) {

 

Remember your telling it that you want $uses to be less then or equal to 2 but greater then 0 in order for the user to use the code.

 

I'm beat been doing php work all day but give that  a try and see if it's working how you want and if not we'll take another look!

 

 

Not quite working still - just rejects both the code with negative uses and the code with 90 uses (i changed <=2 to <=99)

 

$row1 = mysql_fetch_array($remainingusescheck, MYSQL_NUM); // MYSQL_NUM since the uses should be a number value, establish $row1 array with the uses

$uses = $row1['uses'];

 

Will the problem lie here?  as we're saying uses = $row1, however we're not specifying uses anywhere in $row1...i dunno?

 

I may need to sleep on it :-)

 

Cheers again buddy,

 

Tom.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.