First post here so hey guys.
I'm using jEditable and the jQuery library on my Website.
If you don't know what it is then I'll try explain. It allows you to edit content inline, for example:
<div class="edit" id="one">Content</div>
If I used that code then I could click on "Content" and then it would change to a text input field then I could change it and hit Enter and it would change.
When you hit enter the id of the div and the content of the div is sent to a file called save.php. The documentation/example for jEditable uses SQL Lite / Pear DB or something, but I want to use MYSQL.
I'd like it so for every unique id I have there is a new row in a table in the database. Say if I have one with the id of "blah" and the content is "wee" then I change the content to "woo" would it update the row instead of adding a new one? Any and all help is appreciated.
Here is the code for save.php and dbInformation.php in case anyone needs it.
<?php
require_once 'dbConnection.php';
mysql_query("CREATE TABLE config(
id INT PRIMARY KEY,
token VARCHAR(64),
value TEXT
)")
$status = $dbh->query('
CREATE TABLE config (id INTEGER PRIMARY KEY,
token VARCHAR(64),
value TEXT)
');
$id = $dbh->nextId('config');
$query = sprintf("INSERT INTO config (id, token, value)
VALUES (%d, '%s', '%s')",
$id, $_POST['id'], stripslashes($_POST['value']));
$status = $dbh->query($query);
/* sleep for a while so we can see the indicator in demo */
usleep(2000);
$renderer = $_GET['renderer'] ? $_GET['renderer'] : $_POST['renderer'];
if ('textile' == $renderer) {
require_once './lib/Textile.php';
$t = new Textile();
print $t->TextileThis(stripslashes($_POST['value']));
} else {
print $_POST['value'];
}
?>
And dbConnection.php
<?php
require_once 'DB.php';
$dsn = array(
'phptype' => 'sqlite',
'database' => '/tmp/editable.db',
'mode' => '0666'
);
$dbh =& DB::connect($dsn);
$dbh->query("
CREATE TABLE config (id INTEGER primary key,
token VARCHAR(255),
value TEXT,
date DATETIME)
");
mysql_query("CREATE TABLE config(
id INT PRIMARY KEY,
token VARCHAR(255),
value TEXT
date DATETIME)")
?>
I know dbInformation requires a file called DB.php but that wasn't included with the download, hope it isn't a problem. Thanks a LOT.