Jump to content


  • Posts

  • Joined

  • Last visited

thurft's Achievements


Newbie (1/7)



  1. hey guys 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... Can anyone tell me why? <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <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></head> <body> <form class="iValForm" id="iValForm" method="post" action=""><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" id ='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;}?>
  2. thanks! :)didnt understand the cURL thing v much, but that somehow clarified why it didnt work
  3. Hello guys, I am trying to make a validation for a form and if everything goes right it should go to the 2nd page where I should pass the login details. I was told that given the way I am doing it , I should use cURL, but i have no idea what i am doing it and why is not working.... Everything works fine in terms of the validation but somehow the 2nd page is not catching the variables passed by the cURL. It redirects correctly to the install2.php but its not passing any variables to it. What i am doing wrong? I dont know if my problem is in the page 1 in the cURL or in the page 2 in the way im trying to catch the curl My code in the first page is as follows <?php //If the person pressed summit check for the information submited. If everything is correct move to the next page if (isset($_POST['submit'])) { // declare Variables $username = $_POST['username']; $password = $_POST['password']; $server = $_POST['server']; $message = "The following fields are empty: "; //Step 1 : Check if username & server are empty and if they are return the correct error if (empty($username) || empty($server) ) { if (empty($username)) { $message .= "Username"; } if (empty($password)) { $message .= " Password"; } if (empty($server)) { $message .= " Server"; } } else { //Step 2: Attempt to connect to the DB with the information provided. if not sucessful return to correct error to the user. @$connection = mysql_connect($server,$username,$password);if (!$connection) { $message = "Please check your details. the script was unable to connect to the db."; } else { //Step 3: Since the connection was stablished successfuly with the information provided then send the login details tot he next page// NOTE: For porpuses of this script I am only passing 1 variable... to make my life easier $data = "username=".$username;$data2 = urlencode ($data); $ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, 'http://localhost/install2.php'); curl_setopt ($ch, CURLOPT_POST, TRUE); curl_setopt ($ch, CURLOPT_POSTFIELDS, $data2); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec ($ch); echo $response; header ('location: install2.php'); curl_close ($response); } } }?> and the code in the 2nd page (the one that should catch the code is as follows) <?php $username = $_POST['username'];$password = $_POST['password'];$server = $_POST['server']; echo "Welcome to install 2" . '</br>'; if (!empty($username)){ echo "the user name is {$username} and the password is {$password} and the server is" . '</br>';} ?>
  • Create New...