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
kiko
Forum Newbie
Posts: 23 Joined: Fri Sep 07, 2007 6:42 am
Post
by kiko » Wed Feb 20, 2008 3:39 pm
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());
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Feb 20, 2008 6:28 pm
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
Post
by kiko » Wed Feb 20, 2008 10:05 pm
Hi arborint,
Thanks for help. Thanks for reminding me that still need the edit.php page..now it can work already. Thanks..cheers..
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Feb 20, 2008 10:27 pm
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
Post
by kiko » Fri Feb 22, 2008 3:13 am
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());
?>
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Fri Feb 22, 2008 3:57 am
You should check that id and content have valid values first, before you connect. And also sanitize he data a little more.
(#10850)