Jump to content

MYSQL PHP cannot access server


efc84

Recommended Posts

Hi, first post so hope its a good one!

 

I'm building a basic website for a business and i'm only a beginner.

 

I want a page where customers fill in their details, they then press submit and their information is stored on the database.

 

I'm using MySQL, PhpMyAdmin and Dreamweaver to author the page.

 

I have coded the page and when testing it out i get the following error message

 

"Could not connect: Host 'My Host' is not allowed to connect to this MySQL server"

 

All my login in details, password ETC are correct

 

Is this to do with privilages on PhpMyAdmin?

 

Here is the code

 

<?php
        // This tells us if the user has pressed the submit button
        if($_POST['submit']){
                
	$con = mysql_connect('HOST','USER NAME','PASS');
	if (!$con)
	 	{die('Could not connect: ' . mysql_error());}
	mysql_select_db("db1", $con);
                
                // Now we will get the information from the input boxes and clean it
                $forename = mysql_escape_string($_POST['forename']);
                $surname = mysql_escape_string($_POST['surname']);
                $postcode = mysql_real_escape_string($_POST['postcode']);
                $email = mysql_real_escape_string($_POST['email']);
                $mobile = mysql_real_escape_string($_POST['mobile']);
                
                // Now we will add the data to the database
                mysql_query("insert into `customers` (`forename`, `surename`, `postcode`, `email`, `mobile`) values ($forename, $surname, $postcode, $email, $mobile)") or die('Could not add your information to the database!');
                
                // Tell the users their details have been entered into the database
                echo "Thanks! Your details have been added to our database!";
        }
?>

<form action="register.php" method="post">
    
</form>
		<form id="form1" method="post" action="">
		  <p>
		    <label><span id="sprytextfield1">First Name
		    <input type="text" name="forename" id="forename" />
		    <span class="textfieldRequiredMsg">A value is required.</span></span></label>
		    <br />
		    <span id="sprytextfield2">
		    <label>Surname
		    <input type="text" name="surname" id="surname" />
		    </label>
		    <span class="textfieldRequiredMsg">A value is required.</span></span><br />
		    <span id="sprytextfield3">
                <label>Postcode
                <input type="text" name="postcode" id="postcode" />
                </label>
                <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
                <span id="sprytextfield4">
                <label>Email
                <input type="text" name="email" id="email" />
                </label>
                <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
                <span id="sprytextfield5">
                <label>Mobile
                <input type="text" name="mobile" id="mobile" />
                </label>
                <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
		    <label></label>
		    <label>
	        <input type="submit" name="submit" id="submit" value="Submit" />
	        </label>
	      </p>
	    </form>

 

Hope someone can help

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/145056-mysql-php-cannot-access-server/
Share on other sites

sorry was me!

I never looked at the code properly - usually the connection settings are stored in a seperate script.

The mysql error you mention is basically saying the user My Host - cant connect - that means in the script you are using MY Host as the username?

This is either due to incorrect details in the connection script or a mysql permission issue which is restricting access to that host - is the mysql running on a different server?

 

Can you post the full connection script - replace the password with xxxx.

 

Cheers

<?php
        // This tells us if the user has pressed the submit button
        if($_POST['submit']){
                
	$con = mysql_connect('mysql.powerpanel.co.uk','ohnatu_1','XXXX');
	if (!$con)
	 	{die('Could not connect: ' . mysql_error());}
	mysql_select_db("db1", $con);
                
                // Now we will get the information from the input boxes and clean it
                $forename = mysql_escape_string($_POST['forename']);
                $surname = mysql_escape_string($_POST['surname']);
                $postcode = mysql_real_escape_string($_POST['postcode']);
                $email = mysql_real_escape_string($_POST['email']);
                $mobile = mysql_real_escape_string($_POST['mobile']);
                
                // Now we will add the data to the database
                mysql_query("insert into `customers` (`forename`, `surename`, `postcode`, `email`, `mobile`) values ($forename, $surname, $postcode, $email, $mobile)") or die('Could not add your information to the database!');
                
                // Tell the users their details have been entered into the database
                echo "Thanks! Your details have been added to our database!";
        }
?>

<form action="register.php" method="post">
    
</form>
		<form id="form1" method="post" action="">
		  <p>
		    <label><span id="sprytextfield1">First Name
		    <input type="text" name="forename" id="forename" />
		    <span class="textfieldRequiredMsg">A value is required.</span></span></label>
		    <br />
		    <span id="sprytextfield2">
		    <label>Surname
		    <input type="text" name="surname" id="surname" />
		    </label>
		    <span class="textfieldRequiredMsg">A value is required.</span></span><br />
		    <span id="sprytextfield3">
                <label>Postcode
                <input type="text" name="postcode" id="postcode" />
                </label>
                <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
                <span id="sprytextfield4">
                <label>Email
                <input type="text" name="email" id="email" />
                </label>
                <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
                <span id="sprytextfield5">
                <label>Mobile
                <input type="text" name="mobile" id="mobile" />
                </label>
                <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />
		    <label></label>
		    <label>
	        <input type="submit" name="submit" id="submit" value="Submit" />
	        </label>
	      </p>
	    </form>

 

Not sure what server the MySQL is on mate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.