Page 1 of 1

edit-in-place problem in AJAX and PHP

Posted: Wed Feb 20, 2008 3:39 pm
by kiko
Hi all,
I'm probably doing something stupid, but I need your help. I'm try to modify the edit-in-place form that searched from internet but I failed to do so because of unfamiliar with the AJAX stuff. Once I click the save button after I edit the field, and it will end up with update failed. I don't know how should I put the php code so that I can get the value. Attached is the js and css files. Thanks in advance.

Code: Select all

<p id="desc">Learning edit-in-place....</p> 
 
$conn = @mysql_connect('localhost','root','edit')or die("Unable to connect to database ".mysql_error());
mysql_select_db('try') or die("Unable to select database try ".mysql_error()); 
     
     $id = $_POST['id'];
     $content = $_POST['content'];
     $q= htmlspecialchars($_POST['content']);
     echo $q;
     
     $query_1= mysql_query("insert into haha(e_id, e_con)values ('$id', '$content')")or die (mysql_error());
edit-in-place.zip
(29.52 KiB) Downloaded 47 times

Re: edit-in-place problem in AJAX and PHP

Posted: Wed Feb 20, 2008 6:28 pm
by Christopher
The editinplace.js script says you need an edit.php file somewhere. Try this one to see what is going on:

Code: Select all

<?php
echo '<pre>' . print_r($_POST, 1) . '</pre>';

Re: edit-in-place problem in AJAX and PHP

Posted: Wed Feb 20, 2008 10:05 pm
by kiko
Hi arborint,
:wink: Thanks for help. Thanks for reminding me that still need the edit.php page..now it can work already. Thanks..cheers.. :drunk:

Re: edit-in-place problem in AJAX and PHP

Posted: Wed Feb 20, 2008 10:27 pm
by Christopher
If you get a working example, please post the code. I think people would be interested in that example.

Re: edit-in-place problem in AJAX and PHP

Posted: Fri Feb 22, 2008 3:13 am
by kiko
here we go....
a.html

Code: Select all

<html>
<head>
     <link href="editinplace.css" rel="Stylesheet" type="text/css" />
     <script src="prototype.js" type="text/javascript"></script>
     <script src="editinplace.js" type="text/javascript"></script>    
</head> 
<body>
     <h1>Edit-in-place</h1>
     <p id="desc">Learning edit-in-place....</p>
 </body>
 </html>
edit.php

Code: Select all

<?php
 
$conn = @mysql_connect('localhost','root','edit')or die("Unable to connect to database ".mysql_error());
mysql_select_db('try') or die("Unable to select database try ".mysql_error()); 
     
     $id = $_POST['id'];
     $content = $_POST['content'];
     $q= htmlspecialchars($_POST['content']);
     echo $q;
     
     $query_1= mysql_query("insert into haha(e_id, e_con)values ('$id', '$content')")or die (mysql_error());
        
  ?>

Re: edit-in-place problem in AJAX and PHP

Posted: Fri Feb 22, 2008 3:57 am
by Christopher
You should check that id and content have valid values first, before you connect. And also sanitize he data a little more.