-1

I have this error in my html:

Notice: Undefined index: send in C:\xampp\htdocs\liciteiro\search_clientes.php on line 3 false

i need to request data with mysql+ php to my html. i use method post;

i'm use this codes:

Jquery Post Code:

$(function(){
  $("#send").click(function() {
  var json  = $.parseJSON($("#json").val());
        var url2 = $("#url2") .val();
         $.post(url2,json,function(data){
  $('div#status').html(data);
     });
});

HTML CODE:

<div id="form1" class="send"> 
<p>URL:<input type="text" name="url2" id="url2" /></p>
<p> JSON:<textarea name="json" id="json" cols="45" rows="5"></textarea></p>
<p><input type="submit" class="button" name="send" value="send" id="send" /></p>
</div>
<div id="status">
  RETORNO:
<!--  <textarea name="comment" id="comment" cols="45" rows="5"></textarea> -->
</p>
</div>

PHP CODE:

include ('conection.php');
$data = $_POST['send'];
$arr = json_decode($data);
//$arr = json_decode($_POST['json']);
$result = mysql_query("SELECT * FROM clientes WHERE client_descricao='".$arr[0]['client_descricao']."' OR client_razaosocial ='".$arr[0]['client_razaosocial']."' OR client_endereco ='".$arr[0]['client_endereco']."' OR client_cidade ='".$arr[0]['client_cidade']."' OR client_estado ='".$arr[0]['client_estado']."' OR client_telefone ='".$arr[0]['client_telefone']."'")or die(mysql_error());
$json = mysql_fetch_array($result, MYSQL_ASSOC);
echo json_encode($json);

i need put data requested in div status, please help me.

user3033027
  • 13
  • 2
  • 6
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Dec 01 '13 at 17:35
  • but this API is my local test, in the server i use modern replacement :). but thanks for this – user3033027 Dec 01 '13 at 21:55

1 Answers1

0

Your POST variable names are wrong, try this:

jQuery post call

$.post(url2,{data: json},function(data){...

PHP var

$data = $_POST['data'];

Or, if you still use the submit button and not AJAX, do this:

$data = $_POST['json'];

UPDATE

Ok, here's the fixed jQuery code to make an AJAX call and prevent refresh:

function send(){
    var json = $.parseJSON($("#json").val());
    var url2 = $("#url2").val();
    $.post( url2, {data: json}, function( data ){
        $('div#status').html( data );
    });
    return false;
}

HTML form element:

<div id="form1" class="send" onsubmit="return send();">

PHP data:

$data = json_decode($_POST['data']);
Shomz
  • 37,421
  • 4
  • 57
  • 85