Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. When you say that spaces are disappearing, it sounds like you're talking about the space between lines of text. It also sounds like the spaces are disappearing when you view the e-mail message in your e-mail client (Outlook, Gmail, Hotmail, etc.) If this is the case, are you using Outlook to view the e-mail? If so, is there something at the top of the message which says "Extra line breaks in this message were removed"? In Outlook 2007, the message is highlighted in blue and appears above the date the e-mail was sent. If you see that message, just click it and click "Restore line breaks". Of course this will only temporarily fix the e-mail message on your computer.
  2. Yeah sorry about that, I wasn't aware of how the count() feature works. After a quick search, it sounds like it gives you 1 row every time. So using mysql_num_rows() will always return 1. Also, I agree that Ignace solutions looks like a better option. I can understand if you don't want to make the switch though. I have several complicated SQL queries in my scripts which work great. But when the time comes where I need to edit them it takes a little longer to remember how everything works. This makes maintenance a little more complicated...especially if you don't live and breathe SQL code. If you prefer to stick with your code, you should be able to eliminate one of the SQL queries by doing something like this: //CONNECT TO THE DATABASE $con = mysql_connect("localhost", "xxxxxxxxxx", "xxxxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxxxx") or die(mysql_error()); //INTIAILZE VARIABLES $numMembers = 0; $numNonMembers = 0; //GET AND DISPLAY THE NUMBER OF MEMBERS $result = mysql_query("SELECT activate, COUNT(activate) FROM customers WHERE activate='y'"); while($row = mysql_fetch_array($result)) { $numMembers = $row['COUNT(activate)']; echo "There are $numMembers members.<br />"; } //GET AND DISPLAY THE NUMBER OF NON-MEMBERS $result = mysql_query("SELECT activate, COUNT(activate) FROM customers WHERE activate!='y'"); while($row = mysql_fetch_array($result)) { $numNonMembers = $row['COUNT(activate)']; echo "There are $numNonMembers non-members.<br />"; } //FIGURE OUT HOW MANY TOTAL MEMBERS THERE ARE $totalMembers = $numMembers + $numNonMembers echo "There are $totalMembers total users.<br />"; //CLOSE THE DATABASE CONNECTION mysql_close($con); Note that I'm a little confused by what's going on with the "activate" column. In your OP, it sounds like "activate" will contain one of three possibilities. It will contain: y - if they are a member n or null - if they are not a member But your last SQL query had activate!='0' in it. Is there a chance that some records will have '0' in the activate column? If so, what does that mean?
  3. Assuming that you're using Internet Explorer (IE), this seems like a browser bug. The code works as expected in FireFox. I've had a lot of problems with forms that only have one text input. IE usually doesn't pass any information. Since your form also has the drop-down menu, at least the form data is being passed. If you add another text input to the form, you should see that the form will work just fine. Note that it doesn't seem to matter if the form is using the GET or POST method. There are a few ways that you can get around this problem: [*]add a second text input and hide it with CSS or [*]add a hidden input field and use that to test if the form was submitted
  4. I've never looked into removing cookies created by other websites. In my mind that would be a potential security risk. If a website can access another website's cookie to delete; there would also be the potential for that website to read or modify that cookie. With that said, I really don't know if it's possible or not.
  5. This should work if I understand your question correctly: // Print out result while($row = mysql_fetch_array($result)) { echo "There are " . $row['COUNT(activate)'] - 2 . " members.<br />"; } Note that I've never seen a column referred to like "$row['COUNT(activate)']". Does that work? I usually build the query like: $result = mysql_query("SELECT activate, COUNT(activate) AS numMembers FROM customers WHERE activate='y'"); while($row = mysql_fetch_array($result)) { echo "There are " . $row['numMembers'] - 2 . " members.<br />"; }
  6. If all you need to do is count the members, non-members, and get the total; you could also do something like: //CONNECT TO THE DATABASE $con = mysql_connect("localhost", "xxxxxxxxxx", "xxxxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxxxx") or die(mysql_error()); //INTIAILZE VARIABLES $numMembers = 0; $numNonMembers = 0; //FIGURE OUT HOW MANY MEMBERS THERE ARE if($result = mysql_query("SELECT activate, COUNT(activate) FROM customers WHERE activate='y'")) { $numMembers = mysql_num_rows($result); echo "There are $numMembers members.<br />"; } //FIGURE OUT HOW MANY NON-MEMBERS THERE ARE if($result = mysql_query("SELECT activate, COUNT(activate) FROM customers WHERE activate!='y'")) { $numNonMembers = mysql_num_rows($result); echo "There are $numNonMembers non-members.<br />"; } //FIGURE OUT HOW MANY TOTAL MEMBERS THERE ARE $totalMembers = $numMembers + $numNonMembers echo "There are $totalMembers total users.<br />"; //CLOSE DATABASE CONNECTION mysql_close($con);
  7. Maybe I missed something, but is there a reason you need to open and close the database connection so many times? You should be able to do something like this: //CONNECT TO THE DATABASE $con = mysql_connect("localhost", "xxxxxxxxxx", "xxxxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxxxx") or die(mysql_error()); //GET AND DISPLAY THE NUMBER OF MEMBERS $result = mysql_query("SELECT activate, COUNT(activate) FROM customers WHERE activate='y'"); while($row = mysql_fetch_array($result)) { echo "There are ". $row['COUNT(activate)'] ." members."; echo "<br />"; } //GET AND DISPLAY THE NUMBER OF NON-MEMBERS $result = mysql_query("SELECT activate, COUNT(activate) FROM customers WHERE activate!='y'"); while($row = mysql_fetch_array($result)) { echo "There are ". $row['COUNT(activate)'] ." non-members."; echo "<br />"; } //GET AND DISPLAY THE NUMBER OF TOTAL USERS $result = mysql_query("SELECT activate, COUNT(activate) FROM customers WHERE activate!='0'"); while($row = mysql_fetch_array($result)) { echo "There are ". $row['COUNT(activate)'] ." total users."; echo "<br />"; } //CLOSE THE DATABASE CONNECTION mysql_close($con);
  8. You'll need to place the include statement on every page that needs to use those functions. Do you have any other file that's already being included on every page? For example, do you have a header or footer file being included? If so, you should be able to add the include statement for functions.php in one of those files.
  9. Are you talking about removing cookies set by other website (Google, Yahoo, etc.) or just the ones set by your own?
  10. Will not stop the massive SPAM I don't think that will stop any spam, that code is meant to help prevent SQL injections.
  11. FYI, this isn't an SQL injection attack. This sounds like plain old comment spam. There are several techniques you can use to limit the amount of spam you get. For more information on some of the techniques, check out: http://webaim.org/blog/spam_free_accessible_forms/
  12. Are you hosting the website with a company? If so, do they have an admin panel? They may have an option to create a sub-domain there.
  13. I'm not sure what the above echo statement is doing, but it seems like all you should need to do is a somewhat simple date comparison. You could try to do something like this: //ARRAY OF DATES USED TO TEST DATE COMPARISON $dateArray = array('2010-05-14', '2000-11-02', '2010-04-15', '2010-06-15', '2010-05-10', '2010-05-01', '2010-04-30', '2010-04-29'); //GET CURRENT DATE INFORMATION $currentYear = date('Y'); $currentMonth = date('m'); $currentDay = date('d'); //GET DATE USED TO DETERMINE IF AN ENTRY SHOULD BE STYLED $oldDate = mktime(0, 0, 0, $currentMonth, $currentDay-14, $currentYear); //subtract 14 days from the current date $oldDate = date('Y-m-d', $oldDate); //LOOP THROUGH THE ARRAY OF DATES foreach($dateArray as $dateToTest) { if($dateToTest < $oldDate) { echo "<p>$dateToTest needs to be styled; it's more than 14 days old.</p>"; } else { echo "<p>$dateToTest doesn't need to be styled.</p>"; } } Note that all of your dates will need to be formated as YYYY-MM-DD for this to work.
  14. Those variables are likely to have come from a tutorial on connecting to a MySQL database. I've seen a lot of scripts which declare their variables first: $hostname = "test.net"; $username = "test"; $password = "test"; Then, use the variables to connect to the database: $con = mysql_connect($hostname, $username, $password); This is my preferred method also since it makes the code a little cleaner. Therefore easier to maintain.
  15. Everything appears to be working great. I have however found that the solution doesn't work if the method attribute is set to 'get'.
  16. Yep, just click the button that has the # on it or . Both will place the selected code into a box that looks different from the rest of the message.
  17. Yep, the action attribute is required to be valid XHTML.
  18. Awesome, thanks andrewgauger and Mchl! That makes the process so much simplier...now I don't need add variables everywhere.
  19. @liamloveslearning Are you familiar with JavaScript? If so, you should be able to do something like this: <form name="myForm"> <label for="intraartapproval">Art Appr. Date</label> <input type="text" name="intraartapproval" id="intraartapproval" size="32" onchange="myForm.intraestimatedinstall.value = Number(this.value) + 14;" /><br /> <label for="intraestimatedinstall">Est. Install</label> <input type="text" name="intraestimatedinstall" id="intraestimatedinstall" size="32" /> </form> Note that the above code only works with integers. You'll need to modify the code to work with dates. It looks like it may be a little bit of work, but you should be able to use some of the JavaScript functions found here: http://www.elated.com/articles/working-with-dates/
  20. I'm not sure what you mean? Are you asking why I'm using single quotes around the action attribute value (action='$redirect') instead of double quotes (action="$redirect")? If so, I'm using single quotes because I'm already using double quotes around the entire <form> tag: echo "<form method='post' name='form' action='$redirect'>"; I could use double quotes again, but I would need to escape them: echo "<form method='post' name='form' action=\"$redirect\">";
  21. Is there anything I need to be careful of with using REQUEST_URI? I'm updating a login script so that it works with URLs that contain variables. What I want to do is create a variable: $redirect = $_SERVER['REQUEST_URI']; Then for the part which displays the login form as needed, I'll add the following code: if($redirect != '') { echo "<form method='post' name='form' action='$redirect'>"; } else { echo "<form method='post' name='form' action='$_SERVER[php_SELF]'>"; } //...display the rest of the form Basically the $redirect variable will only be created for pages that require someone to be logged in before they can view the page content. Also, the GET variables will be sanitized as needed after they log in.
  22. Is there a reason why you need to redirect to the thank you page? I usually prefer to have the thank you message in the same script. . . . if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } //SEND E-MAIL MESSAGE TO USER AND WEBMASTER /* add code to send message here */ //DISPLAY THANK YOU MESSAGE echo "<p>Thanks, your information has been added to the database.</p>"; mysql_close($con) ?> </body> </html>
  23. The header function needs to be called before anything is printed to the screen.
  24. I have the same problem with one of my scripts. I haven't gotten around to coding any kind of solution, but here is what I plan to do. Run a quick test against the database for exact duplicates (first name, last name, username, etc.) If a record is found, do nothing Else, add the new record
  25. A simple solution to at least highlight the code would be: <form> <textarea name="code" onfocus="this.select();"> <?php echo '<html>'; echo '<body>'; echo '<p>Hello World</p>'; echo '<body>'; echo '</html>'; ?> </textarea> </form> Of course this solution doesn't do the copy part. I would need to brush up on my JavaScript to figure that out.
×
×
  • 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.