Вывод эха на консоль вместо HTML - PullRequest
0 голосов
/ 26 февраля 2019

Моя проблема в том, что значения успешно вставлены в мою БД, но мое эхо «успеха» не работает.Кто-нибудь может помочь?

$conn =  new mysqli($db_host, $db_username, $db_pass, $db_name);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$pw = $_POST['pw'];
$cpw = $_POST['cpw'];

if($pw !== $cpw) {
die("Passwords do not match");
}


$stmt = $conn->prepare("INSERT INTO snpdata (Username, Password, Email, 
Gender) VALUES (?, ?, ?, ?)");

if(!$stmt->bind_param("ssss", $sname, $clean_pw, $clean_em, $gen)) {
    die("Error binding parameters");
} else {}

$gen = $_POST['gender'];
$sname = $_POST['sname'];
$em = $_POST['em'];

$clean_pw = password_hash($pw, PASSWORD_BCRYPT);
$clean_em = password_hash($em, PASSWORD_BCRYPT);

if(!$stmt->execute()) {
    die ('Error executing' . $stmt->error);
} else { 
    echo '<h3 color="green"> SUCCESS </h3>';
}

$stmt->close();
$conn->close();

Я пытался исследовать, как выводить html, но это дало те же результаты, что и то, что я вставил в этот код.

РЕДАКТИРОВАТЬ: Извините за неясностьпроблема в том, что эхо вообще не появляется на странице.

Вот AJAX, он отлично работает.

<script>
function formSubmit() {
$.ajax({
type:'POST',
url: 'snp.php',
data: $('#fm').serialize(),
success:function(response) {
$('#success').html(response);
}

});
var form = document.getElementById('fm').reset()
return false;
}
</script>

Вот мой код формы:

<form id='fm' action="/snp.php" method="post" onsubmit="return formSubmit()">
<div class='snpcontent'>
<h1 style='color: #6e727a; font-weight: 100'> Sign Up Here </h1>
<label style='font-weight: 900'>Username</label>
<input type='text' placeholder='Enter Username' name='sname' required>
<label style='font-weight: 900'>Password</label>
<input type='password' placeholder='Enter Password' name='pw' id="pw" required>
<button onmousedown="document.getElementById('pw').type = 'text' " onmouseup="document.getElementById('pw').type = 'password'" type='button' class="show">Show Password </button>
<label style='font-weight: 900'>Confirm PW</label>
<input type='password' placeholder='Enter Password' name='cpw' id="cpw" required>
<button onmousedown="document.getElementById('cpw').type = 'text' " onmouseup="document.getElementById('cpw').type = 'password'" type='button' class="show">Show Password </button>
<label style='font-weight: 900'> Email </label>
<input type='text' placeholder='Enter Email' name='em' required><br>
<input type='radio' name='gender' value='male' required> Male<br>
<input type='radio' name='gender' value='female' required> Female<br>
<input type='radio' name='gender' value='other' required> Other<br>
<button type='submit' style='background-color: #19ad11; border-color: #19ad11; color: white; font-family: Georgia, verdana; width: 50%; height: 50px; font-size: 20px'> Sign Up </button>
</div>
</form>

1 Ответ

0 голосов
/ 27 февраля 2019

Ой, я только что решил свою проблему.С моим AJAX есть строка кода, которая говорит:

$('#success').html(response);

Получается в моем

<h3> </h3>

Идентификатор был "succes", а не "success", и это вызывало ошибку.Спасибо за вашу помощь!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...