使用PHP MySql创建更新用户配置文件页面

时间:2014-02-16 11:19:39

标签: javascript php html css

我已经设法继续我的用户更新页面,这一切似乎都很好,我点击了登录用户的当前详细信息,当我点击提交它说提交成功,然后我坚持这个页面无法返回,我不知道它是否有效,无法看到任何错误消息或任何我能看到的消息。

我对编码很新,很抱歉,如果我错过任何愚蠢的错误......有人帮我请....

这是我的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's files(pics, MP3s, etc.)
    if (!file_exists("user/$u")) {
        mkdir("user/$u", 0755);
    }
    // Email the user their activation link
    $to = "$e";                          
    $from = "k1003140@kingston.ac.uk";
    $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>

2 个答案:

答案 0 :(得分:0)

我不能写评论所以我会写在这里 你应该使用session_start();在页面的第一行,这可能会导致一些问题尝试

session_start();
include_once("php_includes/check_login_status.php");

答案 1 :(得分:0)

我可以看到你在你的ajax中做了一个POST,但是在你的php中对GET作出反应。

尝试改变:

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

为:

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

或:

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