Jacob Tonna
Jacob Tonna

Reputation: 17

Whats wrong with this PHP/MySQL script? It Will Not Work Properly

PLEASE CLOSE THIS I HAVE FIGURED OUT THE ------------MY PROBLEM---------------------------------------- mysql_select_db("members") or die(mysql_error()); echo "Database Found!
";

----------------SOLUTION------------------------------------------------------------------

mysql_select_db("a2670376_Pass") or die(mysql_error()); echo "Database Found!
";


Here's my script

    <?php 
$ud_ID = $_REQUEST["ID"];
$ud_firstname = $_POST["ud_firstname"];
$ud_surname = $_POST["ud_surname"];
$ud_FBID = $_POST["ud_FBID"];
$ud_IMG = $_POST["ud_IMG"];

mysql_connect('mysql13.000webhost.com'… 'a2670376_Users', 'Password') or die(mysql_error());
echo "MySQL Connection Established! <br>";

mysql_select_db("members") or die(mysql_error());
echo "Database Found! <br>";

$query = "UPDATE stokesley_members SET firstname = '$ud_firstname', surname =    '$ud_surname', 
FBID = '$ud_FBID' WHERE ID = '$ud_ID'";

$res = mysql_query($query);

if ($res)
echo "<p>Record Updated<p>";
else
echo "Problem updating record. MySQL Error: " . mysql_error();
?>

<form action="update.php" method="post">
<input type="hidden" name="ID" value="<?=$UID;?>">
IMGNU: <input type="text" name="ud_img" value="<?=$IMGNU;?>"><br>
First Name: <input type="text" name="ud_firstname" value="<?=$firstname?>"><br>
Last Name: <input type="text" name="ud_surname" value="<?=$surname?>"><br>
FB: <input type="text" name="ud_FBID" value="<?=$FBID?>"><br>
<input type="Submit">
</form>

Here's my error MySQL Connection Established! Access denied for user 'a2670376_Users'@'10.1.1.40' to database 'members' I don't know what the 10.1.1.40 is about though I have tried changing it to ("mysql13.000webhost.com", "a2670376_Users", "Password") and still the same thing now this confuses me a lot so I'm not even sure there is an error but i think there is cause if there was no error the script would show could this error be caused because I haven't made the file update.php yet? i have worked out many bugs in this already but cant seem to get this one out please help me you will be a lifesaver and give me credit for noobish script I'm only 13

I don't need to grant rights because I already have rights I have a file named connect.php it connects the register and login scripts that I have that works fine but this wont..

http://fni.site11.com/edit.php is the page I am working on

Upvotes: 0

Views: 159

Answers (5)

Bhanwar
Bhanwar

Reputation: 11

Please check database location and set the privileges for user.

Upvotes: 1

artragis
artragis

Reputation: 3713

first of all switch from mysql_ to mysqli_ or PDO they are more reliable. Then, check the spelling (host, user and password) and the case ! password and username are case sensitive.

Be sure that user a2670376_Users has privilege for selecting, updating and inserting

Upvotes: 0

Martin Bean
Martin Bean

Reputation: 39439

When creating MySQL databases and users, you then need to grant the user privileges to databases. This allows you to create multiple users with different access levels, for example a user that can do everything, and another user who may only have read (SELECT) access, so they can’t INSERT/UPDATE/DELETE or DROP databases and tables.

If you use something like cPanel, you can add users to your database from there.

Upvotes: 0

Pardeep Kumar
Pardeep Kumar

Reputation: 43

If your db hosted on other server then you need to grant the access from * not only for localhost.

Upvotes: 0

Chella
Chella

Reputation: 1562

First make sure that the user specified above enough privileges to select the data from the db given. you can login to the db hosting account and check the privileges of the user "a2670376_Users". And 10.1.1.40 might be your hosted server IP Address.

Upvotes: 0

Related Questions