
Skewled
Members-
Posts
387 -
Joined
-
Last visited
Everything posted by Skewled
-
if (($dcode = $uniquecode) && ($uses <= 2 && $uses >= 0)) { Give that a try..
-
We started the uses as 2 in the database because the query we are using subtracts 1 from a correct code used. So we couldn't start with 0 because you'd go negative. $adduse = mysql_query("UPDATE discounttable SET uses=uses-1 WHERE uniquecode = '".$uniquecode."'"); You can change that around if you want and do SET uses=uses+1 if you want to start the uses at 0 in your database, but you will have to change the IF statment again. != means does not equal, so we use that because if it dosen't equal 0 they have uses remaining. Change: if (($dcode = $uniquecode) && ($uses != 0)) { to: if (('$dcode' == '$uniquecode') && ($uses != 0)) { That's just incase I made a syntax error, but give that a whirl and see what you get. At this point we know it's doing the check and that something isn't meeting the criteria. If these adjustments don't work I'll have a look at the code before the IF statment again.
-
Okay let's have a look at what is going on with the uses. if (($dcode = $uniquecode) && ($uses <= 0)) { changes to: if (($dcode = $uniquecode) && ($uses != 0)) { Not quite working still - just rejects both the code with negative uses and the code with 90 uses (i changed <=2 to <=99) We will now check to make sure that they have 2 uses by saying they start with 2 uses for each code used by saying uses can't be 0. (You'll have to set the uses to 2 in the database before testing again, so clean up any negative numbers and numbers over 2.) It was working because it was rejecting a user from using a code. $adduse = mysql_query("UPDATE discounttable SET uses=uses-1 WHERE uniquecode = '".$uniquecode."'"); We're subtracting uses by 1 after the verification is passed so if they use the code once they will have 1 use left before reaching 0 where our code will not allow another use. $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']; We are getting the information from the database from our query earlier $remainingusescheck. We are then placing it into a variable $uses to compare to. This should work provided uses is a column in the discounttable table. (Again make sure the uses is set to 2 for each code available) Make that small adjustment and let me know what happens. (Make the updates to the database so they uses start at 2) EDIT: Will the problem lie here? as we're saying uses = $row1, however we're not specifying uses anywhere in $row1...i dunno? To answer your question no it shouldn't. We're just getting the information from the query for uses and placing the information into an array called $row1. So we can compare the number of uses associated with the code the user entered. So if the user has 1 use left $row['uses'] will be 1 and we're just placing it into a variable called $uses to make it easier to read in the IF statement, well for me anyway lol.
-
I'm working with chunks of the code from our different posts, do me a favor and post our fully updated new code to make it easier
-
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!
-
This is going to ouput before your HTML because that's the document flow. function displayBody() { mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'"); echo $extract['title']. ", by ". $extract['username'] ."."; } would this not do the trick? function displayBody() { mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'"); $content = $extract['title']. ", by ". $extract['username'] ."."; }
-
I'm sorry been awake for way too long lol.
-
Move this code into the actual <head> tag <div id="header"> MCSkins </div> that's just my suggestion.
-
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.
-
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!
-
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
-
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
-
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.
-
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
-
No problem
-
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've never used Joomla, but from what I know in my experience so far that should have done the trick for you. But you may want to seek out some Joomla experts because from what I can tell the system itself is doing something with the code. http://www.joomlablogger.net/joomla-tutorials/joomla-template-tutorials/tutorial-create-line-breaks-in-joomla-article-titles/ I did some searching and found the above article that is used for applying line breaks to joomla articles, so this may help you understand how they do it and possibly help you get the line breaks you desire.
-
http://php.net/manual/en/control-structures.switch.php You could use switch/case so that you could see if the time was already taken and let the user know available times. This would probably help you cut down on IF/ELSE statments and make it easier to see the flow.
-
$seek_location = 'Anywhere'; This may simply just drop the whole dynamically created dropdown box and allow Anywhere to pass to the database. BUT I don't have the entire script your working with to clearly see what's going on so this is just my guess. The only issue I could see is if there are checks to see if $seek_location equals a set value before it's passed to the database.
-
I use CSS for applying styles so I'm not sure if that has something to do with it. But try <br> instead of <br />.
-
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!
-
That's how I do it with my while loops hmm. Try adding another echo line with just the <br> tag after your output. echo '<strong>' . $row['hash_num'] . ' ' . $row['hash_name'] . ' - ' . date("D, d M Y", strtotime($row['hash_date'])) . '</strong><em>Total Hashers: ' . mysql_num_rows($result) . '</em>'; echo '<br>';
-
Added the MIN (will only work if the field is numeric otherwise you'll have to add CAST to it MIN(CAST()) ) function to the prices: $cols = firstname, lastname, MIN($price1), MIN($price2), etc. Now we can gather the information using this query and only ouput the lowest price: $result = mysql_query (" SELECT $cols FROM tablename GROUP BY firstname LIMIT 1"); I haven't tried the above query but hope it helps you figure this out.