php - Onclick save textarea content into database and display the content in another page -
i using ajax save textarea conent in database:
$("#update").click(function(e) { e.preventdefault(); var ttle = $("#title").val(); var text = $("#prjdesc").val(); var datastring = 'param='+text+'¶m1='+ttle; $.ajax({ type:'post', data:datastring, url:'insert.php', success:function(data) { alert(data); } }); });
insert.php:
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $name = $_post['param']; $title = $_post['param1']; $sql="insert $tbl_name (title, content) values ('$name','$title')"; if(mysql_query($sql)) { echo "success"; } else { echo "cannot insert"; }
i alerting success message when data saved. need know how displayed on page when data saved.
how done?
check out,
$("#update").click(function(e) { e.preventdefault(); var ttle = $("#title").val(); var text = $("#prjdesc").val(); var datastring = 'param='+text+'¶m1='+ttle; $.ajax({ type:'post', data:datastring, url:'insert.php', success:function(id) { window.location ="path.php?id="+id; // redirects } }); });
insert.php
mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $name = $_post['param']; $title = $_post['param1']; $sql="insert $tbl_name (title, content) values ('$name','$title')"; if(mysql_query($sql)) { echo mysql_insert_id(); // last inserted id } else { echo "cannot insert"; }
Comments
Post a Comment