Jump to content


Popular Content

Showing most liked content since 10/15/2017 in all areas

  1. 1 point
    According to the documentation for the ajax method, beforeSend is called before the request is even sent. The 2 parameters that the function gets passed are the jQuery XHR object, and the settings object. So in your code, podType is set to the jQuery XHR object. The beforeSend function is really for modifying the request before it goes out (or canceling it), so I would think your code for changing the page should all go in the success function. Inside that success function podType will still have the value it had when you send the request, unless you change the value inside the function. You also need to quote all of those values in your case statements, otherwise you're trying to compare the value with different variables.
  2. 1 point
    The reason why your code isn't working is because $con is not defined in those functions (and $pass and $conf_pass are not defined in newUser either). You can use global variables inside the function, but it's better to avoid globals and pass in any variables you want the functions to use. So you should pass $con to the functions. You should add this to the top of your code: ini_set('display_errors', 1); error_reporting(E_ALL); You should switch your database code to use prepared statements instead of trying to manually escape everything. Prepared statements offer better security. You can use prepared statements with mysqli, but it's better to use PDO. The PDO code is shorter and easier to understand, and PDO works with databases other than only MySQL. e.g.: $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); if ($stmt->execute(array($username))) { if ($row = $stmt->fetch()) { // it found a user } } http://php.net/manual/en/book.pdo.php For the code I posted above, I was saying that each function should only do one thing. Your newUser function should only validate and add the user if necessary, it should not also output anything or redirect. Your main code should do that based on what the function returned. If you want to return multiple values you can use an array like I did above to return a "success" value for whether the user was added, and a message to show them. So your main code would call that function and then decide what to do. Those header redirects wouldn't work though, because you sent output to the browser first. $result = newUser(...); if ($result['success']) { // maybe redirect to a thank-you page or something } else { // show the error in $result['message'] }
  3. 1 point
    The forum completely wiped out my reply when I tried to edit my post, because the forum software is awesome. I'll try that again.
  4. 1 point
    function newUser ($username, $password){ $return = ['success' => false, 'message' => '']; if (!isExist($username)) { if (passChk($pass, $conf_pass)){ // insert into the database here $return['message'] = 'Username Created successfully'; $return['success'] = true; } else { $return['message'] = "Password and confirmed password do not match"; } } else { $return['message'] = 'Username already exists'; } return $return; }
  5. 1 point
    .w3-cell-row { margin: auto; margin-top: 0; width: 79%; border-collapse: collapse; /* margin-bottom: -10px;*/ } .w3-cell { background-color: #fff; border: 5px solid #00c; /* margin-bottom: -10px;*/ border-bottom: none; } .w3-cell-row:before, .w3-cell-row:after { content: none; } .w3-cell-row:last-child {border-bottom: 5px solid #00c;}
  6. 1 point
    Yes, you would use an array of objects as shown. As far as file types, it's not very common to have a static file only containing JSON that you read from, they just do that because it's an easy example. It's more likely that you'll be sending ajax requests to PHP or another language on the backend which would dynamically generate the JSON (from a database, as in your example). You can use PHP or whatever language to set the content-type for JSON though, rather than saying it's HTML.
  7. 1 point
    You can use a php function called is_numeric(). if(is_numeric($var)) { //do stuff } else { //do other stuff } Hope this is what you want.