I have been trying to sort this out but so far I haven't been able to get it to work. No errors are thrown, the page refreshes on submit. I am at a loss, but I am not exactly an expert, fairly new to this.
Here is the code (simplified for posting):
<?php if (!isset($_POST['submit'])) {
echo "<!-- Form starts here -->
<form id=\"billing\" action=\"\" method=\"post\">
<!-- Name -->
<div class=\"control-group\">
<label class=\"control-label\"><b>Name</b></label>
<div class=\"controls\">
<input type=\"text\" id=\"name\" name=\"name\" placeholder=\"your name\" class=\"input-large\">
</div>
</div>
<!-- Zip -->
<div class=\"control-group\">
<label class=\"control-label\"><b>Zip Code</b></label>
<div class=\"controls\">
<input type=\"text\" id=\"billingzip\" name=\"billingzip\" placeholder=\"5 digit zip\" class=\"input-large\">
</div>
</div>
<!-- Submit -->
<div class=\"control-group\">
<div class=\"controls\">
<button class=\"button save small_green_button\" type=\"submit\">
Save
</button>
</div>
</div>
</form>";
}
else
{
$host="localhost";
$user_name="user";
$pwd="password";
$database_name="database";
$db=mysql_connect($host, $user_name, $pwd) or die(mysql_error());
$dbsel=mysql_select_db($database_name, $db);
if (mysql_error() > "") print mysql_error() . "<br>";
if (mysql_error() > "") print mysql_error() . "<br>";
$account_id = users::getAttr('Account', 'account_id');
$zip = mysql_real_escape_string($_POST['billingzip']);
$name = mysql_real_escape_string($_POST['name']);
$sql = "INSERT INTO `billing`
SET `account_id` = '{$account_id}',
`zip` = '{$billingzip}',
`name` = '{$name}',
`updated_at` = NOW()";
$result = mysql_query($sql, $dbsel)
or die(mysql_error().$sql);
mysql_close($db);
}
?>
mysql_*functions, especially when you are learning it. They are in the process of becoming deprecated and will be removed in future versions of PHP. Learn withmysqli_*or PDO right away.{$billingzip}should be{$zip}, and if$account_idis a numerical value you don't need the quotes in the query around it. Not sure though if that would result in an invalid query.submitin your form.type="submit"is notname="submit"