vixtay Posted November 13, 2009 Share Posted November 13, 2009 Hi everyone, I am completely new to PHP and trying very hard to teach myself how to use it as I am stepping up to database websites. I have created an MySQL database on GoDaddy and a duplicate on my laptop with phpmyadmin. Both are ok. I set up a testing server in Dreamweaver for the one on my laptop to try out an input info form and it worked perfectly. I have a connection to the database on localhost and the data from the form inserted into the datbase perfectly. Now I need to adapt that same form to do exactly the same but input info in my database on GoDaddy. I have looked on their help section and used the example that they give. But to no joy, I cannot connect to the datbase despite using the correct login details so I am assuming it must be somehting I am doing wrong with the PHP coding. Can someone please take a look at this and tell me where I am going wrong. Many thanks in anticipation. I have changed the actual details with capitals to show you. <?php //Connect To Database $hostname="HOSTNAME PROVIDED BY GoDADDY.hostedresource.com"; $username="MY USERNAME"; $password="MY PASSWORD"; $dbname="vixtay.db"; $usertable="members"; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); $sql="INSERT INTO registrants (Name, Telephone, Email, Username, Password) VALUES ('$_POST[name]','$_POST[telephone]','$_POST','$_POST[username]','$_POST[password]')))"; if($result) { while($row = mysql_fetch_array($result)) { $name = $row["$yourfield"]; echo "Name: ".$name."<br>"; } } ?> <html> <body> <form action="http://www.southwalespropertysolutions.com/insertinfo.php" method="post"> <table width="300" border="1"> <tr> <td>Name:</td> <td><input name="name" type="text" id="name" size="40" /></td> </tr> <tr> <td>Telephone:</td> <td><input name="telephone" type="text" id="telephone" size="40" /></td> </tr> <tr> <td>Email:</td> <td><input name="email" type="text" id="email" size="40" /></td> </tr> <tr> <td>Username:</td> <td><label> <input name="username" type="text" id="username" size="40"> </label></td> </tr> <tr> <td>Password:</td> <td><label> <input name="password" type="text" id="password" size="40"> </label></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td> </td> <td><input type="submit" /></td> </tr> </table> <p> </p> <p> </p> <p> </p> <p> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/ Share on other sites More sharing options...
Schlo_50 Posted November 13, 2009 Share Posted November 13, 2009 I just visited the page your trying to process and the error returned was: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'vixtay' etc.. That error means that the database 'vixtay.db' doesn't exist. I'd suggest checking your database names. Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-956705 Share on other sites More sharing options...
vixtay Posted November 13, 2009 Author Share Posted November 13, 2009 I just visited the page your trying to process and the error returned was: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'vixtay' etc.. That error means that the database 'vixtay.db' doesn't exist. I'd suggest checking your database names. I have just logged into it to double check and the database is definately there and called vixtay with one table called members. What I did notice in the home page was that it had User: [email protected] That is all I can see everything is correct, i.e. the database name, the Hostname, my password etc. Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-956710 Share on other sites More sharing options...
vixtay Posted November 13, 2009 Author Share Posted November 13, 2009 This is the info on GoDaddy under MySql: Status:Setup Host Name:vixtay.db.4394481.hostedresource.com Database Name:vixtayDatabase Version:5.0 Description:Registrations User Name:vixtay DSN:Pending Setup Just to show that there is an actual database and it is all setup. I could really do with some help here guys as I am going to need a few php forms for this such as login check users etc. and the most important one is this one as it will be linked to a register form. The one below works perfect on localhost, can anyone help me change this one to work on GoDaddy? <?php require_once('Connections/vixtay.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO registrants (Name, Telephone, Email, Username, Password) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['Name'], "text"), GetSQLValueString($_POST['Telephone'], "text"), GetSQLValueString($_POST['Email'], "text"), GetSQLValueString($_POST['Username'], "text"), GetSQLValueString($_POST['Password'], "text")); mysql_select_db($database_vixtay, $vixtay); $Result1 = mysql_query($insertSQL, $vixtay) or die(mysql_error()); $insertGoTo = "thanks.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_vixtay, $vixtay); $query_register = "SELECT Name, Telephone, Email, Username, Password FROM registrants"; $register = mysql_query($query_register, $vixtay) or die(mysql_error()); $row_register = mysql_fetch_assoc($register); $totalRows_register = mysql_num_rows($register); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Register</title> <style type="text/css"> <!-- .style2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; } --> </style> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Name:</div></td> <td><input name="Name" type="text" value="" size="40" maxlength="40" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Telephone:</div></td> <td><input name="Telephone" type="text" value="" size="15" maxlength="15" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Email:</div></td> <td><input name="Email" type="text" value="" size="40" maxlength="40" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Username:</div></td> <td><input name="Username" type="text" value="" size="25" maxlength="25" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Password:</div></td> <td><input name="Password" type="password" value="" size="25" maxlength="25" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left"></div></td> <td><input type="submit" value="Register" /></td> </tr> </table> <p> <input type="hidden" name="MM_insert" value="form1" /> </p> </form> <p> </p> <p> </p> </body> </html> <?php mysql_free_result($register); ?> Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-956884 Share on other sites More sharing options...
siric Posted November 13, 2009 Share Posted November 13, 2009 //Connect To Database $hostname="HOSTNAME PROVIDED BY GoDADDY.hostedresource.com"; $username="MY USERNAME"; $password="MY PASSWORD"; $dbname="vixtay.db"; $usertable="members"; This is the info on GoDaddy under MySql: Status:Setup Host Name:vixtay.db.4394481.hostedresource.com Database Name:vixtayDatabase Your script shows the database name as "vixtay.db", yet the GoDaddy information shows the name as "vixtayDatabase". Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-956901 Share on other sites More sharing options...
Schlo_50 Posted November 13, 2009 Share Posted November 13, 2009 Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-956946 Share on other sites More sharing options...
vixtay Posted November 13, 2009 Author Share Posted November 13, 2009 Hi thanks for your suggestions. I just tried it with VixtayDatabase and by putting . mysql_error()); in and this is what I get: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'vixtay'@'72.167.232.219' (using password: YES) in D:\Hosting\4394481\html\insertinfo.php on line 11 Unable to connect to database! Please try again later.Access denied for user 'vixtay'@'72.167.232.219' (using password: YES) Why am I getting this and in particular D:\hosting\4394481\html\insertinfo.php on line 11 because I have uploaded the insertinfo.php to the host server Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-957065 Share on other sites More sharing options...
siric Posted November 13, 2009 Share Posted November 13, 2009 I do not know the schema for GoDaddy, but usually copying the file from a localhost verbatim will not work. Try changing the hostname to "localhost". Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-957108 Share on other sites More sharing options...
vixtay Posted November 13, 2009 Author Share Posted November 13, 2009 Thank you again for the advice. Through trial and error I have no got the form to connect to the database, it seemed I simply had the password wrong!! So I have changed it and now the form is visable here: http://www.southwalespropertysolutions.com/insertinfo.php But the form does not input the data into the members table. Can you please take a look below and see why this is and how I correct it. I also want to link to this page when the registration is successful, what do I put in for this and where please: http://www.southwalespropertysolutions.com/thanks.php Here is the current code that gets the form to at least be seen. <?php //Connect To Database $hostname="vixtay.db.4394481.hostedresource.com"; $username="vixtay"; $password="password"; $dbname="vixtay"; $usertable="members"; mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>"); mysql_select_db($dbname); $sql="INSERT INTO MEMBERS (Name, Telephone, Email, Username, Password) VALUES('$_POST[name]','$_POST[telephone]','$_POST','$_POST[username]','$_POST[password]')))"; if($result) { while($row = mysql_fetch_array($result)) { $name = $row["$yourfield"]; echo "Name: ".$name."<br>"; } } ?> <html> <body> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Name:</div></td> <td><input name="Name" type="text" value="" size="40" maxlength="40" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Telephone:</div></td> <td><input name="Telephone" type="text" value="" size="15" maxlength="15" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Email:</div></td> <td><input name="Email" type="text" value="" size="40" maxlength="40" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Username:</div></td> <td><input name="Username" type="text" value="" size="25" maxlength="25" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left" class="style2">Password:</div></td> <td><input name="Password" type="password" value="" size="25" maxlength="25" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"><div align="left"></div></td> <td><input type="submit" value="Register" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/181361-help-needed-with-form-code-for-mysql-database-on-godaddy/#findComment-957112 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.