PHPのMySQLについてエラーがでてしまいました。
192.168.1.30で実行すると
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'staff'@'localhost' (using password: YES)' in /home/user/public_html/honorific_input.php:78 Stack trace: #0 /home/user/public_html/honorific_input.php(78): PDO->__construct('mysql:host=loca...', 'staff', 'password') #1 {main} thrown in /home/user/public_html/honorific_input.php on line 78
というエラーがでてしまいます。
http://localhost/kisoform_/honorific_input.phpで実行すると、エラーは表示されません。
エラーがでてしまうのが嫌です。なぜでしょうか。
php:honorific_input.php
1<?php 2var_dump($_POST); 3// var_dump($_POST['keyword']); 4var_dump($_REQUEST); 5 6// if($_POST) { 7// $keyword = $_POST['keyword']; 8// } 9?> 10<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 11"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 12<html xm1ns="http://www.w3.org/1999/xhtml"> 13<html lang="ja"> 14<head> 15<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 16<meta http-equiv="Content-Script-Type" content="text/javascript"> 17 18 19<title>敬語学習ノート</title> 20<style type="text/css"> 21.font1 { 22 font-family: "あずきフォント", serif; 23} 24 25.font2 { 26 font-family: "あずきフォント", serif; 27 font-size:160%; 28 color:"#e4b9f9"; 29} 30.body{ 31 cursor:url(hosi5.ani); 32} 33html,body { 34 scrollbar-base-color:#c3d7e0; 35 scrollbar-track-color:#c3d7e0; 36 scrollbar-face-color:#c3d7e0; 37 scrollbar-shadow-color:#c3d7e0; 38 scrollbar-darkshadow-color:#c3d7e0; 39 scrollbar-highlight-color:#c3d7e0; 40 scrollbar-3dlight-color:#c3d7e0; 41 scrollbar-arrow-color:#ffffff; 42 filter:chroma(color=#c3d7e0); 43 } 44</style> 45</head> 46<body> 47<table cellspacing="0" cellpadding="4" style="border:5px black solid;"><tr><td style="border:5px brown inset;color:white;" bgcolor="green"> 48<p class="font1">検索したい文字を入力してください</p> 49<form action="" method="post"> 50<input type="text" name="keyword"> 51<input type="submit" value="検索"> 52</form> 53</p> 54 55</td></tr></table> 56 57<!-- <p class="font1">検索したい文字を入力してください</p> --> 58<!-- <form action="" method="post"> --> 59<!-- <input type="text" name="keyword"> --> 60<!-- <input type="submit" value="検索"> --> 61<!-- </form> --> 62<!-- </p> --> 63<!-- <img src="敬語学習ノートロゴ.png"></img> --> 64 <table border="1" width="80%"> 65 <caption class="font2" >敬語学習ノート</caption> 66</br> 67</p> 68 69 </br> 70 <tr style="background: #ccccff"> 71 <th class="font1">番号</th> 72 <th class="font1">タメ語</th> 73 <th class="font1">正しい敬語</th> 74 <th class="font1">例文</th> 75 </tr> 76<?php 77 78$pdo = new PDO ( 'mysql:host=localhost;dbname=honorific;charset=utf8', 'staff', 'password' ); 79 80if($_POST){ 81$vKeyword = isset($_POST['keyword']) ? $_POST['keyword']:''; 82 83$sql = $pdo->prepare ( 'select * from honorifics where wrongHonorific like ? or rightHonorific like ? or example like ?' ); 84$sql->execute (array ('%'.$vKeyword.'%','%'.$vKeyword.'%','%'.$vKeyword.'%')); 85function h($str) { 86 return htmlspecialchars ( $str ); 87} 88foreach ( $sql->fetchAll() as $row ) { 89 echo '<tr>'; 90 echo '<td>' . h ( $row ['id'] ), '</td>'; 91 echo '<td>', h ( $row ['wrongHonorific'] ), '</td>'; 92 echo '<td>', h ( $row ['rightHonorific'] ), '</td>'; 93 echo '<td>', h ( $row ['example'] ), '</td>'; 94 echo '</tr>'; 95 echo "\n"; 96} 97}else if(empty($_POST['keyword'])){ 98function h($str) { 99 return htmlspecialchars ( $str ); 100} 101foreach ( $pdo->query('select * from honorifics') as $row ) { 102 echo '<tr>'; 103 echo '<td>' . h ( $row ['id'] ), '</td>'; 104 echo '<td>', h ( $row ['wrongHonorific'] ), '</td>'; 105 echo '<td>', h ( $row ['rightHonorific'] ), '</td>'; 106 echo '<td>', h ( $row ['example'] ), '</td>'; 107 echo '</tr>'; 108 echo "\n"; 109} 110} 111?> 112</table> 113</body> 114</html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/07 02:06
2017/02/07 02:12
2017/02/07 02:41
2017/02/07 02:56
2017/02/07 03:01
2017/02/07 03:12
2017/02/07 04:04
2017/02/07 04:10
2017/02/07 04:20
2017/02/07 04:40
2017/02/07 05:07
2017/02/07 06:34
2017/02/07 06:36
2017/02/07 06:39
2017/02/07 06:50
2017/02/07 07:03
2017/02/09 03:45