I have a form here that once submitted keeps giving me the error ‘No database selected’ I can’t understand this because if I test locally it’s fine and submits to the database but once uploaded to the server it’s giving this message instead of being redirected to a ‘Thank You’ page. Any other pages on the site connect ok.
Any ideas as to why this is because I have used similar on a good few sites and never had this problem before.
Thanks
Brian
Code: Select all
<?php require_once('Connections/snazzy.php'); ?>
<?php
$pattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
if ($_POST && array_key_exists('submit',$_POST)) {
$messageemail = '';
$nomessage='';
$fname_error = '';
$message_fname = '' ;
$email= $_POST['email'];
$error_email=array();
$trimmedGuestDetails = $_POST['GuestDetails'];
// Check each field and build errors array if problems found
//Full Name Conditional
if (isset($_POST['name']) && !empty($_POST['name'])) {
$message_fname=trim(strip_tags($_POST['name']));
}else{
$fname_error = '<b>Required</b>';
}
if (!trim($message_fname) && !empty($_POST['name'])) {
$fname_error = '<b>Required!</b>';
}
// EmailConditional Statement
if (isset($_POST['email']) && !empty($_POST['email'])) {
}else{
$messageemail = '<b>Required</b>';
}
if (empty($_POST['email'])) { // validation of email if inserted otherwise ignore
} else {
if (!preg_match($pattern,$email)) $error_email['invalid'] = '<b>ERROR! Your email address seems to be invalid. <br> It should be similar to the following: info@me.com</b>';
}
if (isset($_POST['GuestDetails']) && !empty($_POST['GuestDetails'])) {
$trimmedGuestDetails=trim(strip_tags($_POST['GuestDetails']));
}
else {
$nomessage = '<b>Required</b>';
}
if (!trim($trimmedGuestDetails) && !empty($_POST['GuestDetails'])) {
$nomessage = '<b>Required!</b>';
}
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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["submit"])) && ($_POST["submit"] == "addToCart")) {
if (!$nomessage && !$messageemail)
if (!$nomessage && !$error_email)
if (!$nomessage && !$fname_error)
{
/* send mail etc*/
if ((isset($_POST["submit"])) && ($_POST["submit"] == "addToCart")) {
$insertSQL = sprintf("INSERT INTO tbl_embroidery (name, email, details, ip) VALUES (%s, %s, %s,'".$_SERVER['REMOTE_ADDR']."')",
GetSQLValueString("$message_fname", "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString("$trimmedGuestDetails", "text"));
mysql_select_db($database_snazzy, $snazzy);
$Result1 = mysql_query($insertSQL, $snazzy) or die(mysql_error());
$insertGoTo = "embro_act.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}}}
?>