开发者

$.ajax jquery to php script that stores in mysql

I have this code in jquery:

$.ajax({
  type: "POST",
  url:  "tosql.php",
  data: {textnode: textnode},
  success: function(){
    alert( "Data Saved: " );
  }
});

and this php script:

<?php
  $textnode = $_POST['textnode'];
  $con = mysql_connect("localhost","root开发者_开发知识库","");
  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("repository", $con);

  mysql_query("INSERT INTO paragraphs (paragraphs) VALUES ('$textnode')");

  mysql_close($con);
?>

When I go to mysql to view if the array was stored, I see "Array" as the value. What I'm trying to do is store each value in the array into its own row also. Serialize didn't work in this case.


Edited:

if(get_magic_quotes_gpc())
  $magic = 1;
else
  $magic = 0;


foreach($textnode as $key => $value) {

 if($magic == 0){
   $value = mysql_real_escape_string($value, $con);
 }
 else{
   $value = stripslashes($value);
   $value = mysql_real_escape_string($value, $con);
 }


 mysql_query("INSERT INTO paragraphs (paragraphs)
 VALUES ('$value')");


}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