문제

i get the below error msg for the code given below

"Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'stthohuu'@'localhost' (using password: NO) in /home/stthohuu/public_html/forms/upload_newsletter.php on line 31"

can you please guide me.. am not aware of file upload processes.. please share your suggestions

<html>
<head></head>
<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
    cellspacing="1" class="box">
<tr>
  <td><h4>Please select a file</h4></td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE"
  value="16000000">
<input name="userfile" type="file" id="userfile"> 
</td>
<td width="80"><input name="upload"
  type="submit" class="box" id="upload" value=" Upload "></td>
 </tr>
</table>
</form>
  <a href="newsletter_sec.php">Back</a>
</body>
</html>
<?php
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
//$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(stripslashes ($_FILES['userfile']['name'])));
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'stthohuu_batch', 'abc') or die(mysql_error());
$db = mysql_select_db('stthohuu_church', $con);

/* identify the max id in existing data*/


$max_id[0]='';
$sql="SELECT id FROM newsletter WHERE id=(SELECT max(id) FROM newsletter)";
$result = mysql_query($sql);
$max_id = mysql_fetch_array($result);

if ($max_id[0]=='')
{
  $max_id[0]=0;
}
$id=0;
$id=$max_id[0]+1;  

/* to insert data into newsletter table */

if($db){
$query = "INSERT INTO newsletter (name, size, type, content ) ".
 "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed'); 
mysql_close();
echo "<br>File $fileName uploaded<br>";
}else { echo "file upload failed"; }
} 
 ?>

This s working well in local xampp.. But NOT in web server.. :(

도움이 되었습니까?

해결책

The problem is with your MySQL Connection. Remove mysql_real_escape_string() before opening a MySQL Connection. Generally, your web server will have a different username and password from your local xampp account. Change them.

Also, a best practice is not to use mysql_* functions, instead replace them with mysqli_* or PDO.

다른 팁

You must use your server database setting. You can not use 'localhost' for server database. For more servers it is their database IP. For more detail you can contact your server administrator.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top