Please help me PHP geniuses! U are my last hope!
Posted: Tue Feb 17, 2009 5:43 am
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi guys,
I have to start by apologizing for posting what will probably prove to be an easy question! I have been agonizing over this for days now and have tried all the forums and tutorials etc but have hit a real stumbling block.
Basically - I am a web designer and have been learning mysql for a while now and have a good understanding of it (I thought!). I am trying to add a simple guestbook to a website using php, which I have been learning for a while also by following tutorials & scouring the net for tips.
So far I have:
* been on to my hosing servers site & opened a mysql database.
* built my simple database in mysql and added 3 .php pages to my site (details below).
* uploaded my site to my server.
The problem I am having is that when I try to add my first post to my guestbook - I get an error message that reads:
" cannot select DB Access denied for user 'myusername'@'%' to database 'mrcagb' "
(I have changed my actual username for 'myusername' for the purposes of this post but have left the curious '@'%' coz thats nothing to do with me!).
I am really confused! The username & password I have been using are the one's given to me by my hosing provider 'Switch Media'. I went onto their site, accessed the control panel for my website & opened a mysql database. It then gave me my username & asked me to set the password. Am I not using the right details? Should I have set these details in mysql to allow access from my website?
I have had the code checked over by people on Yahoo Answers but I suspect no one on their really gives a stuff! Could any of you give it the once over? I would be forever grateful!
********
I have a simple mysql database called 'mrcagb'
Within that I have a simple table to collect the information called 'guestbook'
I have 3 .php pages on my site called 'guestbook.php', 'addguestbook.php' & 'viewguestbook.php'.
GUESTBOOK.PHP
----------------------------
[THAT SEEMS TO WORK FINE & OFFER A PAGE TO ENTER THE MESSAGE ETC]
ADD GUESTBOOK.PHP
------------------------------------
and then finally:
VIEWGUESTBOOK.PHP
-------------------------------------
Once again - I have changed my username & password for the purposes of this post. I am aware it wont work like that and thats not what I have been doing!
I just want to get this to work so I can get on learning all the juicy things php can do. I am eager to learn but hit a real stumbling block. If any of you have the time to help I will be forever in your debt!
Kind regards
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi guys,
I have to start by apologizing for posting what will probably prove to be an easy question! I have been agonizing over this for days now and have tried all the forums and tutorials etc but have hit a real stumbling block.
Basically - I am a web designer and have been learning mysql for a while now and have a good understanding of it (I thought!). I am trying to add a simple guestbook to a website using php, which I have been learning for a while also by following tutorials & scouring the net for tips.
So far I have:
* been on to my hosing servers site & opened a mysql database.
* built my simple database in mysql and added 3 .php pages to my site (details below).
* uploaded my site to my server.
The problem I am having is that when I try to add my first post to my guestbook - I get an error message that reads:
" cannot select DB Access denied for user 'myusername'@'%' to database 'mrcagb' "
(I have changed my actual username for 'myusername' for the purposes of this post but have left the curious '@'%' coz thats nothing to do with me!).
I am really confused! The username & password I have been using are the one's given to me by my hosing provider 'Switch Media'. I went onto their site, accessed the control panel for my website & opened a mysql database. It then gave me my username & asked me to set the password. Am I not using the right details? Should I have set these details in mysql to allow access from my website?
I have had the code checked over by people on Yahoo Answers but I suspect no one on their really gives a stuff! Could any of you give it the once over? I would be forever grateful!
********
I have a simple mysql database called 'mrcagb'
Within that I have a simple table to collect the information called 'guestbook'
I have 3 .php pages on my site called 'guestbook.php', 'addguestbook.php' & 'viewguestbook.php'.
GUESTBOOK.PHP
----------------------------
Code: Select all
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>Test Sign Guestbook </strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="addguestbook.php">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><input name="name" type="text" id="name" size="40" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td>
</tr>
</table>ADD GUESTBOOK.PHP
------------------------------------
Code: Select all
<?php
$host="localhost";
$username="myusername";
$password="mypassword";
$db_name="mrcadb";
$tbl_name="guestbook";
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB ". mysql_error());
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);
//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page
}
else {
echo "ERROR";
}
mysql_close();
?>VIEWGUESTBOOK.PHP
-------------------------------------
Code: Select all
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>View Guestbook | <a href="guestbook.php">Sign Guestbook</a> </strong></td>
</tr>
</table>
<br>
<?php
$host="localhost";
$username="myusername";
$password="mypassword";
$db_name="mrcadb";
$tbl_name="guestbook";
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB ". mysql_error());
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)...
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td>ID</td>
<td>:</td>
<td><? echo $rows['id']; ?></td>
</tr>
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><? echo $rows['name']; ?></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><? echo $rows['email']; ?></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><? echo $rows['comment']; ?></td>
</tr>
<tr>
<td valign="top">Date/Time </td>
<td valign="top">:</td>
<td><? echo $rows['datetime']; ?></td>
</tr>Once again - I have changed my username & password for the purposes of this post. I am aware it wont work like that and thats not what I have been doing!
I just want to get this to work so I can get on learning all the juicy things php can do. I am eager to learn but hit a real stumbling block. If any of you have the time to help I will be forever in your debt!
Kind regards
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: