Pokebert Posted December 17, 2012 Share Posted December 17, 2012 (edited) I keep getting error: PHP Error Message Warning: mysql_query() [function.mysql-query]: Access denied for user 'a6743732'@'localhost' (using password: NO) in /home/a6743732/public_html/chat.php on line 25 PHP Error Message Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a6743732/public_html/chat.php on line 25 Access denied for user 'a6743732'@'localhost' (using password: NO) <?php session_start(); //CREDITS TO MODERNSONIC FROM 3DSPLAZA-3DSPAINT-SOMELUIGI.COM-3DSMEGUSTA-DSISTARZ for this chat script! //CREDITS TO MARIOERMANDO FOR THE TABLE CREATOR //CREDITS TO JUNAID FOR THE AUTO REFRESH...THAT WILL ONLY WORKS IF YOU SEPARATE THE MESSAGE FILE. ?> <? //AUTO TABLE CREATOR BY MARIOERMANDO //http://3DSFun.heliohost.org/ //http://marioermando.tumblr.com $sql = "CREATE TABLE chat( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), user TEXT(30), message TEXT(40))"; $result = mysql_query($sql) or die(mysql_error()); ?> <script type='text/javascript'> function updateChat() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET",".php?error=",true); xmlhttp.send(); } </script> <body onload="setInterval('updateChat()',2000);"> <div id="chat" style="witdth:320px height:200px; overflow:auto;"> <?php $user = $_SESSION['username']; //database infos $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a6743732_pokeb", $con); if ($_POST['submit']) { $_POST['message'] = mysql_real_escape_string(htmlentities($_POST['message'])); $sql = "INSERT INTO chat (user, message) VALUES ('$user', '$_POST[message]')"; $result = mysql_query($sql) or die(); } session_start(); if (!empty($_SESSION['username'])) // he got it. { echo ""; } else // bad info. { header('Location: connexion.php'); } //db connect $user = $_SESSION['username']; $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a6743732_pokeb", $con); //max messages $result = mysql_query("SELECT * FROM chat ORDER BY id DESC LIMIT 0, 15"); while($row = mysql_fetch_array($result)) { //smilies $smIn=array("R:"); $smOut=array("EPIC FACE URL"); $o_user = $row['user']; $message = $row['message']; $message = str_replace($smIn, $smOut, $message); echo '<u>'. $o_user . '</u>: '. $message . '</font>'. '</font>'. '</b>' ; echo "<br>"; } ?> </div> <style> #chat { background-color:green; width:320px; height:200px; overflow:auto; } </style> <form action="chat.php" method="POST"> <input type="text" name="message"><input type="submit" value="Chat" name="submit"> </form> <meta name="viewport" content="width=320"> <br> <a href="index.php"><img src="[url="http://png-2.findicons.com/files/icons/1572/minicons/48/refresh.png%22></a>refresh"]http://png-2.findico...ng"></a>refresh[/url] <br> Chat! </body> Edited December 17, 2012 by Pikachu2000 Removed advert links. Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/ Share on other sites More sharing options...
Pokebert Posted December 17, 2012 Author Share Posted December 17, 2012 (edited) Password hidden for obvious reasons Edited December 17, 2012 by Pokebert Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399744 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2012 Share Posted December 17, 2012 Notice which line the error is on, then look at which line your connection to the database is on. Something seem backwards? Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399746 Share on other sites More sharing options...
Muddy_Funster Posted December 17, 2012 Share Posted December 17, 2012 right at the very top, after all your credits, you query the database without establishing a connection, however the error shows that you have attempted connection with the urser name but no password. That just doesn't add up. Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399747 Share on other sites More sharing options...
Pokebert Posted December 17, 2012 Author Share Posted December 17, 2012 (edited) Edited the code: <?php session_start(); //CREDITS TO MODERNSONIC FROM 3DSPLAZA-3DSPAINT-SOMELUIGI.COM-3DSMEGUSTA-DSISTARZ for this chat script! //CREDITS TO MARIOERMANDO FOR THE TABLE CREATOR //CREDITS TO JUNAID FOR THE AUTO REFRESH...THAT WILL ONLY WORKS IF YOU SEPARATE THE MESSAGE FILE. ?> <? //AUTO TABLE CREATOR BY MARIOERMANDO //http://3DSFun.heliohost.org/ //http://marioermando.tumblr.com //database infos $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb",**********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a6743732_pokeb", $con); ?> <script type='text/javascript'> function updateChat() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET",".php?error=",true); xmlhttp.send(); } </script> <body onload="setInterval('updateChat()',2000);"> <div id="chat" style="witdth:320px height:200px; overflow:auto;"> <?php $user = $_SESSION['username']; $result = mysql_query($sql) or die(mysql_error()); if ($_POST['submit']) { $_POST['message'] = mysql_real_escape_string(htmlentities($_POST['message'])); $sql = "INSERT INTO chat (user, message) VALUES ('$user', '$_POST[message]')"; $result = mysql_query($sql) or die(); } session_start(); if (!empty($_SESSION['username'])) // he got it. { echo ""; } else // bad info. { header('Location: connexion.php'); } //db connect $user = $_SESSION['username']; $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a6743732_pokeb", $con); //max messages $result = mysql_query("SELECT * FROM chat ORDER BY id DESC LIMIT 0, 15"); while($row = mysql_fetch_array($result)) { //smilies $smIn=array("R:"); $smOut=array("EPIC FACE URL"); $o_user = $row['user']; $message = $row['message']; $message = str_replace($smIn, $smOut, $message); echo '<u>'. $o_user . '</u>: '. $message . '</font>'. '</font>'. '</b>' ; echo "<br>"; } ?> </div> <style> #chat { background-color:green; width:320px; height:200px; overflow:auto; } </style> <form action="chat.php" method="POST"> <input type="text" name="message"><input type="submit" value="Chat" name="submit"> </form> <meta name="viewport" content="width=320"> <br> <a href="index.php"><img src="http://png-2.findicons.com/files/icons/1572/minicons/48/refresh.png"></a>refresh <br> Chat! </body> Now i simply get: "Query was empty" Edited December 17, 2012 by Pokebert Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399748 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2012 Share Posted December 17, 2012 Go change your database password on the server right now, since you just posted it on the internet. Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399749 Share on other sites More sharing options...
Muddy_Funster Posted December 17, 2012 Share Posted December 17, 2012 You left the passwords in... Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399750 Share on other sites More sharing options...
Pokebert Posted December 17, 2012 Author Share Posted December 17, 2012 Aww. Well, I'll go change the password.... *facepalm* Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399751 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2012 Share Posted December 17, 2012 $user = $_SESSION['username']; $result = mysql_query($sql) or die(mysql_error()); <---- Why is this here? $sql isn't defined until several lines later, so of course the query is empty. if ($_POST['submit']) { $_POST['message'] = mysql_real_escape_string(htmlentities($_POST['message'])); $sql = "INSERT INTO chat (user, message) VALUES ('$user', '$_POST[message]')"; $result = mysql_query($sql) or die(); See my comment in the code. Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399752 Share on other sites More sharing options...
Pokebert Posted December 17, 2012 Author Share Posted December 17, 2012 Changed password. Thanks for pointing out my epic fail Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399753 Share on other sites More sharing options...
Pokebert Posted December 17, 2012 Author Share Posted December 17, 2012 Okay, I go my script to work. Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/#findComment-1399754 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.