0

Basically i am trying to create a validation for the form. I want it to check if it can connect to the DB and if true to proceed to another page and if false to return an error.

I am inputting the wrong details to make it just display the error but somehow it always returns "TRUE" on page load... and everytime i click the submit it doesnt do anything regardless of my entry...

thx

       <script>
      $(document).ready(function(){
    var u = $('#username');
    var s = $('#server');
    var p = $('#password');

    $('#iValForm').submit(
    $.post("connect.php", {u: u.val(),p: p.val(),s: s.val()}, function(fd){
        if (fd == "true"){
        alert("Is: " + fd);
        return false;
                        } // if1
        if (fd == "false"){
        alert("Is2: " + fd);
        return false;
                        } // if2
    } //post function

    ) //Post    
    ) //submit
  }) //document

      </script>

    <form class="iValForm" id="iValForm" method="post">
    <fieldset>
    <legend id="error"> </legend>
    <p>
        <label for="username">Username </label>
        <input id="username" name="username" class="required" /> </input>
    </p>
    <p> 
        <label for="password">Password</label>
        <input id="password" name="password" class="required"/> </input>
    </p>

    <p> 
        <label for="server">Server</label>
        <input id="server" name="server" class="required"/> </input>

    </p>
    <p>
         <input class="submit" type="submit" value="Submit"/>
    </p>
    </fieldset>
    </form>

Connect.php

<?php
$user = $_POST['u'];
$password = $_POST['p'];
$server = $_POST['s'];

@$con = mysql_connect ($server, $user, $password);


if (!$con) { 
    $response = "false";
    echo $response;


    } else { 
        $response = "true";
        echo $response;
    }

?>
1
  • I know it's a "bit" late but are you still having this problem? You might try outputting the variable $con through print_r() so you can see what it's actually outputting... Commented Jan 19, 2013 at 8:40

1 Answer 1

1

change your php script

if (!$con) { 
    $response = 'false';
    echo $response;


    } else { 
        $response = 'true';
        echo $response;
    }

and in javascript

if (data == 'false')
Sign up to request clarification or add additional context in comments.

8 Comments

Just did, still not showing the alert or the error in the page
Can you check with your firebug what response you are getting from the server?
I just put firebug and didnt get anything :S
Did you see the request being made properly in firebug? Can you confirm you are correctly passing the parameters to php script via ajax call?
The weird thing is that if i change to .keyup the php works and returns what it should, so then the problem is on my jQuery. but somehow it does not even show in firebug an error as it is right now
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.