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> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($register);
?>