Aureole Posted July 21, 2007 Share Posted July 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
pedrobcabral Posted July 21, 2007 Share Posted July 21, 2007 I am not directly anwsering your question because I don't know that library. Anyway a word about require, that will be trouble because as it is stated at php.net website "don't hesitate to use require() if you want a missing file to halt processing of the page". include is diferent from require. Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 21, 2007 Author Share Posted July 21, 2007 Yes I know this, but the download didn't include a DB.php... ??? Strange I know. Anyway I think with the code from the two files I provided it should be possible to get it working and also you don't really need to know the library you just need to know php and mysql. The javascript and html and everything is all done and working. I just need to be able to add to the database the divs id and the content of the div when the form is submitted. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.