last day (15 days later) » 

11:02 PM
0
Q: Check Database result based on condition

AuroraMy problem is as follows. I want javascript to check if a value exists in the database. I have a javascript function which checks if an email adress exists in the database. That one is working fine, so i made copy of it and changed it to match a different input field, which should check if a valu...

 
Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy.
 
What is the problem ?
 
return false; in your success callback does not prevent the submission, the return statement has to be directly in the submit callback function (eg checkMailStatus, checkCityStatus ). Also you have checkMailStatus() & checkCityStatus() a single & is a bitwise operator while && is a logical operator, you want to use the latter
 
@Poria It doesn't perform a check for 'woonplaats', instead, even if it does exist, it always shows 'woonplaats doesn't exist. I'll edit it in my question, because you're right, it's not clear.
 
Your PHP code starts if(isset($_POST['register'])) { I dont see a variable called register being sent to this script anywhere so it cannot be running anything
 
11:02 PM
The HTML, PHP code with the SQL which checks the database and the javascript are all in the same PHP file...don't put everything in one page, send your AJAX request to a different page and process it there.
 
I see you editied your question and added a name="register" to the button, but is that code there in your real code and has that changed what the code is now doing???
 
@RiggsFolly yes i edited it for you, and yes it's in my real code and it hasn't changed what it's doing.
@RajdeepPaul You already helped me out once, i'm still thankfull for that. I'm creating a check.php. Should i put every check in there or do i have to make a different php for every check?
 
@Aurora It's based on your requirement, you can put all your status checking code in check.php page, but you have to make few changes. In each of the AJAX request, you've to change the data setting, like this: data: {email: email, checkMail: true} or data: {keyword: keyword, checkCity: true}, and on check.php page, process your AJAX request like this: if($_POST['checkMail'] == "true"){ // code to check mail } if($_POST['checkCity'] == "true"){ // code to check city }
 
@RajdeepPaul I edited my index.php file and made a check.php file based on your awnser and on pioz his / or her awnser. I edited it in my question. I still can't get it to work. I did not change the register button as Pioz suggested. I also have no idea how to comment on Pioz' awnser because there is no comment button underneath the awnser...
 
@Aurora Could you please explain what you're trying to do in with this html form? Do you want to register an email, or keyword if it doesn't already exist in the database?
 
11:02 PM
@RajdeepPaul No, i want it to register the e-mail address, but it has to check first if it already exists and if it does, display an error and stop the form from registering. For 'keyword', it has to check the database if a place name (woonplaats) exists. If the placename is not in the database, also give an error and stop it from registering. (to prevent people registering fake place names)
 
@Aurora I've given an answer below. Hopefully this will resolve your issue.
 
@RajdeepPaul First of all thank you! I changed it. Now it sends messages if an email address exists, but it doesn't give back a message if a place name doesnt exist...
 
@Aurora please comment on my answer below. Edit: see the comment, just below my answer.
 
@Aurora Test it out yourself here: jsfiddle.net/9k8d6kfw It is important to notice that the alerted message is nowhere in entire code: JS or HTML, which means it is coming from the PHP File on the Server.
 
@RajdeepPaul I did comment, it gives a message if an e-mail address doesnt exist, but it doesn't give a message when i fill in a wrong placename
 
11:02 PM
@Aurora See my comment. And comment there.
 
@Poiz I'm sorry for my late response, i tested it again after testing Rajdeep's code, but when i try, it somehow doesnt do anything. doesnt register, no message, nothing.
 
@Aurora What? You tested the the Link here: jsfiddle.net/9k8d6kfw
@Aurora I mean L-I-V-E Testing which everybody can confirm... it is in JS Fiddle... not the Local Test (because, honestly; no one can see what you are doing there) but it is the same code here that is at JS Fiddle.... Just click on the URL to see it yourself: jsfiddle.net/9k8d6kfw Enter your Email & City and hit Register to see what happens...
 
@RajdeepPaul i have tested it again. When i use an e-mail address which already exists, it gives an error. when i use one which doesnt, i dont get an error. when i use a placename which doesnt exist, (after correcting the email address) it DOES give an error! but after correcting it, it wont register
@Poiz First of all 10.000 kisses for helping me and i did use the link and i did see it work. i reallyreallyreally tested it on my test site and don't get a message, nothing... and it won't register...
 
@Aurora... show us your PHP Code containing the Database Connection & Stuff... You can copy the entire PHP Code, then go to eval.in and paste it. Then copy the URL and paste it back here....
 
@Aurora So the code does work, just as you expect. BTW, do you have the registration code in index.php page? Because right now, I don't see any code to register anything.
 
11:02 PM
@RajdeepPaul Exactly... No code for Registration.... The problem is in her PHP Codes.... even all your Codes and Example should do the Trick when followed accurately... The Problem is that no one knows exactly what her PHP looks like back there and it's difficult to imagine... That's why i suggested she should paste her Codes either at eval.in or pastebin.com So that we can all be on the same sheet of music...
 
@Poiz Totally agree with you. :-) @Aurora, also share your users table structure.
 
@RajdeepPaul I will add the full index.php right away, hold on please
 
@Aurora You know that you are using JQuery, right? Not Raw JS. So: the very first line of code in your JS Block should read as follows: (function ($) { $(document).ready(function(e) { and the very last lines just before the the closing script tag should read as Follows: }); })(jQuery); Otherwise your Code wouldn't work!
 
@Poiz I had no idea there was a difference...i am still learning everything about programming...
@Poiz I tried again and added your new code. It's still not working. Nothing at all, i'm sorry...
@RajdeepPaul or is there anything else you need?
@Poiz is there anything else you need?
 
@Aurora The code you Posted at pastebin.com has been refactored. With the exception of a few minor tweaks, the File is almost identical to your original file. So, please make a backup of your original file and go copy the code here: eval.in/572918. Replace the content (code) with the current one you have.... For the check.php File; You can find the code here too: eval.in/572917 Try it out and let us know how it went... Remember to backup the originals, Please!!!
@Aurora SORRY The link to the check.php is the old one! Here is the Correct Link to the check.php File: eval.in/572927 NOTE: You may have to reload the Page if you get a Server Error. No cause for alarm... That is because we are requiring files that doesn't exist.... Keep that in mind...
 
11:02 PM
@Poiz I did exactly as described. I even made a db connection in the check.php it doesnt do anything and i feel so sorry, because both you have been at this for hours...
 
@Aurora ...by choice... not force ;-) Wait for Paul's Solution...
@Aurora YEEEEEEEE!!!! GOTCHA!!!! Change the check.php File to this and let's see if it's Time to Dance some Salsa: eval.in/572945
 
