Jeśli nie ten dział to proszę moderatorów o przesunięcie do innego
Mam gotową stronę ze starym skryptem wyglądowo jest ok ale nie funkcjonuje zapisywanie do bazy.
Nie bardzo wiem gdzie szukać przyczyny po za tym że index jest w html
jest to formularz ,który ma tylko zapisać lub wypisać z bazy.
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Zapisz się i zgarnij LODA Proteinowego
</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="css/normalize.css"> <link rel="stylesheet" href="css/main.css"> <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800' rel='stylesheet' type='text/css'> <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> <!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<form id="subscribe-form" class="subscribe-form hide"> <div class="form-title">Zapisz się i zgarnij Loda Proteinowego
</div> <div class="form-loading hide"><i class="fa fa-circle-o-notch fa-spin"></i></div> <div class="form-message hide"> Dzięki teraz zgłoś się po LODA !
</div> <div class="form-content"> <div class="input-prefix"> <i class="fa fa-user"></i> <input id="email" name="email" class="form-control" type="email" placeholder="Your email"> <div class="input-prefix"> <i class="fa fa-envelope"></i> <input id="name" name="name" class="form-control" type="text" placeholder="Your name"> <div class="group group-submit"> <div class="form-footer"> <a class="btn" data-toggle="unsubscribe" href="#">Wypisz się
</a> <input type="hidden" name="action" value="subscribe">
<form id="unsubscribe-form" class="subscribe-form hide"> <div class="form-title unsubscribe">Unsubscribe from our newsletter
</div> <div class="form-loading hide"><i class="fa fa-circle-o-notch fa-spin"></i></div> <div class="form-message hide"> You've been unsubscribed.
</div> <div class="form-content"> <div class="input-prefix"> <i class="fa fa-user"></i> <input id="unsubscribe_email" name="unsubscribe_email" class="form-control" type="email" placeholder="Your email"> <input id="confirm" type="checkbox" name="confirm" value="T"> <label for="confirm">Click to confirm you want to unsubscribe
</label> <div class="group group-submit"> <div class="form-footer"> <a class="btn" data-toggle="subscribe" href="#">Subscribe
</a> <input type="hidden" name="action" value="unsubscribe">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script>window.jQuery || document.write('
<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')
</script>
CREATE TABLE IF NOT EXISTS `subscription_form` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(250) NOT NULL,
`name` varchar(250) NOT NULL,
`date_subscribe` datetime NOT NULL,
`date_unsubscribe` datetime NOT NULL,
`status` char(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
# CONFIG
define('_DB_HOST', 'xxxxxxxxxxxxxxx'); define('_DB_NAME', 'xxxxxxxxxxxxxxx'); define('_DB_USER', 'xxxxxxxxxxxxxxx'); define('_DB_PASS', 'xxxxxxxxxxxxxxx');
$subscribe = (isset($_POST['action']) && $_POST['action'] == 'unsubscribe')?
false:true;
if ($subscribe){
array('name' => 'email', 'valid' => array('require', 'email')), array('name' => 'name', 'valid' => array('require')), );
}else{
array('name' => 'unsubscribe_email', 'valid' => array('require', 'email')), array('name' => 'confirm', 'valid' => array('require'), 'err_message' => 'Please confirm'), );
}
// Connect to database
$connection = mysql_connect(_DB_HOST
, _DB_USER
, _DB_PASS
) or
die ('Unable to connect to MySQL server.<br ><br >Please make sure your MySQL login details are correct.'); $db = mysql_select_db(_DB_NAME
, $connection) or
die ('request "Unable to select database."');
foreach ($fields AS $field){
$value = isset($_POST[$field['name']])?
$_POST[$field['name']]:''; }
}
$is_valid = true;
$err_message = '';
if (!empty($field['valid'])){ foreach ($field['valid'] AS $valid) {
switch ($valid) {
case 'require':
$is_valid = $is_valid && strlen($value) > 0; $err_message = 'Field required';
break;
case 'email':
$is_valid = $is_valid && preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $value); $err_message = 'Email required';
break;
default:
break;
}
}
}
if (!$is_valid){
if (!empty($field['err_message'])){ $err_message = $field['err_message'];
}
$error_fields[] = array('name' => $field['name'], 'message' => $err_message); }
}
if (empty($error_fields)){ if ($subscribe){
'email' => "'".$get['email']."'",
'name' => "'".$get['name']."'",
'date_subscribe' => 'NOW()',
'status' => "'T'",
);
}else{
$sql = "UPDATE subscription_form SET date_unsubscribe = NOW(), status = 'F' WHERE email = '".$get['unsubscribe_email']."'";
}
$sql_result = mysql_query ($sql, $connection ) or
die ('request "Could not execute SQL query" '.$sql); }
echo (json_encode
(array('code' => 'success'))); }else{
echo json_encode
(array('code' => 'failed', 'fields' => $error_fields)); }
Ten post edytował traczu1985 26.08.2019, 17:43:32