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");
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.