Jump to content

PHP / MYSQL Help


Aureole

Recommended Posts

First post here so hey guys.  ;D

 

 

 

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.  ;)

Link to comment
https://forums.phpfreaks.com/topic/61105-php-mysql-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/61105-php-mysql-help/#findComment-304085
Share on other sites

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.  :P

 

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.  :)

Link to comment
https://forums.phpfreaks.com/topic/61105-php-mysql-help/#findComment-304087
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.