Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several problems with your code I have tried to explain via the corrected and commented code here:</p> <h2>HTML &amp; JavaScript</h2> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;pippo&lt;/title&gt; &lt;!-- added link to jQuery library --&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"&gt;&lt;/script&gt; &lt;!-- javascript can go here --&gt; &lt;script type="text/javascript"&gt; $.ajax({ type: "POST", url: "chgcontact.php", // use javascript object instead of `get` string to represent data data: {surname:user, name:'', tel:'', companymail:'', mail:'', fbid:''}, success: function(data){ // removed name,tel,companymail,mail,fbid alert(JSON.parse(data)); } }); return ""; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; Contact List: &lt;ul&gt; &lt;!-- removed `javascript` form onclick handler --&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img src="contacts/pippo.png" onclick="change('pippo')"/&gt;pippo&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img src="contacts/pluto.png" onclick="change('pluto')"/&gt;pluto&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;img src="contacts/topolino.png" onclick="change('topolino')"/&gt;topolino&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h2>PHP</h2> <pre><code>&lt;?php $surname = $_POST['surname']; $result = mysql_query("select * from profile Where surname='$surname'") or die(mysql_error()); while ($row = mysql_fetch_array( $result )){ // create data object $data = new stdClass(); // add values to data object $data-&gt;name = ucfirst($row['name']); $data-&gt;tel = $row['telephone']; $data-&gt;companymail = $row['companymail']; $data-&gt;mail = $row['email']; $data-&gt;fbid = $row['facebook']; // send header to ensure correct mime type header("content-type: text/json"); // echo the json encoded data echo json_encode($data); } ?&gt; </code></pre> <p>All code is untested, but you should be able to see what I have done at each step. Good luck.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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