Jump to content

Help With A Chat Script?


Pokebert

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/272078-help-with-a-chat-script/
Share on other sites

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"

$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.

 

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.