как правильно сделать MySQL подготовить

<?php
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['action']))):

if (isset($_POST['myname'])) { $myname = $_POST['myname']; } else { $myname = ''; }
if (isset($_POST['mypassword'])) { $mypassword = $_POST['mypassword']; } else { $mypassword = ''; }
if (isset($_POST['mypasswordconf'])) { $mypasswordconf = $_POST['mypasswordconf']; } else { $mypasswordconf = ''; }
if (isset($_POST['mycomments'])) {
$mycomments = filter_var($_POST['mycomments'], FILTER_SANITIZE_STRING ); }
else { $mycomments = ''; }
if (isset($_POST['reference'])) { $reference = $_POST['reference']; } else { $reference = ''; }
if (isset($_POST['favoritemusic'])) { $favoritemusic = $_POST['favoritemusic']; } else { $favoritemusic = array(); }
if (isset($_POST['requesttype'])) { $requesttype = $_POST['requesttype']; } else { $requesttype = ''; }
if (isset($_POST['ajaxrequest'])) { $ajaxrequest = $_POST['ajaxrequest']; } else { $ajaxrequest = ''; }

$formerrors = false;

if ($myname === '') :
$err_myname = '<div class="error">Sorry, your name is a required field</div>';
$formerrors = true;
endif; // input field empty

if (strlen($mypassword) <= 6):
$err_passlength = '<div class="error">Sorry, the password must be at least six characters</div>';
if ( $ajaxrequest ) { echo "<script>$('#mypassword').after('<div class=\"error\">Sorry, the password must be at least six characters</div>');</script>"; }
$formerrors = true;
endif; //password not long enoughif ($mypassword !== $mypasswordconf) :
$err_mypassconf = '<div class="error">Sorry, passwords must match</div>';
if ( $ajaxrequest ) { echo "<script>$('#mypasswordconf').after('<div class=\"error\">Sorry, passwords must match</div>');</script>"; }
$formerrors = true;
endif; //passwords don't matchif ( !(preg_match('/[A-Za-z]+, [A-Za-z]+/', $myname)) ) :
$err_patternmatch = '<div class="error">Sorry, the name must be in the format: Last, First</div>';
$formerrors = true;
endif; // pattern doesn't match

$favoritemusic1 = implode(",", $favoritemusic);
$formid1 = " ";

$formdata = array (
'myname' => $myname,
'mypassword' => $mypassword,
'mypasswordconf' => $mypasswordconf,
'mycomments' => $mycomments,
'reference' => $reference,
'favoritemusic' => $favoritemusic,
'requesttype' => $requesttype
);

date_default_timezone_set('US/Eastern');
$currtime = time();
$datefordb = date('Y-m-d H:i:s', $currtime);
$salty = dechex($currtime).$mypassword;
$salted = hash('sha1', $salty);if (!($formerrors)) :
include("log_formdb.php");

$forminfolink = mysqli_connect($host, $user, $password, $dbname);
/* check connection */

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

/* create a prepared statement */
if ($stmt = mysqli_prepare($forminfolink, "INSERT INTO table form_info (forminfo_id, forminfo_ts, myname, mypassword, mycomments, reference, favoritemusic, requesttype) VALUES (?,?,?,?,?,?,?,?")) {

if ($forminforesult = $stmt):
$msg = "We will get back with you in a timely manner. Thanks.";
if ( $ajaxrequest ):
echo "<script>$('#myform').before('<div id=\"formmessage\"><p>",$msg,"</p></div>'); $('#myform').hide();</script>";
endif; // ajaxrequest
else:
$msg = "Sorry, there was a problem and your data has not been processed.  If this problem continues please send an email to our webmaster at [email protected].";
if ( $ajaxrequest ):
echo "<script>$('#myform').before('<div id=\"formmessage\"><p>",$msg,"</p></div>'); $('#myform').hide();</script>";
endif; // ajaxrequest
endif; //write to database

/* bind parameters for markers */
mysqli_stmt_bind_param($stmt, "isssssss", $formid1, $datefordb, $myname, $mypassword, $mycomments, $reference, $favoritemusic1, $requesttype);

/* execute query */
mysqli_stmt_execute($stmt);

/* close statement */
mysqli_stmt_close($stmt);
}

endif; // check for form errors

endif; //form submitted
?>

Я пытаюсь написать свой первый оператор подготовки mysqli для отправки информации из формы на сервер. Я думаю, что я зациклен на проверке … Я смотрел на другие вопросы, подобные этому, и не видел ничего, что могло бы помочь. Любая идея?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]