efc84 Posted February 13, 2009 Share Posted February 13, 2009 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 More sharing options...
nostrodamned Posted February 13, 2009 Share Posted February 13, 2009 Hi where is $con defined? Do you have the connection script?(is the connection script included) - Host is usually localhost Link to comment https://forums.phpfreaks.com/topic/145056-mysql-php-cannot-access-server/#findComment-761169 Share on other sites More sharing options...
nostrodamned Posted February 13, 2009 Share Posted February 13, 2009 $con=mysql_connect('localhost', 'mysql_user', 'mysql_password'); Link to comment https://forums.phpfreaks.com/topic/145056-mysql-php-cannot-access-server/#findComment-761170 Share on other sites More sharing options...
efc84 Posted February 13, 2009 Author Share Posted February 13, 2009 Sorry if i ask stupid questions but what is the connection script? I know Host is localhost i just put Host for time saving isnt this where con is defined? mysql_select_db("db1", $con); Link to comment https://forums.phpfreaks.com/topic/145056-mysql-php-cannot-access-server/#findComment-761174 Share on other sites More sharing options...
nostrodamned Posted February 13, 2009 Share Posted February 13, 2009 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 Link to comment https://forums.phpfreaks.com/topic/145056-mysql-php-cannot-access-server/#findComment-761178 Share on other sites More sharing options...
efc84 Posted February 13, 2009 Author Share Posted February 13, 2009 <?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 Link to comment https://forums.phpfreaks.com/topic/145056-mysql-php-cannot-access-server/#findComment-761184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.