Создание страницы обновления профиля пользователя с использованием PHP MySql

0

Мне удалось продолжить работу с моей страницей обновления пользователей, и все это кажется прекрасным в той форме, в которой я читал текущие данные от входа в систему, когда я нажал кнопку "Отправить", говорит, что отправить успешно, затем я застрял на этой странице, t вернитесь назад, я не знаю, если он работал, и не может видеть никаких сообщений об ошибках или любого, что я могу видеть.

Я очень новичок в кодировании, так что извините, если какая-нибудь глупая ошибка, которую я пропустил... кто-то мне помогает...

Вот мой PHP

<?php

include_once("php_includes/check_login_status.php");
session_start();
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
}
else {
echo "You have not signed in";
}

// Initialize any variables that the page might echo
$firstname = "";
$surname = "";
$u = "";
$weight = "";
$height = "";
// Make sure the _GET username is set, and sanitize it
if(isset($_GET["u"])){
    $u = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
} else {
    header("location: index.php");
    exit(); 
}

// Select the member from the users database table
$sql = "SELECT * FROM users WHERE username='$u' AND activated='1' LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
// check if the user exists in the database
$numrows = mysqli_num_rows($user_query);
if($numrows < 1){
   echo "That user does not exist or is not yet activated, press back";
exit(); 
}

while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$firstname = $row["firstname"];
$surname = $row["surname"];
$weight = $row["weight"];
$height = $row["height"];
$profile_id = $row["id"];
$u = $row["u"];
}

// this is the calculation of the BMI index
//$BMI = ($weighteight / ($heighteight * $heighteight))* 10000;


if($firstname =="" || $surname == ""|| $weight == "" || $height == ""){
echo "The form submission is missing values.";
    exit();
} else {    
    $p_hash = md5($p);
    // Add user info into the database table for the main site table
    $sql = "INSERT INTO users (firstname, surname, weight, height)       
                           VALUES('$fn','$sn','$w','$h')";
    $query = mysqli_query($db_conx, $sql); 
    $uid = mysqli_insert_id($db_conx);
    // Establish their row in the useroptions table
    $sql = "INSERT INTO useroptions (id, username, background) VALUES ('$uid','$u','original')";
    $query = mysqli_query($db_conx, $sql);
    // Create directory(folder) to hold each user files(pics, MP3s, etc.)
    if (!file_exists("user/$u")) {
        mkdir("user/$u", 0755);
    }
    // Email the user their activation link
    $to = "$e";                          
    $from = "[email protected]";
    $subject = 'studentnet.kingston.ac.uk/k1003140';
    $message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursitename Message</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.yoursitename.com"><img src="http://www.yoursitename.com/images/logo.png" width="36" height="30" alt="yoursitename" style="border:none; float:left;"></a>yoursitename Account Activation</div><div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="https://studentnet.kingston.ac.uk/k1003140/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';
    $headers = "From: $from\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    mail($to, $subject, $message, $headers);
    echo "signup_success";



    exit();
}
exit();
?>

Вот мой код Javascript

<script>
function signup(){
var u = _("username").value;
var fn = _("firstname").value;
var sn = _("surname").value;
var w = _("weight").value;
var h = _("height").value;
var e = _("email"). value;
var status = _("status");
if(fn == "" || sn == "" || w == "" || h == ""|| g == ""){
    status.innerHTML = "Fill out all of the form data";
} else {
    _("signupbtn").style.display = "none";
    status.innerHTML = 'please wait ...';
    var ajax = ajaxObj("POST", "signup.php");
    ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
            if(ajax.responseText != "signup_success"){
                status.innerHTML = ajax.responseText;
                _("signupbtn").style.display = "block";
            } else {
                window.scrollTo(0,0);
                _("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
            }
        }
    }
    ajax.send("fn="+fn+"&sn="+sn+"&w="+w+"&h="+h+);
}
} 

здесь я добавил еще немного своего кода, чтобы увидеть HTML

    <body>
<?php include_once("template_pageTop.php"); ?>
    <div id="pageMiddle">  
    <form name="signupform" id="signupform" onsubmit="return false;">  
    <div id="usernamecss"><?php echo $u; ?></div>
    <p><b>Is the viewer the page owner, logged in and verified? <?php echo $isOwner; ?></b></p>   
    <p>First Name: <input type="text" name="firstname" onfocus="emptyElement('status')" size="35" maxlength="15" value='<?=$firstname?>'></p>
    <p>Surname: <input type="text" name="surname" onfocus="emptyElement('status')" size="35" maxlength="15" value='<?=$surname?>'></p>
    <p>Weight: <input type="text" name="weight" onfocus="emptyElement('status')" size="35" maxlength="15" value='<?=$weighteight?>'></p>
    <p>Height: <input type="text" name="height" onfocus="emptyElement('status')" size="35" maxlength="15" value='<?=$heighteight?>'></p>
    <button id="signupbtn" onclick="signup()">Create Account</button>
    </div>
    </form>
        <?php include_once("template_pageBottom.php"); ?>
        <span id="status"></span>
</body>
  • 0
    Ваш запрос вставки указал больше столбцов, чем вставлено. Они по умолчанию нулевые?
  • 0
    Я исправил это, все еще идет к успеху регистрации прямо, не давая мне HTML @ RoyalBg
Показать ещё 2 комментария
Теги:

2 ответа

0

Как я вижу, вы делаете POST в своем ajax, но реагируете на GET на вашем php.

Попробуйте изменить:

if(isset($_GET["u"])){

чтобы:

if(isset($_POST["u"])){

или:

if(isset($_REQUEST["u"])){
0

я не могу написать комментарий, поэтому напишу здесь. U должен использовать session_start(); в первой строке страницы, и это может вызвать некоторые проблемы.

session_start();
include_once("php_includes/check_login_status.php");
  • 0
    Я пытался, чтобы он возвращался с «Форма отправки пропускает значения», но я ничего не нажимал и не вводил данные @robert
  • 0
    смотреть w3schools
Показать ещё 3 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню