Hello everyone and this is my first post as I am completely new to PHP but trying hard to pick it up. The problem I have is this:
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[email]','$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">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" /></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>

</body>
</html>

My other problem is that I want to set up a testing server in Dreamweaver for ny GoDaddy DB to test it out before uploading but cannot find any settings for it and doesn't work with the info that I put in this form for host etc.

    The form below works perfect on my localhost and inputs data just greats.
    Can anyone please help me adjust this one to work on the GoDaddy database. the example they give is this:
    There are two main steps to connecting to a MySQL database using PHP.

    First, connect to your MySQL server using the mysql_connect statement. For example:

    $con = mysql_connect('HOSTNAME','USERNAME','PASSWORD');
    You can log in to your hosting account manager to find the hostname, user name, and password for your database.

    Next, select the database that you want to access using mysql_select_db. For example:

    mysql_select_db('DATABASENAME', $con)
    Where "DATABASENAME" is the name of your database. Again, you can log in to your hosting account manager to find the name of your database. The name of your database is usually the same as the user name for that database.

    From here, you can query your database using your PHP script.
    FULL EXAMPLE:
    <?php
    //Sample Database Connection Syntax for PHP and MySQL.

    //Connect To Database

    $hostname="your_mysqlserver.secureserver.net";
    $username="your_dbusername";
    $password="your_dbpassword";
    $dbname="your_dbusername";
    $usertable="your_tablename";
    $yourfield = "your_field";

    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);

    Check If Record Exists

    $query = "SELECT * FROM $usertable";

    $result = mysql_query($query);

    if($result)
    {
    while($row = mysql_fetch_array($result))
    {
    $name = $row["$yourfield"];
    echo "Name: ".$name."<br>";
    }
    }
    ?>

    MY SCRIPT THAT WORKS ON LOCALHOST
    <?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>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>
    <?php
    mysql_free_result($register);
    ?>

      Just to clarify, are you trying to connect to the GoDaddy hosted database from a script running on the GoDaddy host, or are you trying to connect to it from a script running on your local PC? If the latter, that probably will not be do-able due to external access restrictions on the database server.

      In any case, if the connection is failing, you might get more useful debug info my adding the return value from mysql_error() to your connection error message. For the production version you would probably want it logged via error_log() rather than risk outputting DB info to the browser, but for now it could help:

      mysql_connect(blah blah blah) or die("Could not connect to DB: " . mysql_error());
      

      PS: Welcome to the forums, and in the future, please make use of this forum's [noparse]

      ...

      [/noparse] bbcode tags around your code blocks in order to help us help you.

        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

          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[email]','$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>

            5 years later

            Simple advice from another newbie: start with the code example that godaddy offers on their site with the variables for connecting to your database that they offer on your db details page...and then work yourself back to where you are now.

              Write a Reply...