-
Posts
87 -
Joined
-
Last visited
Never
About mellis95
- Birthday 09/09/1981
Profile Information
-
Gender
Male
-
Location
Texas
mellis95's Achievements
Member (2/5)
0
Reputation
-
Are you having a specific problem with this code? You methodology looks generally okay. I would probably not use all the variables, and do this: (Not sure that it really makes much difference...) <?php session_start(); if(isset($_SESSION['firsttime'])) { header("location: teamselections.php"); } else { header("location: myaccount.php"); } ?> Also, if you have some value assigned to $_SESSION['firsttime'], you might check for that value as well as just isset. i.e.: if(isset($_SESSION['firsttime'])&&($_SESSION['firsttime']==true))
-
PHP sessions, and random strings. Help completing code.
mellis95 replied to ibr4n's topic in PHP Coding Help
I don't know what to tell you. It works fine on my setup. If you copy the code exactly as I have it in the post it should have a blank screen with a random color code (ex. FF6D2D) displayed on the screen. Are you saying it is not even doing that? Or is it not changing your background color the way you want. If the latter is the case, the problem is likely in the way you apply the random code the the background style. -
PHP sessions, and random strings. Help completing code.
mellis95 replied to ibr4n's topic in PHP Coding Help
I have tested the code below and it works perfectly on my setup. I should have noticed last night that you were only setting the cookie in the else statement. I'm not sure if that was the problem or not, but the only things I changed was where the cookie was set and I added curly braces to all of the if statements, just because I think it is good practice and makes the code more readable. With the code below I can continue refreshing the page and get a different random color on each refresh. I left the die() in there so you can verify the color change in the browser. Just take that out and you should be ready to go. <?php session_start(); ob_start(); if ($_POST['change']) { $thevar = $_POST['change']; $_SESSION['bcg'] = $thevar; } if(!empty($_SESSION['bcg'])) { $thecolor = $_SESSION['bcg']; } else { $num = rand(0,9); if ($num == 0) { $thecolor = "0DEBDF"; // CYAN } if ($num == 1) { $thecolor = "AE00FF"; // PURPLE } if ($num == 2) { $thecolor = "FFDC01"; // YELLOW } if ($num == 3) { $thecolor = "FF6D2D"; // PEACH } if ($num == 4) { $thecolor = "20ff7f"; // LIGHTER-GREEN } if ($num == 5) { $thecolor = "00E612"; // GREEN } if ($num == 6) { $thecolor = "E6005D"; // PINK } if ($num == 7) { $thecolor = "E600CF"; // PINK-PURPLE } if ($num == { $thecolor = "e2ff20"; // LIME } if ($num == 9) { $thecolor = "8868ff"; // LAVENDER } } setcookie("thecolor", $thecolor, time()+604800); die($thecolor); -
PHP sessions, and random strings. Help completing code.
mellis95 replied to ibr4n's topic in PHP Coding Help
What does the syntax error say? I haven't dealt with setcookie, but from what I understand it needs to be the first thing done in a script, but can be set after other script processing by buffering the output with ob_start(). -
PHP sessions, and random strings. Help completing code.
mellis95 replied to ibr4n's topic in PHP Coding Help
Try adding ob_start(); to the first line of the code. Like this. <?php ob_start(); if ($_POST['change']){ $thevar = $_POST['change']; $_SESSION['bcg'] = $thevar; } if(!empty($_SESSION['thecolor'])) { $thecolor = $_SESSION['thecolor']; } else { $num = rand(0,9); if ($num == 0) $thecolor = "0DEBDF"; // CYAN if ($num == 1) $thecolor = "AE00FF"; // PURPLE if ($num == 2) $thecolor = "FFDC01"; // YELLOW if ($num == 3) $thecolor = "FF6D2D"; // PEACH if ($num == 4) $thecolor = "20ff7f"; // LIGHTER-GREEN if ($num == 5) $thecolor = "00E612"; // GREEN if ($num == 6) $thecolor = "E6005D"; // PINK if ($num == 7) $thecolor = "E600CF"; // PINK-PURPLE if ($num == $thecolor = "e2ff20"; // LIME if ($num == 9) $thecolor = "8868ff"; // LAVENDER // send a cookie that never expires setcookie("thecolor",$thecolor, time()+604800); } ?> -
PHP sessions, and random strings. Help completing code.
mellis95 replied to ibr4n's topic in PHP Coding Help
Depending on how $_SESSION['thecolor'] gets set, you might have better luck checking if it is empty instead of isset. Isset will always evaluate true if $_SESSION['thecolor'] exists and is not NULL. For instance, $_SESSION['thecolor']='' will evaluate true using isset. It will evaluate correctly in your code if you use !empty. For example: if(!empty($_SESSION['thecolor'])) { $thecolor = $_SESSION['thecolor']; } else { $num = rand(0,9); ......... -
WOW. I knew it would be something easy. Thank you for the help. x[0].coord is just what I needed. Matt
-
I am attempting to use JSON.parse for my first time today and I am having trouble figuring out what is going on. I have the following PHP code: while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $dataArray[] = $row; } echo json_encode($dataArray); Which passes the following data to the client (viewed with Chrome Developer Tools): [{"coord":"23","data":"PATIENT NAME"},{"coord":"127","data":"PATIENT NAME"}] I have the following javascript code (snippet) to process the JSON: if(httpObject.readyState == 4) { if (httpObject.status == 200) { x = JSON.parse(httpObject.responseText); alert(x); } } The alert I get is: [object Object],[object Object] I have been on Google for quite a while trying to figure this out, and everything that I have read says that the following code should just work: x = JSON.parse(httpObject.responseText); alert(x.coord); If I try to access the array key (x.coord OR x.coord[0]) I get "undefined". What am I missing here? I bet it is something simple. (It usually is...) Thanks in advance for the help. Matt
-
You need to join them on the common keys. For example: SELECT a.comp_name,b.ord_number,c.inv_number FROM Companies AS a LEFT JOIN Orders AS b ON b.comp_id=a.comp_id LEFT JOIN Invoices AS c ON c.comp_id=a.comp_id However, if I am understanding what you are trying to do, you might change your table structures so that the invoice references the order number: Companies comp_id comp_name Orders ord_id comp_id ord_number Invoices inv_id ord_id inv_number In this case, your query would look like this: SELECT a.comp_name,b.ord_number,c.inv_number FROM Companies AS a LEFT JOIN Orders AS b ON b.comp_id=a.comp_id LEFT JOIN Invoices AS c ON c.ord_id=b.ord_id
-
Don't SELECT DISTINCT, just SELECT. I don't have a mysql server to test on right now, but I believe if you use SELECT DISTINCT it only selects each DISTINCT itemNumber. To SUM them and group you need to select duplicate item numbers.
-
How are you closing the connection? Are you closing it by specifying the link_identifier? What does the code look like?
-
For one thing, you have the same field name used twice. Once as the actual field name, and once as the name for the SUM. Change your query to something like this and see what it looks like: $result=@mysql_query("SELECT DISTINCT itemNumber, itemDesc, quantityHand, SUM(quantityHand) AS quantityHandSUM FROM inventory WHERE id='$select' GROUP BY `itemNumber` ORDER BY `itemNumber`");
-
Please assist with provide discount before certain date only
mellis95 replied to Jeniveve's topic in PHP Coding Help
28 is correct. I think we need to see the rest of the script to track down what is going on. The piece you posted is working correctly. -
am having a small display problem with sessions when logging out
mellis95 replied to PHPSuperNewb's topic in PHP Coding Help
I am getting a little over my own head here, but I think that unsetting the $_SESSION prior to calling session_destroy() may be hurting you. I would try commenting out the "unset($_SESSION)" line in the function stopSession() and see what happens. So basically, stopSession() would look like this: function stopSession() { // unset($_SESSION); session_destroy(); } -
Please assist with provide discount before certain date only
mellis95 replied to Jeniveve's topic in PHP Coding Help
I just plugged this into a script and it calculates full cost. Today date("j") is '28', so I don't see why you should have any issue with that script today. Based on the code you provided the discount would start again on May 1. What do you get if you echo date("j") from your server? Could the date on the server be incorrect??