@Poiz I will, sorry, i thought you were working together somehow...xx
 
@Aurora We were doing if(isset($_POST['register'])) { inside the check.php File. That's Wrong as register was not posted... so, please replace the contents of check.php with this one: eval.in/572945
 
@Poiz I updated check.php, it now gives a message (Hooray!) that the email is already taken. But it still doesnt show a message saying the place name doesnt exist. If i choose a place name from the drop down, the dropdown wont dissapear after choosing anymore
@Poiz Hold on please, ill update
@Poiz I updated check.php, it now gives a message that the email is already taken. But it still doesnt show a message saying the place name doesnt exist. If i choose a place name from the drop down, the dropdown wont dissapear after choosing anymore (so it's still the same)
 
@Aurora LOL The very last and last and last and last thing ;-) Update the Javascript on that page using this code:eval.in/572947 Just delete the entire script block at the end of the page and replace it with the one you copied from eval.in/572947...
 
11:02 PM
@Poiz Lol i updated and tried, but it's still the same problem...
 
@Aurora Do you have Team Viewer??? or Skype??? With Team Viewer, We can share screens: You can see mine and I can see yours... It is Free and you can get it here: For Windows - teamviewer.com/en/download/windows or for Mac - teamviewer.com/en/download/mac or for Linux - teamviewer.com/en/download/linux It may be a little easier... And I also could work on your machine as if i was there beside you... It's worth the try... if you will
 
@Poiz i have neighter... not even a facebook account...
@Poiz im downloading teamviewer x
 
@Aurora It's not like FaceBook or any Social Media thing. It is just an Application that lets People collaborate on a Project even from very remote Locations. No profile is needed... not your name or address or photo... just download the Program, install it and off you go... that's why it's rightly called team viewer.. it helps coordinates work from people in different Geographical Locations as if they are in the same Office... OK... You may need (at some point to provide your Email) in which case you just have to provide a pseudo Email Address. No-Big Deal, huh?
 
@Poiz I just installed it! so how can we connect and share screens?
 
@Aurora What System are you on? Mac, Window or Linux?
 
11:02 PM
@Poiz windowssss
 
@Aurora Launch the App. Then login... On then Left side of the Window, You'd notice a section that reads Allow remote control::: Copy the ID and and send it to me here*
 
So you will be able to control my computer?
 
Moderators have move the discussion to a chat room... And sure it got too much... the are right...
No... I will not
 
yes they are right
 
@Poiz Please lay off the extremely annoying use of bold and italics in your comments. The next time you want to add *** to your comments, DON'T.
 
11:05 PM
by the way
thank you so much for all of your help
 
I will just see your screen
 
802 430 402
 
password...
?
 
tez861
 
Invalid Password...
 
11:07 PM
i dont understand
 
its ok
 
i sent the password underneath the id
 
@Aurora Just a heads up, it is extremely unwise to install software based on the recommendation of somebody you met online.
Especially to give them any degree of remote access to your computer.
Please exercise caution.
 
@meagar You are right but if everyone really thinks like you do; the world would be chaos...
@meag
@meagar This is an open chat and you see it as well as anybody else...
You also have my ip address too
 
@meagar, thank you for making me aware, i have heard of this program before.
 
11:11 PM
now what would happen when someone shares a screen with another....
Com'on man...
It is not necessary to discuss this any further....
@meagar TRUST IS ONE THING THAT THE WORLD NEEDS MORE THAN YOUR TECHNOLOGY AND INTELLIGENCE
To look without leaping is Courage...
And to Trust someone who might even harm you is the greatest Demonstration of Innocence and Purity.....
But hey!!! Who am i now to tell you anything about that? You know it better....
 
Even though that could buildt false trust if someone in the end does take advantage
;)
 
