ziedinjsh Posted May 23, 2011 Report Share Posted May 23, 2011 query: $(function() { $("#addtopic").click(function() { var name = $("#name").val(); var title = $("#title").val(); var description = $("#description").val(); var content = $("#content").val(); var dataString = 'name='+ name + '&title='+ title + '&description'+ description + '&content'+ content; if(name=='' || title=='' || description=='' || content=='') { $('.success').fadeOut(500).hide(); $('.error').fadeOut(500).show(); } else { $.ajax({ type: "POST", url: "misc/addtopic.php", data: dataString, success: function(){ $('.success').fadeIn(500).show(); $('.error').fadeOut(500).hide(); $('#name').fadeOut(600).val(''); $('#title').fadeOut(600).val(''); $('#description').fadeOut(600).val(''); $('#content').fadeOut(600).val(''); $('.titles').fadeOut(600).val(''); $('.button').fadeOut(600).val(''); } }); } return false; }); }); formas:" <form method='post' name='form'> <p class='titles'>Tavs segvārds</p><p style='margin:0px;padding:0px;'><input type='text' name='name' id='name' class='inputs'></p> <p class='titles'>Tēmas nosukums</p><p style='margin:0px;padding:0px;'><input type='text' name='title' id='title' class='inputs'></p> <p class='titles'>Tēmas apraksts</p><p style='margin:0px;padding:0px;'><input type='text' name='description' id='description' class='inputs'></p> <p class='titles'>Tēmas saturs</p><p style='margin:0px;padding:0px;'><textarea name='content' id='content' class='inputs2'></textarea></p> <span class='error' style='display:none;color:red;text-align:center;'><h3>Kāds no lauciņiem ir palicis tukš.</h3></span> <span class='success' style='display:none;color:green;text-align:center;'><h3>Paldies, tēma ir pievienota!</h3></span> <p style='margin:0px;padding:0px;text-align:center;margin-bottom:10px;'><input type='submit' value='Pievienot' id='addtopic' class='button'></p> </form> addtopic.php: $name = mysql_real_escape_string($_POST['name']); $title = mysql_real_escape_string($_POST['title']); $description = mysql_real_escape_string($_POST['description']); $content = mysql_real_escape_string($_POST['content']); $date = date("Y-m-d H:i:s"); $add = mysql_query("INSERT INTO topics (name, title, description, content, date) VALUES ('$name', '$title', '$description', '$content', '$date')") or die(mysql_error()); iekš datubāzēs pievienot tikai name, title un date, bet description un content netiek pievienosts! kapēc tā!? Quote Link to comment Share on other sites More sharing options...
Rincewind Posted May 23, 2011 Report Share Posted May 23, 2011 var dataString = 'name='+ name + '&title='+ title + '&description'+ description + '&content'+ content; '&description' un '&content' vietā vajag '&description=' un '&content=' Vispār pirmo reizi redzu ka post datus šitā sagatavo, parasti tak bliež kā masīvu vai kā objektu. Quote Link to comment Share on other sites More sharing options...
briedis Posted May 23, 2011 Report Share Posted May 23, 2011 ir arī tāda lieta kā $("form").serialize 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.