edit-in-place problem in AJAX and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

edit-in-place problem in AJAX and PHP

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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>';
(#10850)
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

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

Post 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:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post by Christopher »

If you get a working example, please post the code. I think people would be interested in that example.
(#10850)
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

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

Post 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());
        
  ?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post by Christopher »

You should check that id and content have valid values first, before you connect. And also sanitize he data a little more.
(#10850)
Post Reply