Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. What do you mean it was converted to HTML? It is a PHP file. It does output HTML though. So, what was it before it was converted when it did work? FYI, there are errors in that PHP code. Whoever created that PHP file didn't doa great job.
  2. Calling JavaScript from a different site than the page is loaded creates security risks and will be problematic. You can instead create a service on www.2.com that is called either from the JavaScript loaded from the page on www.1.com or have your JavaScript call a PHP page on www.1.com which then calls the service on www.2.com. The service should be a page that accepts the parameters as GET or POST vars.
  3. Yes, it makes sense. And, as I stated, I tested the code in both IE and Chrome and found it to be working. So, my guess is the problem is due to the browser you are using or you are implementing other code along with this that is not provided.
  4. OK, this may not fix your problem, but at least you would be starting from a much cleaner bit of code. As before, this does work for me - both in FF & IE. If there is an error the page does not submit. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Ballard Social</title> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <style> body { background-color: #ddeae7; } #signUpFormTable{ border: 1px solid #bfc2c1; padding: 10px; margin: auto; margin-top: 100px; background: #ffffff; width: 355px; text-align: center; } #formTitle{ color: #4c4f4e; font: bold 16px arial, verdana, serif; } #formText{ font-size: 12px; } </style> <script type='text/javascript'> function validEmail(emailStr) { //Return true/false for valid/invalid email formatTest = /^[\w!#$%&\'*+\-\/=?^`{|}~]+(\.[\w!#$%&\'*+\-\/=?^`{|}~]+)*@[a-z\d]([a-z\d-]{0,62}[a-z\d])?(\.[a-z\d]([a-z\d-]{0,62}[a-z\d])?)*\.[a-z]{2,6}$/i lengthTest = /^(.{1,64})@(.{4,255})$/ return (formatTest.test(emailStr) && lengthTest.test(emailStr)); } function pValidateForm() { var emailVal = document.getElementById('email').value; if(!validEmail(emailVal)) { alert('Not a valid e-mail address'); return false; } return true; } </script> </head> <body> <div id="signUpFormTable"> <form onsubmit='return pValidateForm()' action="pAddEmail_BallardSocial_1_validate.php" method="post" name='myForm' id='myForm'> <span id="formTitle">Sign Up on the Email List</span><br> <span id="formText">You will be notified of the next Ballard Social event</span><br> <input type="Hidden" name="SourcePage" value="SignUp.htm"> <input name="Email" id="email" type="text" size="28" placeholder="enter your email address"> <input name="OK2" type="submit" value="OK"> </form> </div> </body> </HTML>
  5. Well, the first thing I thought was that you were not doing a "return false" to prevent the form from submitting. But, it seems you are. So the second thing to look for is some JavaScript erroring out. But, I don't see any obvious problems there. So, I went ahead and copied/pasted the code (as is) into a document and it worked perfectly. Page does not submit if there is an error in the email logic. I'm using FF, so the problem could be browser specific. You have the JavaScript code block after the HTML closing tag. I don't know if that is even valid markup (I'm thinking not). Try moving that code block within the HTML tags, preferably within the HEAD tags. EDIT: I just took a closer look at that code and - where are you learning to code? FONT tags, really? Those have been deprecated for over a decade. Also, your process for validating the email is pretty worthless since it only validates the content has an "@" and a "." and that the period comes after.
  6. There is no way for us to provide any help based upon what you have posted. But, to your point, no there is no way that any MySQL code would magically appear on a page if it didn't exist in the code.
  7. You need to crawl before you walk. What you have doesn't appear to be anything like what you are after. The square brackets are defining a class of characters to be matched - not specific sequences of characters. What, EXACTLY, are you trying to achieve? Show some potential input strings and the matches you are trying to achieve. If you are trying to match the number VALUE that is from 20 to 30, then you should be looking for two characters where the first character is a '2' and the second characters is a numeral OR where both characters are '30' preg_match('#2\d|30#', $input)
  8. Psycho

    ID to GUID

    To add the GUIDs run this UPDATE table_name SET GUID_Field = UUID() WHERE GUID_Field = '' OR GUID_Field IS NULL Replace "table_name" and "GUID_field" with the appropriate names. As for updating the links, as Ch0cu3r stated, you need to find the code that creates those links and change it. It's impossible for us to tell you how to do that since we don't know anything about the code as you have failed to provide any. Most likely you will need to find the SELECT query that is used to get the data and ensure the GUID field is included in the SELECT parameters. Then find the code that produces the links and change them to use that value as well.
  9. Psycho

    ID to GUID

    Do you mean to say that you have a table with a primary key and a GUID key field and you want to replace instances of the Primary key used as foreign keys in other tables with the GUID? If so, it is as simple as running an UPDATE query with a JOIN for each of those tables. Example: UPDATE related_table JOIN primary_table ON related_table.foreign_key_name = primary_table.primary_key_name SET related_table.foreign_key_name = primary_table.guid
  10. What site is this? If the site is offering their functionality for others to use then they most likely have developed an API for it. If there is no API, then my guess is that the site doesn't want you to use their functionality for 3rd party sites. So, helping you would likely violate that sites ToS.
  11. Since all the articles will always be associated with a category you should just use a normal JOIN. And since you are joining on the same field name, you can use the USING() function. SELECT title, url, cat FROM `articles` JOIN `categories` USING(catid) ORDER BY cat ASC Also, there is some inefficiency in the logic. For example, why have a line of code at the end of the if() condition to output the article and then have an else statement to output the same thing? Remove that line from the if() condition and then have it come after the if condition. It will then get executed on each iteration of the while() loop. Never write code to do the same thing more than once. Also, when I have to do something at the end of a group (i.e. the category) I prefer to put the data into an array first. It makes the code much cleaner for the output - in my opinion. $sql = "SELECT title, url, cat FROM `articles` JOIN `categories` USING(catid) ORDER BY cat, title ASC"; $results = mysql_query($sql, $conn) or die(mysql_error()); if(!mysql_num_rows($results)) { echo "<p>No articles found.</p>"; } else { $data = array(); while($row = mysql_fetch_assoc($results)) { $data[$row['cat']][] = $row; } foreach($data as $category => $articles) { echo "<ol>\n"; echo "<h3>{$category}</h3>\n"; foreach($articles as $article) { echo "<li><a href=\"{$article['url']}\">{$article['title']}</a></li>\n"; } echo "</ol>\n"; } }
  12. I didn't realize in my initial post that there were multiple levels of children.
  13. Also, the site you liked to has Term of Service which state, in part: Also Six months?
  14. A couple other points. 1. You are calling the parent function with an ech0, but the functions themselves are echoing content. The functions should return the content. 2. You use GLOBAL $_SESSION in the functions. The $_SESSION variable is global by default. 3. You are referencing array values with a non-numeric index that is not enclosed in quotes. That will work but is very inefficient since the PHP parser will first look for a constant of that name then, if that doesn't exist, it will then treat it as a text. As to your problem, I see it has many levels. There are numerous articles about handling Hierarchical data in queries. But, that aside, you can get all the data with a greatly reduced number of queries. First query all the records at the parent level. Then query ALL the records at the next level instead of getting the child records for each parent individually.
  15. NEVER run queries in loops unless absolutely necessary - and this isn't necessary. You need to JOIN the tables to get all the data you need in one query. I'll take a look and post back.
  16. Well, it's not entirely clear what you are trying to accomplish. If you want something to dynamically display in the browser with data from the server without a page refresh, then AJAX is what you want. But, your specific example seems to be an 'odd' implementation, so I assume you have something else in mind.
  17. << Moving topic to AJAX forum >> 1. Your textarea tag is not properly formed. A textarea has an opening and a closing tag. <textarea>Context goes here</textarea>. I can't believe you don't see this as it completely corrupts the page. 2. The "onreadystatechange" action is recursively calling the clothing function or it is redefining the clothing function. Either way it is wrong. Either create a seaparate function for that process and call that function or don't name the function process. 3. The button is submitting the form (at least it is in FF). Not sure why since it is not a submit button. So even if everything else was working correctly, the value would only populate the textarea briefly until the form is submitted. Then the page would be recreated and the field would be empty again. You can put a "return false" after the function call in the onClick call to prevent this. 4. You should really be using something like JQuery for AJAX since it has been used by thousands across different Browsers and Versions. By creating your own you will need to test all those different configurations. <html> <head> <script language="Javascript"> function clothing(form) { clothingname = form.order.options[form.order.selectedIndex].text; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("recap").value = xmlhttp.responseText; } } xmlhttp.open("GET","clothingvar.php?q="+clothingname, true); xmlhttp.send(); return false; } </script> </head> <body> <textarea id="recap" rows="10" readonly></textarea><br /> <form><select name="order" id="selection"> <option>Shirt <option>Shoes <option>Pants </select><br /> <td colspan=2><button onClick="clothing(this.form);return false;">Select</button></form> </body> </html>
  18. Your query is failing and returning false. The IN clause uses parens () around the list of values not curly braces {}. Plus, using a foreach loop to create the list of values and then removing the last comma is a waste when you can do it all in a single line using implode(). //Ensure all values are integers and remove 0 values $prodIDs = array_filter(array_map('intval', $_SESSION['cart'])); //Create comma separated list $prodIDList = implode(', ', $prodIDs); $sql = "SELECT * FROM products WHERE id_products IN ($prodIDList) ORDER BY id_products ASC"; $query = mysql_query($sql);
  19. Well, just be sure that you want to receive such an email. At a minimum you would want to log them so the data is in one place instead of tracking down emails. As for using error_get_last(), well that only tells you about PHP errors. A function to get a salesperson's data could just as easily malfunction in the DB call. Of course, you could check for that and then throw a PHP error with the details of the DB error. Then you could get the data using error_get_last(). At this point, we're down to personal preference on how to build a good error reporting framework. You could just as easily build your own function to call when any type of error occurs, pass it the file name, line number, actual error message, relevant variable values, etc. etc.
  20. Either one - just so long as your PHP installation can connect to that server.
  21. Is the file named as a *.php file on the web server? Is the web sever configured to support PHP? Are you accessig the file through a webserver and not just opening it in your browser directly from your file system?
  22. Think about what you just said. The function fetchArray() will return false if there are no more rows in the result set. So, what do you think will happen if NO rows were in the result set and you called fetchArray()? Hint: it would return false!. Since you are expecting only one record, the code calls fetchArray() once, so if it returns false you know there were no records in the result set (although the code currently has no handling n the case of a failed query) - thus tthere was no record that matched the email address. This is basic logic. Ah, the results are being fetched using fetchArray(), not fetchObject(), so the references to the values need to be as an array and not an object. Change elseif($psswd == $user->password) to elseif($psswd == $user['password'])
  23. <?php $email = $_POST['email']; $psswd = $_POST['psswd']; $db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE); if(!$db) { echo "Could not open/access DB"; } else { $result = $db->query("SELECT email, password FROM users WHERE email='$email'"); $user = $result->fetchArray(); if(!$user) { echo "No user match found in database."; } elseif($psswd == $user->password) { echo "You have already changed your password"; } else { $file = fopen("./accounts.txt", 'r+') or die("Failed to open file"); while(!feof($file)) { $line = fgets($file); if(strpos($line, $email) !== false) { if(strpos($line, $psswd) !== false) { header("location: ./changepassword.html"); } else { echo "User was a match in accounts.txt, Invalid password"; } exit(); } } fclose($file); echo "No user match found in accounts.txt file."; } } ?>
  24. Read the documentation. fetchArray(0 returns - an array! You are then trying to compare the string values sent in the POST data to those arrays - which will never return true.
  25. Your query doesn't make sense to me since "Exceptions" and the use of if/else conditions are not mutually exclusive. You would normally use a control such as if/else to make a determination on whether to throw an exception or not anyway. Having said that, what I *think* you meant to ask is when does it make sense to throw an exception as opposed to writing functionality to handle the error in the code, e.g. echoing the error. That is a good question and it does not always have an easy answer. I guess I would state that Exceptions should primarily be used for unanticipated situations that an error would prevent the code from completing and providing a complete output. Versus a situation that could be expected to happen. For example, let's say you have code to calculate the the percentage of a salesperson's sales are made from "widgets" in a given time period. That would be calculated as (widget sales / total sales). What if the salesperson doesn't have any sales during the given time period? That would lead to a division by zero error. But, that is a perfectly valid scenario and needs to be handled in the code to provide an acceptable output rather than throwing a system error if($totalSales==0) { $percentage = 'N/A'; } else { $percentage = $widgetSales / $totalSales; } Now, let's take that one step further. Let's say you have a function to determine a salesperson's sales for a given period so you can perform the above calculation. If that function fails because of bad input data, DB error, etc. then you simply can't provide a response to fulfill the request for the percentage of widget sales. This would be a situation where it could be appropriate to throw an error. But, that doesn't mean you can't also have code to provide a good user response. That's because you can suppress errors to the user. That allows you to provide the user with friendly messaging in a production environment while allowing you to debug errors in a test environment. So, let's say you have a loop to iterate over five salespeople to provide their sales data. In that loop you call a method to get the salesperson's data. If that method fails then you can't generate the output for that sales person. That might be a good place to implement an exception. So, the method would throw the exception (e.g. "Unable to get sales data for $salesPerson") and the method would return false to the calling code. That code would see the false result and provide something such as "Sales data unavailable at this time." for that particular sales person. The user would only see that and not the exception (assuming error reporting was at the appropriate level).
×
×
  • 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.