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? Link to comment https://forums.phpfreaks.com/topic/174830-solved-jquery-ajax-wrong-message/ 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. Link to comment https://forums.phpfreaks.com/topic/174830-solved-jquery-ajax-wrong-message/#findComment-921369 Share on other sites More sharing options...
9three Posted September 19, 2009 Author Share Posted September 19, 2009 thanks, that did it. Link to comment https://forums.phpfreaks.com/topic/174830-solved-jquery-ajax-wrong-message/#findComment-921373 Share on other sites More sharing options...
corbin Posted September 20, 2009 Share Posted September 20, 2009 Link to comment https://forums.phpfreaks.com/topic/174830-solved-jquery-ajax-wrong-message/#findComment-921513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.