homepage Welcome to WebmasterWorld Guest from 107.22.45.61
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
unable to connect to sql with a form
sql form
siloxr




msg:4309218
 8:49 am on May 7, 2011 (gmt 0)

So, I'm painfully new at all of this. The last time I even thought about playing around with websites, angelfire was the new hotness and everyone was getting in on some sixdegrees...

Well, I'm trying to learn by doing, but I've ran into a roadblock. I'm attempting to make a simple random quote generator. I've got the MySQL db made, configured, and user set. I decided to try to make a form so populating it would be easier. When I load the URL for the form, I get this error:
Access denied for user 'dbusername'@'localhost' (using password: YES) in /home/hostusername/public_html/quoteform.php on line 18


Here is the code I'm using:
<form action="" method="post">
<fieldset>
<legend>Add a Quote</legend>
<label for="quote">Quote:</label>
<input type="text" name="quote" id="quote" maxlength="1500" />
<label for="author">Author:</label>
<input type="text" name="author" id="author" maxlength="60" />
<input type="submit" value="Add Quote" />
</fieldset>
</form>

<?php
$user="mydbusername";
$password="dbpw";
$database="dbname";
$connection = mysql_connect('localhost',$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

if ($_REQUEST['quote'] != "") {
if($_REQUEST['author'] != "") {
$author = $_REQUEST['author'];
} else {
$author = "Anonymous";
}
$quote = $_REQUEST['quote'];

$query="INSERT INTO `quote` (`quote`,`source`) values ('" . mysql_real_escape_string($quote) . "','" . mysql_real_escape_string($author) . "')";
$result = mysql_query($query) or die(mysql_error());
echo("inserted quote: " . htmlentities($quote) . " by " . htmlentities($author) . " into database");
} else {
echo("<p>Please enter a quote and author</p>");
}
?>


Now, I freely admit to having ganked this code off of a blog (I would include the blog's url, but I'm not sure if that's kosher.) in an attempt to learn by fiddling with, but I'm at a loss.

Oh, I've a shared host at hostgator if that makes any sort of difference.

Thanks

 

eelixduppy




msg:4309413
 11:37 pm on May 7, 2011 (gmt 0)

Hello and Welcome to WebmasterWorld!

Assuming you are using the correct host, username, and password, then my second guess would be that you are using an older mysql library that would require to use an older version of the MySQL passwords. If you can run a query in your database, try doing the following as root (or equivalent):


UPDATE
mysql.user
SET
Password = OLD_PASSWORD('dbpw')
WHERE
Host = 'localhost'
AND User = 'mydbusername';


And then flush the privileges:

FLUSH PRIVILEGES;

siloxr




msg:4309594
 6:37 pm on May 8, 2011 (gmt 0)

Thank you for the reply.

I managed to get it fixed based on your first suggestion. I created a new db user just for that database (I had assigned an existing one prior, with what I thought were full permissions, but obviously were not for whatever reason), and it started working just fine.

Heh, now on to the joys of attempting to figure out how to integrate javascript, php, and html :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved