Jump to content

Darkranger85

Members
  • Posts

    44
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Darkranger85's Achievements

Member

Member (2/5)

0

Reputation

  1. I apologize, I do tend to do that. I assure you, it's not because of laziness, it's because of excitement. Stuff starts working and I just start rapidfire. I'll try to improve. I am having another issue. If you would like feel free to make me work for my answer, I'm all for working things out I just need some guidance. The script before was a mock up that I was using to get the hang of using the ajax function. Now, I hooked it up to my real php file that has the actual arrays I'm working with in my project. The thing is, it doesn't work even though it seems to be setup exactly the same. if I change the url in the ajax function back to the test file, it works fine. This is the real file: <?php session_start(); include 'configs/starting.config.php'; require 'connection/connect.php'; require 'functions/general.lib.php'; require 'functions/users.lib.php'; require 'functions/chatbox.lib.php'; $errors = array('Error'); $success = array('Success'); /*-Export PHP Arrays to jQuery (init.js)-*/ echo json_encode($export = array( 'errors'=>$errors, 'success'=>$success )); /*----------*----------*/ ?> And this is the original test file: <?php $errors = array('Error'); $success = array('Success'); echo json_encode($export = array( 'errors'=>$errors, 'success'=>$success )); ?> I don't see a difference. The arrays are the same and I copy and pasted the json function so it has to be the same. The two files are in the same directory, so it shouldn't be a file path issue.
  2. But I'm assuming that would effect how I would have to setup the for loop in order to put them into their own arrays on the JS side right?
  3. Awesome! And I just thought of another thing lol. Hope ya don't tar and feather me lol. What if I want to get two separate arrays from my php file? For instance I have the $errors array but I also have a $success array. I'd need to put them in separate JavaScript arrays.
  4. Well, hopefully I can get it lol. On a side note, do you guys know if I can mimic this functionality with jQuery: EDIT: Specifically the include part. <?php if(!empty($errors)){ include 'includes/modules/error.mod.php'; }else if(!empty($success)){ include 'includes/modules/success.mod.php'; } ?>
  5. Ah! That would do it wouldn't it lol. Thanks man, I really appreciate the help! I'm just getting into JavaScript and I'm finding it a lot less forgiving than PHP was lol.
  6. Crap, the studentArray was left behind from a tutorial I was following. Here is the current code. Still gives me the same error and I'm sure called console.log on the fist line of the success function. $(document).ready(function(){ /*-AJAX Request-*/ $.ajax({ type: 'POST', url: 'core/content.php', data: '', dataType: 'json', cache: false, success: function(result){ console.log(result); var errors = new array(); for(i=0;i<result.length;i++){ errors[i] = result[i]; } $('#content').html(result[0]); } }).error(function(){ alert('Some error occurred!'); }); /*----------END AJAX----------*/ });
  7. Irate: I assume you mean 'alert(result);' inside of the success function. If so, it alerts 'An error has been detected,And stuff'. So I know the information from the PHP script is in there. cpd: The console says: Uncaught ReferenceError: array is not defined init.js:11 $.ajax.successinit.js:11 cjquery.js:4 p.fireWithjquery.js:4 kjquery.js:6 r
  8. Hey all, I'm trying to get a php array using AJAX in order to load it into a JavaScript array. I've managed to retrieve the PHP arrays information but I can't seem to figure out how to get it into a JavaScript array. When I run the code and just have it use 'result' in the success function it shows all the data from the PHP array, so I know the information is there. Here is my code so far. JavaScript: $(document).ready(function(){ /*-Click Button-*/ $('#button').click(function(){ /*-AJAX Request-*/ $.ajax({ type: 'POST', url: 'core/content.php', data: '', dataType: 'json', cache: false, success: function(result){ var errors = new array(); for(i=0;i<studentArray.length;i++){ errors[i] = Array[i]; } console.log(errors); $('#content').html(errors[0]); } }).error(function(){ alert('Some error occured!'); }); /*----------END AJAX----------*/ }); /*----------End Button Click----------*/ }); And the PHP: <?php $errors = array('An error has been detected!', 'And stuff'); echo json_encode($errors); ?> I appreciate any and all help! Thanks guys!
  9. Noted! And it works! Thank you both for your very quick replies!
  10. Hey guys, I'm having a problem with my code and am hoping that someone can help me narrow it down. The full error I get is as follows: Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ')' in C:\wamp\www\testsite\login.php on line 9 Here is the code is question <?php include 'core.inc.php'; include 'connect.inc.php'; session_start(); $username = strip_tags(trim($_POST['user'])); $password = strip_tags(trim($_POST['pass'])); if(!empty($username&&$password)){ mysql_select_db('adatabase') or die('Couldnt connect to db!'); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if($numrows != 0){ while ($row = mysql_fetch_assoc($query)){ $dbusername = $row['username']; $dbpassword = $row['password']; $salt = $row['salt']; $password = crypt($password,$salt); $seclevel = $row['seclevel']; } if($seclevel > 1){ die('Please activate your account before logging in.'); } if ($username == $dbusername && $password == $dbpassword){ echo "Welcome back! Click <a href='overview.php'>here</a> to proceed!"; $_SESSION['username'] = $dbusername; }else{ echo "Incorrect username or password!"; } }else{ die ('Incorrect username or password!'); } }else{ die('Please enter a username and password!'); } ?> I've been staring at it all morning and I cant for the life of me figure out where a parenthesis is missing. I went down the code line by line and checked every single one to make sure it had a "mate" so to speak. And as for the unexpected "T_BOOLEAN" I have no idea lol. Thanks for your help in advance!
  11. Sorry, I should have also included this: function empty(obj) { if (typeof obj == 'undefined' || obj === null || obj === '') return true; if (typeof obj == 'number' && isNaN(obj)) return true; if (obj instanceof Date && isNaN(Number(obj))) return true; return false; } my own empty function!
  12. Thanks, that's good to know! I guess a lot of my problem comes from not knowing the syntax all that well. But, thinking back, I guess it was the same when I started learning PHP. Getting errors in just about every single test run, normally ending up being something stupid like missing a semi colon and such lol. But I just can't figure this out. function RegValidate(){ var error = new Array(); //Setup error array and validation variables// var _user = document.forms['register'].username.value; var _pass = document.forms['register'].password.value; var _pass2 = document.forms['register'].password2.value; var _email = document.forms['register'].email.value; var _email2 = document.forms['register'].email2.value; if(empty(_user)){ error[] = 'Please enter a username.'; alert('I hate JavaScript!'); } } The code stopped working after I tried to add string to the error array. I looked up arrays and how to insert information into them and it seems right to me.
  13. Hey guys, I'm trying to add a little bit of JavaScript to my toolbox of knowledge and I'm finding that, for me, it's a lot harder to pick up than PHP was. The main reason for this being that when there is an error in my code, it doesn't seem to tell me anything about the error. It just "doesn't work." This is extremely frustrating because it makes my progress very very slow because I have to sit there and search my entire code trying to find where the error is and considering I just started learning JS, that can take a long time cause I'm not as familiar with the syntax. Is there some kind of "error reporting" that I have to turn on or something? Thanks!
  14. Thats an awesome idea! That will save me a crap load of work and headaches lol. Thanks alot!
  15. Hey all, In my user registration system I'm trying to figure something out. When the user puts in his information and hits submit it goes into a temporary user table while it waits for the user to click on the activation code in the email that is sent out. Once they click on it it's then transferred into the user table. Now, I have a few questions: 1. Should the user check on the registration screen check both tables for a username match? What if someone starts a registration but never activates it. That username, though not in use, is now taken up in the tempuser table. 2. Should the information in the temporary table be cleared after it is moved into the regular table? Thanks guys!
×
×
  • 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.