Re: [PHP] PHP want not write in Database
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 h1Artikel ist eingetragen!/h1; } catch (PDOException $ex) { echo $ex-getMessage(); } } ? /end The HTML Tags: start div class=entry form method=post action= / fieldset labelAutor/label input type=text class=text name=autor / labelTitle/label input type=text class=text name=title / labelTeaser/label textarea cols=80 rows=10 class=textarea name=teaser/textarea labelContent/label textarea cols=80 rows=10 class=textarea name=content/textarea labelKategorie/label input type=text class=text name=category / labelBild/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
Re: [PHP] PHP want not write in Database
Hello, On Mon, 16 May 2011 07:13:19 +0100 Ashley Sheridan wrote: 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. in the db.html is the follow code: start try { $db = new PDO(mysql:host={$host};dbname={$database}, $user, $pass); }catch(PDOException $pe) { die('Connection error, because: ' .$pe-getMessage()); } end Yes my Webserver parse html files as php. My formular work without problems, and the old Blog Script work too without problems. Regards Silvio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP want not write in Database
Hello, On Mon, 16 May 2011 09:57:23 +0800 xianhua zhou wrote: VALUES(:autor, :title, :teaser, :teaser, :content, :category, :bild) There are 2 :teaser, try remove one. Yes thats it. Now it work well done! Thank you, im sorry sure was to long at the pc yesterday. Silvio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP want not write in Database
On Mon, May 16, 2011 at 10:30 AM, Silvio Siefke li...@silvio-siefke.dewrote: Hello, On Mon, 16 May 2011 09:57:23 +0800 xianhua zhou wrote: VALUES(:autor, :title, :teaser, :teaser, :content, :category, :bild) There are 2 :teaser, try remove one. Yes thats it. Now it work well done! Thank you, im sorry sure was to long at the pc yesterday. In order to avoid this problem in future I encourage you to check the return value of every function call you make that might fail, i.e. every single one! Had you done that here, and then pulled out the last error message from PDO you would not have had this problem for longer than a minute. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] PHP want not write in Database
Hello, On Mon, 16 May 2011 11:06:17 +0100 Stuart Dallas wrote: In order to avoid this problem in future I encourage you to check the return value of every function call you make that might fail, i.e. every single one! Had you done that here, and then pulled out the last error message from PDO you would not have had this problem for longer than a minute. im sorry, but what u mean? Can u give example. I really starting with PHP and when have error messages in log there is no problem for me, i can fix the mistakes in script, but when php write no messages to log i not know where should search. I has try with xdebug, but this want not work or i understand it wrong. And which ways for debug give in PHP? Regards Silvio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP want not write in Database
On Mon, May 16, 2011 at 11:40 AM, Silvio Siefke li...@silvio-siefke.dewrote: Hello, On Mon, 16 May 2011 11:06:17 +0100 Stuart Dallas wrote: In order to avoid this problem in future I encourage you to check the return value of every function call you make that might fail, i.e. every single one! Had you done that here, and then pulled out the last error message from PDO you would not have had this problem for longer than a minute. im sorry, but what u mean? Can u give example. I really starting with PHP and when have error messages in log there is no problem for me, i can fix the mistakes in script, but when php write no messages to log i not know where should search. I has try with xdebug, but this want not work or i understand it wrong. And which ways for debug give in PHP? Not all functions raise PHP errors when they fail, in fact most don't. Most will return an error value, and a few throw exceptions. As the manual states, the execute method you're using will return true if it succeeded or false if it failed (http://php.net/pdostatement.execute). You can then use the errorInfo method to get details of the actual error ( http://php.net/pdostatement.errorinfo). The best piece of advice I can give you if you're just starting out is... only ever assume that all of the code you write will fail, and make sure it handles failures appropriately. Any other assumptions are likely to come back and bite you on the arse one way or another. Oh, and read the manual entry for every function, class and method you're using thoroughly! -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] PHP want not write in Database
Hello, On Mon, 16 May 2011 12:07:37 +0100 Stuart Dallas wrote: Not all functions raise PHP errors when they fail, in fact most don't. Most will return an error value, and a few throw exceptions. As the manual states, the execute method you're using will return true if it succeeded or false if it failed (http://php.net/pdostatement.execute). You can then use the errorInfo method to get details of the actual error ( http://php.net/pdostatement.errorinfo). The best piece of advice I can give you if you're just starting out is... only ever assume that all of the code you write will fail, and make sure it handles failures appropriately. Any other assumptions are likely to come back and bite you on the arse one way or another. Oh, and read the manual entry for every function, class and method you're using thoroughly! thanks i will do it but the most of the manual will not understand direct, that will come with time. I have read the manual for PDO, so that i can use it. Before i has my Script with mysqli, but i have read from Prepared Statemants and that they more comfortable and secure and so i has write. All was good, only that not want write in database. Okay thanks all, and im sorry that i disturb with the easy questions. All mistakes in the script i has found with google and the manual, but when not give message, there is problem. Often i not know the correct word which should use to search. For example i have a HTML Table, in this are much Code for calculate the Stock Portfolio. Value, Dividend, Win, Lose Thats okay, but i search a function with can tell php that should calculate all data in table. At moment i have write much Variables for every stock which is in Portfolio. Better were that i can copy the mathematical formula from one row/cell in next row/cell, like in excel. That i not found, because i not know what is the right words for searching. I dont know understand what i mean? My English not the best. Thanks for time and help. Silvio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php