-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax_userform.php
62 lines (62 loc) · 2.74 KB
/
ajax_userform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php include('includes/db.php') ?>
<?php
if(isset($_POST['name'])) {
$result = mysql_query("UPDATE users SET name = '" . $_POST['name'] . "', surname='" . $_POST['surname'] . "' WHERE id='" .$_SESSION['User']['id']. "'", $db);
if($result) {
$error['type'] = 'success';
$error['text'] = 'Succefully updated!';
}
} elseif(isset($_POST['password']) && $_POST['password'] != '') {
$passw = sha1($_POST['password'] . $salt);
$passw_sub = sha1($_POST['password_submit'] . $salt);
if ($passw != $passw_sub) {
$error['type'] = 'error';
$error['text'] = 'Passwords do not match!';
} else {
$result = mysql_query("UPDATE users SET password = '" . $passw . "' WHERE id='" .$_SESSION['User']['id']. "'", $db);
if($result) {
$error['type'] = 'success';
$error['text'] = 'Succefully updated!';
}
}
}
$result = mysql_query("SELECT * FROM users WHERE id = '" . $_SESSION['User']['id'] . "'", $db);
$user = mysql_fetch_array($result, MYSQL_ASSOC);
?>
<div id="user-info-form">
<?php if (isset($error)): ?>
<div class="message <?php echo $error['type'] ?>"><span><?php echo $error['text'] ?></span></div>
<?php endif; ?>
<form action="<?php echo $baseUrl ?>user.php" method="POST" id="user-form-data">
<div class="fieldset">
<span class="fieldsetlabel">Change main information</span>
<div class="input">
<label>Name</label>
<input type="text" name="name" value="<?php echo $user['name']?>" class="required"/>
</div>
<div class="input">
<label>Surname</label>
<input type="text" name="surname" value="<?php echo $user['surname']?>" class="required"/>
</div>
<div class="submitter">
<input type="submit" value="Submit" onclick="sendAjaxUserData(); return false; " id="submit"/>
</div>
</div>
</form>
<form action="<?php echo $baseUrl ?>user.php" method="POST" id="user-password">
<div class="fieldset">
<span class="fieldsetlabel">Change password</span>
<div class="input">
<label>Password</label>
<input type="password" name="password" class="required"/>
</div>
<div class="input">
<label>Repeat password</label>
<input type="password" name="password_submit" class="required"/>
</div>
<div class="submitter">
<input type="submit" value="Submit" onclick="sendAjaxUserPassword(); return false;" id="submit"/>
</div>
</div>
</form>
</div>