9three Posted September 19, 2009 Share Posted September 19, 2009 Hey, I have a simple form that inserts a name into a database. The functionality works fine. But the message that is suppose to show is wrong. $(document).ready(function () { $('#nameForm').submit(function () { $('.msgbox').hide(); $.post('ajax.Register.php', {name: $('#name').val()}, function (data) { if (data) { $('.msgbox').show('fast', function () { $(this).html('OK!'); }); } else { $('.msgbox').show('fast', function () { $(this).html('Failed!'); }); } }); return false; }); }); The form always shows "Failed!" even though the name went through in my database. try { $objUser = new PDO("mysql:dbname=ajax;host=localhost", "root", ""); } catch (PDOException $e) { echo 'Unable to connect'; } $strName = $_POST['name']; if (empty($strName)) return false; $strQuery = "INSERT INTO name (name) VALUES (:name)"; $objStatement = $objUser->prepare($strQuery); $objStatement->bindParam(':name', $strName, PDO::PARAM_STR); if ($objStatement->execute()) return true; return false; Anyone lend a hand? Quote Link to comment Share on other sites More sharing options...
corbin Posted September 19, 2009 Share Posted September 19, 2009 Returning true or false in the context of a webpage means nothing. You could echo 1 or 0 instead and then check the value of data. Quote Link to comment Share on other sites More sharing options...
9three Posted September 19, 2009 Author Share Posted September 19, 2009 thanks, that did it. Quote Link to comment Share on other sites More sharing options...
corbin Posted September 20, 2009 Share Posted September 20, 2009 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.