Re: PHP want not write in Database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2011-05-16 at 02:55 +0200, Silvio Siefke wrote:

> Hello,
> 
> i have a Blog Script for my private Website. Normal i write new Articles
> direct with phpmyadmin, but this is not comfortable. I has no errors in Log
> for the script and the mysql query log write the correct insert SQL code, but
> nothing would be write in the database. I really understand not where is the
> mistake. Can someone help me?
> 
> Thank You! Wish nice day at all!
> 
> Regards
> Silvio
> 
> 
> My PHP Code:
> <start>
> <?php
> error_reporting(E_ALL);
> ini_set('display_errors', 1);
> require ("inc/db.html");
> var_dump($_POST);
> 
> // Check the Fields
> if (isset ($_POST['submit']) &&
> isset ($_POST['autor']) &&
> isset ($_POST['title']) &&
> isset ($_POST['teaser']) &&
> isset ($_POST['content']) &&
> isset ($_POST['category']) &&
> isset ($_POST['bild']) &&
> $_POST['autor'] != '' &&
> $_POST['title'] != '' &&
> $_POST['teaser'] != '' &&
> $_POST['content'] != '' &&
> $_POST['category'] != '' &&
> $_POST['bild'] != '') {
> 
> 
> try {
> 
>     $sql = "INSERT INTO `test` (autor, title, teaser, content, category, bild)
>         VALUES
> (:autor, :title, :teaser, :teaser, :content, :category, :bild)";
> 
>     $write = $db->prepare($sql);
>     $write->bindValue(':autor', $_POST['autor']);
>     $write->bindValue(':title', $_POST['title']);
>     $write->bindValue(':teaser', $_POST['teaser']);
>     $write->bindValue(':content', $_POST['content']);
>     $write->bindValue(':category', $_POST['category']);
>     $write->bindValue(':bild', $_POST['bild']);
>     $write->execute();
>     echo "<h1>Artikel ist eingetragen!</h1>";
> 
> 
> } catch (PDOException $ex) {
>     echo $ex->getMessage();
> }
> }
> ?>
> </end>
> 
> The HTML Tags:
> <start>
> <div class="entry">
> <form method="post" action="" />
> <fieldset>
>     <label>Autor</label>
>     <input type="text" class="text" name="autor" />
> 
>     <label>Title</label>
>     <input type="text" class="text"	name="title" />
> 
>     <label>Teaser</label>
>     <textarea cols="80" rows="10" class="textarea" name="teaser"></textarea>
> 
>     <label>Content</label>
>     <textarea cols="80" rows="10" class="textarea" name="content"></textarea>
> 
>     <label>Kategorie</label>
>     <input type="text" class="text" name="category" />
> 
>     <label>Bild</label>
>     <input type="text" class="text" name="bild" />
>     <input type="submit" class="submit" name="submit" value="Posten" />
> </fieldset>
> </form>
> </div>
> </end>
> 
> The Mysql Query Log:
> <start>
> 110516  2:44:29	  187 Connect	root@localhost on bloggen
> 		  187 Query	INSERT INTO `test` (autor, title, teaser,
> content, category, bild) VALUES ('Silvio Siefke', 'Test', 'We try we can
> write in database with the script.', 'We try we can write in database with
> the script.', 'When not then i not know what is the problem with the
> script.', 'Freizeit', 'content.png') 187 Quit
> <end>
> 
> The var_dump give me:
> <start>
> array(7) { ["autor"]=> string(13) "Silvio Siefke" ["title"]=> string(4)
> "Test" ["teaser"]=> string(48) "We try we can write in database with the
> script." ["content"]=> string(61) "When not then i not know what is the
> problem with the script." ["category"]=> string(8) "Freizeit" ["bild"]=>
> string(11) "content.png" ["submit"]=> string(6) "Posten" }
> <end>
> 


What is your code in the included db.html? You do realise that unless
you've told the server especially that it won't know to parse your HTML
files for PHP code as well. HTML is embedded in PHP, not the other way
around. If you think more like that, you'll realise why it's not
working.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux