Jump to content

Shoutbox code cant understand why it gives an error.


dynamicgfx

Recommended Posts

Hi there ive got this php code for a shoutbox im working on but i keep getting the error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a7865530_shout'@'localhost' (using password: YES) in /home/a7865530/public_html/index.php on line 66

The while loop works its just when im inserting something it give an error

<style>
table {
border:thin solid #000;
width:600px;
font-family:arial;
}
th {
color:#fff;
background:#000;
}
</style>
<?
$username="a7865530_shout";
$password="passwordishere";
$database="a7865530_shout";
$host="mysql16.000webhost.com";
if(!isset($_GET['insert'])){ ?>
<meta http-equiv="REFRESH" content="20;url=/">
<table style="max-height:600px;overflow:scroll;" border="0">
<tr>
<th>Name:</th>
<th>Message:</th>
</tr>
<?php
$con = mysql_connect($host, $username, $password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($database , $con);

$result = mysql_query("SELECT * FROM shout");

while($row = mysql_fetch_array($result))
  {
  echo "<tr><td>";
  echo stripslashes($row['name']) . "</td><td/> " . stripslashes($row['message']);
  echo "</td></tr>";
  }

mysql_close($con);
?>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<form name="addform" method="post" action="?insert">
  <tr>
     <td align="center">
       Name:
       <input type="text" id="name" name="name">
       Message:
       <input type="text" id="message" name="message">
       <input type="submit" name="shout" title="shout" value="shout">
     </td>
  </tr>
</table>
</form>
<?php
} else {
$table="shout";
$name = $_POST['name'];
$message = $_POST['message'];
$name = stripslashes($name);
$message = stripslashes($message);
$ip = $_SERVER['REMOTE_ADDR'];  
mysql_connect($$host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="INSERT INTO $table (ip,name, message) values ('$ip','$name','$message')";
$result=mysql_query($query);
echo "Succsesfully Shouted. <a href=\"/\">Return</a>";
header("location: .../index.php");
}
?>

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.