Najt Posted November 29, 2010 Share Posted November 29, 2010 hello, please where is the problem... this is my php code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Výsledky</title> </head> <body> <h2>Výsledky </h2> <?php $mysqlhostitel="localhost"; $mysqluzivatel="ODBC"; $mysqlheslo=""; $mysqldb="test_hlasovani"; //pripojime se k db $link = mysql_connect($mysqlhostitel, $mysqluzivatel, $mysqlheslo) or die ("Error: ".mysql_error()); mysql_select_db($mysqldb) or die("Could not select database: ".mysql_error()); //pokud jsou k dispozici data formulare, zpracujeme je a ulozime function array_item($ar, $key){ if (array_key_exists($key,$ar))return($ar[$key]); return('');} $potvrzeni = array_item($_POST, 'potvrzeni'); $hlasovani = intval(array_item($_POST, 'hlasovani')); if($potvrzeni=="Odeslat"){ if($hlasovani >=1 && $hlasovani <=6){ mysql_querry("INSERT INTO volenyjazyk (volba) VALUES($hlasovani)"); } else{ echo"<p>Tento jazyk neni správny.Prosím volte znovu. Zpět na <a href=\"01hlasovani.html\">dotazník</a>.</p></body></html>\n"; exit(); } } //zobrazíme vysledky echo "<p><b>Jaký programovací jazyk nejraději používáte pro tvorbu MySQL aplikací?</b></p>\n"; //celkový počet hlasů $vysledek = mysql_querry("SELECT COUNT(volba) FROM volenyjazyk"); $pocethlasu = mysql_result($vysledek, 0,0); //procenta if($pocethlasu == 0){ echo "<p>Nikdo zatim nehlasoval</p>\n"; } else{ echo"<p>$pocethlasu lidí hlasovalo:</p>\n"; $textvolby = array (1 => "C/C++", "Java", "Perl", "PHP", "ASP", "Jinej"); print ("<p><table>\n"); for($i=1; $i<=6; $i++){ $vysledek = mysql_query("SELECT COUNT(volba) FROM volenyjazyk " . "WHERE volba = $i"); $volba = mysql_result($vysledek, 0,0); $procent = round($volba/$pocethlasu*10000)/100; print("<tr><td>$textvolby[$i]:</td>"); print("<td>$procent %</td></tr>\n"); } print("</table></p>\n"); } ?> </body> </html> but the result is: Výsledky =1 && $hlasovani <=6){ mysql_querry("INSERT INTO volenyjazyk (volba) VALUES($hlasovani)"); } else{ echo" Tento jazyk neni správny.Prosím volte znovu. Zpět na dotazník. \n"; exit(); } } //zobrazíme vysledky echo " Jaký programovací jazyk nejraději používáte pro tvorbu MySQL aplikací? \n"; //celkový počet hlasů $vysledek = mysql_querry("SELECT COUNT(volba) FROM volenyjazyk"); $pocethlasu = mysql_result($vysledek, 0,0); //procenta if($pocethlasu == 0){ echo " Nikdo zatim nehlasoval \n"; } else{ echo" $pocethlasu lidí hlasovalo: \n"; $textvolby = array (1 => "C/C++", "Java", "Perl", "PHP", "ASP", "Jinej"); print (" \n"); for($i=1; $i<=6; $i++){ $vysledek = mysql_query("SELECT COUNT(volba) FROM volenyjazyk " . "WHERE volba = $i"); $volba = mysql_result($vysledek, 0,0); $procent = round($volba/$pocethlasu*10000)/100; print(""); print("\n"); } print(" $textvolby[$i]: $procent % \n"); } ?> why? if i tryied connect like this: $connection =@mysql(....); if ($connection == FALSE){ echo .... Not possible ... exit(); } but it PHP could connect to DB so it was detected like FALSE, and even if there was exit(); on the site continous the php code .. :-( what is wrong? thanks Quote Link to comment https://forums.phpfreaks.com/topic/220098-database-connection-problem/ Share on other sites More sharing options...
BlueSkyIS Posted November 29, 2010 Share Posted November 29, 2010 try $sql = "INSERT INTO volenyjazyk (volba) VALUES('$hlasovani')" mysql_query($sql) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/220098-database-connection-problem/#findComment-1140760 Share on other sites More sharing options...
Najt Posted November 29, 2010 Author Share Posted November 29, 2010 Hi, I have tried it. But the result is still the same . even no error report. I guess that the php wont work properly. Coz it cant connect to DB via: $mysqlhostitel="localhost"; $mysqluzivatel="root"; $mysqlheslo="pass"; $connection =@mysql_connect($mysqlhostitel, $mysqluzivatel, $mysqlheslo); if($connection == FALSE){ .... - it is always false. but how i have install php properly with all extensions. and the phpMyadmin works fine with DB. I have W7 and the ipV6 disabled. Quote Link to comment https://forums.phpfreaks.com/topic/220098-database-connection-problem/#findComment-1140858 Share on other sites More sharing options...
trq Posted November 29, 2010 Share Posted November 29, 2010 Remove the error suppressor so you can at least see what error your getting. Quote Link to comment https://forums.phpfreaks.com/topic/220098-database-connection-problem/#findComment-1140861 Share on other sites More sharing options...
Najt Posted November 29, 2010 Author Share Posted November 29, 2010 dont understand what should I remove...but now I have this code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Výsledky</title> </head> <body> <h2>Výsledky </h2> <?php $mysqlhostitel="localhost"; $mysqluzivatel="ODBC"; $mysqlheslo=""; $mysqldb="test_hlasovani"; //pripojime se k db $link = mysql_connect($mysqlhostitel, $mysqluzivatel, $mysqlheslo) or die ("Error: ".mysql_error()); mysql_select_db($mysqldb) or die("Could not select database: ".mysql_error()); //pokud jsou k dispozici data formulare, zpracujeme je a ulozime function array_item($ar, $key){ if (array_key_exists($key,$ar))return($ar[$key]); return('');} $potvrzeni = array_item($_POST, 'potvrzeni'); $hlasovani = intval(array_item($_POST, 'hlasovani')); if($potvrzeni=="Odeslat"){ if($hlasovani >=1 && $hlasovani <=6){ mysql_querry("INSERT INTO volenyjazyk (volba) VALUES($hlasovani)"); } else{ echo"<p>Tento jazyk neni správny.Prosím volte znovu. Zpět na <a href=\"01hlasovani.html\">dotazník</a>.</p></body></html>\n"; exit(); } } //zobrazíme vysledky echo "<p><b>Jaký programovací jazyk nejraději používáte pro tvorbu MySQL aplikací?</b></p>\n"; //celkový počet hlasů $vysledek = mysql_querry("SELECT COUNT(volba) FROM volenyjazyk"); $pocethlasu = mysql_result($vysledek, 0,0); //procenta if($pocethlasu == 0){ echo "<p>Nikdo zatim nehlasoval</p>\n"; } else{ echo"<p>$pocethlasu lidí hlasovalo:</p>\n"; $textvolby = array (1 => "C/C++", "Java", "Perl", "PHP", "ASP", "Jinej"); print ("<p><table>\n"); for($i=1; $i<=6; $i++){ $vysledek = mysql_query("SELECT COUNT(volba) FROM volenyjazyk " . "WHERE volba = $i"); $volba = mysql_result($vysledek, 0,0); $procent = round($volba/$pocethlasu*10000)/100; print("<tr><td>$textvolby[$i]:</td>"); print("<td>$procent %</td></tr>\n"); } print("</table></p>\n"); } ?> </body> </html> and no errors displayed and it writes only : Výsledky that is the H2 topic. I have the html and this php file in htdocs in apache dir but still no error appears ...to show me where is the problem :_( Quote Link to comment https://forums.phpfreaks.com/topic/220098-database-connection-problem/#findComment-1140868 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.