Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert multiple values sent from AJAX into sql database
    primarykey
    data
    text
    <p>hi have this code which works perfectly with just value:</p> <pre><code> &lt;script type="text/javascript"&gt; $(document).ready(function() { $("input[type=button]").click(function () { var textarea_content = $('textarea#wall').val(); // get the content of what user typed (in textarea) if (textarea_content != '') { // if textarea is not empty var sender = "&lt;?php echo $_SESSION['user_id'];?&gt;"; $.ajax({ type: "POST", url: "send_message_function.php", data : "action=send&amp;from_id="+sender+"&amp;to_user="+$(this).siblings("input[type=text]").val()+"&amp;message="+textarea_content, dataType: "json", success: function (data) { var LastID = data["cid"]; alert("toUser: " + $(this).siblings("input[type=text]").val()+"and text area " + textarea_content + " message id: " + LastID); } });//end success function //do something else } else { alert('Enter some text ! '); // just in case somebody click on share witout writing anything :) } });//end click function });//end ready function &lt;/script&gt; </code></pre> <p>and send_message_function.php :</p> <pre><code>&lt;?php require 'core/functions/init.php'; $action = $_POST['action']; if($action=="send"){ $from_id = mysql_real_escape_string($_POST['from_id']); $to_id = mysql_real_escape_string($_POST['to_user']); $message = strip_tags($_POST['message']); $sql = mysql_query("INSERT INTO chat (from_id, to_id, message, dt)VALUES('$from_id','$to_id','$message',NOW())") or die("0"); echo json_encode(array("cid"=&gt;(mysql_insert_id()), "from_id"=&gt;''.$message_id.'')); } ?&gt; </code></pre> <p>the problem is when I try to send the message to multiple users. The sql query try to insert all the users IDs in the same row. I know I should do some loop but I can't think how run the query for every users I want to send the message to.</p> <pre><code>$(this).siblings("input[type=text]").val() </code></pre> <p>returns multiple users id like this: 113,143,234</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload