-
Posts
307 -
Joined
-
Last visited
Everything posted by TapeGun007
-
Yeah, I had noticed and was trying to find the issue. But drop down box of the selected item is still dark red (background) even with that. The background of a the active item drop down should be #f6f6f6 (or whatever other color).
-
Ah nevermind, I'm dumb. <?php echo createMenu($menuLinks, "testcss.php"); ?> Thank you so very much Psycho, this is awesome!
-
Wow Psycho... I wasn't asking for all that, but this is certainly eye opening on a way better method of generating a simple menu. Yes, HTML tables are old hat, but I was just trying to better learn CSS, so I wasn't focused too much on that. My only frustration with building "tables" using <div> and CSS is there seems to be no replacement of "colspan" or "rowspan" (that I can find anyway). I put all of this into a testcss.php file exactly as you have it above and it works fine except the highlight of the selected menu item. I set "Home" to this: $menuLinks = array( 'Home' => array( 'href' => 'testcss.php' ), So when I click home it's not highlighted in the dark red. In my HTML I just put the additional CSS in a style tag: <!DOCTYPE HTML> <html> <head> <link rel="stylesheet" type="text/css" href="css/rs.css"> </head> <style> li.active a { background-color: #990000; } </style> <body> I also put it at the end of the css file actually just now.
-
Oh sorry, I didn't know another reply was coming... now I see the explanation.
-
Thanks for the reply Psycho. I am not good with CSS, so while I understand what you are saying I do not know how to apply it. I am guessing you mean I need something like this? .active:hover .dropdown-content{ position: relative; display: block; } Now that DOES give me a "drop down" on the selected item, but not correctly. I'll have to keep reading and see how to fix, but at least you got me on the right track! What I completely do not understand is when you said:
-
Ah thanks Jacques1, you probably saved me some time there! And this is why I asked, because the 2nd one didn't make sense to me either. The first one was just my initial (failed) attempt at better understanding the differences in PDO coming from mySQLi.
-
Hey guys, I just want to ask if I am doing this right because I don't want to learn bad habits. To loop through a database gathering information I see a lot of "solutions" where the examples store everything into an array. On the particular page that I am developing I don't see a need for this. I am thinking about simply writing the code something like this: $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row){ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ // Display results in a table } }else{ echo "<br>No Results Found<br>"; } Where a lot of examples use something more like this: if ($stmt->execute()) { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $products[] = $row; } } I could see where storing table values into an array would make sense in some/many cases or is this a standard way of pulling database data with PDO? Doesn't it just really depend on what you need on the page?
-
Help with creating an Unsubscribe PHP page.
TapeGun007 replied to nootkan's topic in PHP Coding Help
What I gather from his post is... he has an email list of friends and family that are all using either yahoo, gmail, or hotmail. Those three companies require a "unsubscribe" option or his outbound emails immediately go to their spam folders instead of receiving them. I'm not sure why you can't just put at the bottom of the email an HTML link with unsubscribe (even if it does nothing) and prevent it from being flagged as spam (granted I don't know that's true). -
@gizmola, Yes, I just read that actually on a website, but I tried this instead and it seems to work fine (more along the lines of what Jacques suggested). I want to simply check for any data so it doesn't bother building out a table for nothing. $stmt = $con->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row){ echo "<br>Not Empty<br>"; }else{ echo "<br>Empty<br>"; }
-
Yes, Barand made me convert... so I'm learning slowly... if ($stmt->num_rows == 0) { echo "<p>No record(s) found.</p>"; }else{ echo "<br>".$row['FirstName']."<br>"; } I'm getting no records found. So then I realize it's because (Barand made me convert) I'm on PDO not mySQLi. So I read about rowCount, but then it states the following (Which is disturbing): So what is the best alternative? From googling, I'm getting like so many different pieces of code, I'm not sure what is the best method. I just want to check to see if there are any values at all in the query.
-
Where can I donate to phpfreaks?
TapeGun007 replied to TapeGun007's topic in PHPFreaks.com Website Feedback
I kind of gathered that. I have donated in the past. I would just like to show my support even though $100 really isn't much in the grand scheme of things and it certainly wouldn't pay for all the help that I have received. A big thank you to whomever it is that runs this website. -
My company would like to donate $100 for all the help we have received.
-
I love Barand. He has helped me out of a bind so many times while I'm trying to learn mySQL and sometimes even php. I've probably been on this site for 10+ years now, but off and on as I have not always been actively coding. What I really like about Barand is that often times when asking for help, some people will say, "Why are you doing it this way?" where Barand just gives you the answer. He's always very helpful!
-
Ignorance. I just didn't know the proper method of going about that. But when I post on here, not only do I get the answer I am looking for, but I also get an education on how to do things the RIGHT way.
-
I thought Psycho's way of writing my code was very neat and tidy yesterday, but I couldn't figure out how to apply it. Now I'm trying to figure out how to apply what you are telling me. This is my complete rudimentary and failed attempt at coding this: // $dbs tells us how many databases are in that array. $dbs = count($statedb); // Establish all of the connection strings that we will need. Some states will need 1, some states will need 10. $con = array(); foreach($statedb as $counter => $db_name){ $con[$counter] = new mysqli($DBServer, $DBUser, $DBPass, $db_name); //echo "$counter - $db_name<br>"; // Loop through each database name in the array and add it to the $sql $sql .= " SELECT FirstName, LastName, Email, Mobile, PromoCode FROM $db_name.<tablename> WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) "; $args .= "sss"; // This just stops adding to the string 1 count before so we do not get 3 extra $Search's if($counter < ($dbs - 1)){ $searches .= $Search.", ".$Search.", ".$Search; } // This prevents putting an extra comma at the end of the final string or we would get "$Search, $Search, $Search," if($dbs <> 1 && $counter < ($dbs - 2)){ $searches .= ", "; } /* If there is only 1 database, then we do not need a UNION. Also, we do not want a UNION at the end of our $sql either. */ if($dbs <> 1 && $counter < ($dbs - 1)){ // If the State selected has more than 1 database, then add the UNION to the SQL command. $sql .= " <p>UNION</p> "; } } echo "<p> $sql </p>"; echo "<br> $args - $searches<br>"; $stmt = $consd->prepare($sql); $stmt->bind_param($args,".$searches."); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($ID, $FirstName, $LastName, $Email, $Mobile, $Code); But at least I was trying... LOL. I'll read up on mySQL variables. I get what you are doing, I just need to learn how to apply it. Thanks.
-
This has to do with yesterday's thread found here: https://forums.phpfreaks.com/topic/303251-can-you-store-con-into-an-array/ So the actual mySQL is something like this: SELECT FirstName, LastName, Email, Mobile, PromoCode FROM <database>.<table> WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) A user fills out a search INPUT and so they can search based on the email address, cell phone or promo code stored in $Search. Then for the prepared statement I would simply use something like this: $stmt->bind_param('sss', $Search,$Search,$Search); So, the code we worked on yesterday pulls the SQL statement from potentially 1 database, or it could be 5 databases using UNION. So if there were 5 databases, then the bind_param would be set to say 'sssssssssssssss' and $Search x 15 times. I don't know how to accomplish this... I am assuming that for the 'sss' I can store that in a string easy enough, but what about duplicating the $Search field over and over? I'm not sure if I am making coherent sense here. Hopefully I am.
-
Yes, I agree with both of you. It's because some states have a different # of databases. So if $statedb = "1", then "SELECT * FROM <db> WHERE... " else "SELECT * FROM <db> WHERE ... UNION..." Thanks for the code Psycho, I'm not familiar with implode so I'll go look that up. edit: You wrote what I wanted to do in a MUCH better way. Thanks again.
-
I think I have it already... I was too quick to post. I see my syntax error above as well. I think this will work: foreach($statedb as $x => $x_value){ $con[$x] = new mysqli($DBServer, $DBUser, $DBPass, $x_value); }
-
I'm looking for a temporary solution to a database issue. Eventually, I will put an end to all of this nonsense, so for all those would reply "Why in the world would you do that?"... I didn't. Someone else did. I'm just looking for a temporary fix. I have a set of databases all on the same server, same fields, same log in credentials. I simply want to create a $con array because based on user selection, there may only be one database, or there could be as many as 10 (all of which I would use UNION to join them). I know this is a syntax error on my part, I cannot seem to Google the right information to understand how to do this properly. $con = array(); $arrlength = count($statedb); echo "$arrlength<br />"; for ($x = 0; $x < $arrlength; $x++) { $con($x) = new mysqli($DBServer, $DBUser, $DBPass, $statedb($x)); echo $con($x); } So in the example above, let's say California was selected, there are 10 databases (all identical in login, layout, but different information). I'd like there to basically be $con x 10. I think the code above is pretty self explanatory.
-
I think I'm not googling the right phrase so I can't seem to find the right answer. I'm not super great with CSS especially when it comes to drop down menus. I usually spend time on the back end of a website, not the front end. Here is my CSS: /***** Begin Menu CSS *****/ ul { width: 100%; list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; } li { float: left; } li a, .dropbtn{ display: inline-block; font-size: 15px; color: white; text-align: center; padding: 14px 16px; text-decoration: none; border-right: 1px solid #bbb; } /* Color of the main menu text when hovering */ li a:hover { background-color: red; } /* Once the mouse has moved off the main menu button and is now highlighting a sub menu button, this defines what that main menu button color is */ .dropdown:hover{ background-color: red; } /* Color of main menu button when not selected */ .dropbtn { background-color: 333; } li .dropdown { position:relative; display: inline-block; } li:last-child { border-right: none; } .dropdown-content{ display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2); z-index: 1; } /* Links inside the dropdown */ .dropdown-content a{ color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; background-color: #f6f6f6; /* Sets background color of the drop down menu (not selected) */ } /* Change color of dropdown links on hover */ .dropdown-content a:hover {background-color: #ccc} .dropdown:hover .dropdown-content{ display: block; } /* I have no idea what this does as it appears nothing... li a:hover:not(.active) { background-color: #blue; } */ .active { background-color: #990000; } .active dropdown-content{ display: none; position: absolute; min-width: 160px; box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2); z-index: 1; } .active dropdown-content a{ color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } /***** End Menu CSS *****/ And here is the HTML: (PHP Function) function Active($menuselection, $page){ if($page == "$menuselection"){ echo "active"; }else{ echo "dropdown"; } } (HTML) <table width="100%"> <tr> <td> <ul> <li> <a class="<?=Active("menu.php", $webpage); ?>" href="menu.php">Home</a> </li> <li class="<?=Active("tms.php", $webpage); ?>"> <a href="javascript:void(0)" class="dropbtn">Territory Manager</a> <div class="dropdown-content"> <a href="#">Add TM</a> <a href="search.php?search=TM">Search TM</a> </div> </li> <li class="<?=Active("sales.php", $webpage); ?>"> <a href="javascript:void(0)" class="dropbtn">Sales</a> <div class="dropdown-content"> <a href="#">Add Sales Person</a> <a href="search.php?search=sales">Search Sales</a> </div> </li> <li class="<?=Active("drivers.php", $webpage); ?>"> <a href="drivers.php" class="dropbtn">Drivers</a> <div class="dropdown-content"> <a href="#">Add Driver</a> <a href="drivers.php">Search Drivers</a> </div> </li> <li class="<?=Active("passengers.php", $webpage); ?>"> <a href="javascript:void(0)" class="dropbtn">Passengers</a> <div class="dropdown-content"> <a href="#">Add Passenger</a> <a href="search.php?search=passengers">Search Passengers</a> </div> </li> </ul> </td> </tr> </table> So... the drop down menu works wonderfully except for one thing... if I were to click on "Drivers" for example, now that it is actively selected... the drop down menu is now gone so I cannot select "Add Driver" or "Search Drivers". I just cannot seem to figure out why I cannot get the drop to work on a menu item that is selected. Any help would be greatly appreciated. EDIT By Psycho: Wrapped HTML within code tags
-
I have mySQLi statement that looks similar to this: $sql = "SELECT ID, FirstName, Last Name, Email, Mobile, PromoCode FROM table1 WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) "; $stmt = $consd->prepare($sql); $stmt->bind_param('sss', $Search,$Search, $Search); Works fine. But what I cannot seem to find is what if I had two databases with all the same tables and I want to query both of them using mySQLi? I've tried all types of things, but I *think* because it's older mysql code that I'm not getting the syntax quite right...
-
Hey Jacques1, I didn't really know much about cURL, so I had to read up and learn how it works. I used a var_dump to help figure out what I was doing as well. Bottom line is, you got me pointed in the right direction so thank you for that. Here is the code that works: $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify', CURLOPT_POST => 1, CURLOPT_POSTFIELDS => [ 'secret' => '***SECRET KEY HERE***', 'response' => $_POST['g-recaptcha-response'], ], ]); $response = json_decode(curl_exec($curl)); if($response->success){ echo "<p>Captcha was successful!</p>"; } var_dump($response); One curious question... is that my editor phpDesigner 8 gives me an error on the "curl_setopt_array" line with syntax error expected '[' Yet the code runs great. Is there something I am missing here?
-
So when I run the code, the page loads... I check the captcha box and then submit... the echo "failed" is then triggered. I tried the following examples (and more): http://www.codexworld.com/new-google-recaptcha-with-php/ https://webdesign.tutsplus.com/tutorials/how-to-integrate-no-captcha-recaptcha-in-your-website--cms-23024 http://www.techflirt.com/integrate-google-no-captcha-recaptcha-in-php https://codeforgeek.com/2014/12/google-recaptcha-tutorial/
-
Here's my code: <?php include 'recaptchalib.php'; if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ echo $_POST['g-recaptcha-response']."<p>"; $secret = "<secret key>"; $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); $responseData = json_decode($verifyResponse); echo "Response:".$verifyResponse."<p>"; if($responseData->success){ echo "Success"; }else{ echo "Failed"; } } ?> <!DOCTYPE HTML> <html> <head> <link rel="stylesheet" type="text/css" href="components/css/rs.css" /> <script src='https://www.google.com/recaptcha/api.js'></script> </head> <body> <form method="post" action="test2.php"> <input type="text" /> <div class="g-recaptcha" data-sitekey="<key>"></div> <input type="submit" /> </form> </body> </html> I've tried like 7 different websites coding example... my captcha fails every time. Their examples always work. What else could it be?
-
Whoops... I thought it worked. but when submitting the form with nothing in the INPUT field it crashes on the if(!strlen($PostLicenseExp) == 10){ echo "yes"; $PostLicenseExp = DateTime::createFromFormat('m-d-Y', $_POST['LicenseExp'])->format('Y-m-d'); } I see... I didn't need the ! before strlen...I had it the wrong way around.