In my world; there is the concept of what goes around coming around....
You cannot escape some natural laws...
 
Point of clarification:
> And to Trust someone who might even harm you is the greatest Demonstration of Innocence and Purity.....
 
if you take advantage of someone's open mindedness and trust, you payback might be worser than you imagined...
 
There is no excuse for being so utterly naive. That is a horrible, ignorant attitude to have on the Internet, and it's wildly reckless and to advise anybody else to behave in such a way.
 
11:16 PM
Master!!! What taught you?
You were born Wise and you came out of the Stomach Programming too....
Why run from experience... ???
 
Goodbye, Poiz.
 
Good Morning Mr. Caution....
People like you is the reason we have Robots than Humans.... IN YOUR HEART, THERE IS ALSO A BRAIN... MIGHTIER THAN THAT IN YOUR HEAD... USE IT AND SEE WHAT YOU BECOME IN ADDITION TO YOUR BRAIN-POWER
Protecting against Evil in the first Place is the very cause of it....
But hey... You are a Programmer... You know everything about security and protection.... the question is: After protecting the World outside you; how does the world inside you look like?
You can do as will my friend....
 
are you always fighting?
 
No!!! The guy just went too far...
It is not necessary but i just don't get it....
 
where are you from by the way?
 
11:27 PM
@aurora I will give you my email... We can conti
Continue from there some other time...
Sorry...
poiz777@yahoo.com
 
its ok, you dont have to be sorry for anything
and i would love to get to know you
I have saved it and i will send you an email tomorrow!
 
Beautiful... I will be glad
Despite what happened here; i want to tell you one thing: **YOUR INNOCENCE IS THE ONLY TRUE QUALITY YOU HAVE... let the world call it naive or ignorance... SO LONG AS YOU COME STRAIGHT FROM YOUR HEART... YOU ARE A GODDESS AMONG MORTALS... other things are only relative...
Good luck and bye for now... and I hope you find a solution...
 
Hey Rajdeep!
 
@Aurora Did you find the solution?
 
@Poiz Thank you for all your help and i would love to get to know you
@RajdeepPaul No not yet, i wanted to thank you too for everything you have done.
@RajdeepPaul your script gave the right warnings, but the only problem is that if there are no errors, it wont register
 
11:36 PM
@Aurora You're welcome. :-) Just for the debugging purpose add this line in your form <input type="hidden" name="register" value="Register" /> and test your application again. See if the registration thing happens or not.
 
@RajdeepPaul what will the line do? and do i have to delete the "normal" one?
@RajdeepPaul the button i mean..
 
Don't delete any line from your html form. Just add this line <input type="hidden" name="register" value="Register" /> before your submit button and run your application again.
 
and debugging on right? ill test it right away with your script
@RajdeepPaul IT WORKED!
 
11:51 PM
Let me tell you the reason behind it, and one workaround method.
 
@RajdeepPaul yesssss!
@RajdeepPaul i would love to learn :)
 
See this line in your AJAX request, f.submit();. When you submit the form in this way, $_POST['register'] is not set, and hence the control doesn't even enter the if block. That's why I told you to add that hidden input field.
So do you realise what's happening in your code?
 
so it litterly hides register, on top of the index.php, but doesnt that mean if i refresh the page, it registers a empty user? let me try...;)
i was wrong....let me think...
 

  last day (15 days later) »