我对HTML和SQL有一点问题。
我在登录会话中,我通过SQL保存一些用户信息,函数saveProfile
正常工作。
我想要做的是,当下面的表单提交时,它会运行数据库更新功能,但也会将表单提交的新注册字符串插入到表单所在的位置。
例如,如果用户提交www.google.com
,我希望updateProfile函数从某个地方获取新提交的www.google.com
(我试过直接从
$x = $_POST["fbProfile"]
但无法设法检索该值)并将其插回那里。有没有办法做到这一点?非常感谢你
<?php
session_start();
if(!$_SESSION['loggedin'])
{
header("location:index.html?problem=notLoggedin");
exit;
}
$name = $_SESSION['name'];
$surname = $_SESSION['surname'];
$email = $_SESSION['email'];
$profile = $_SESSION['profile'];
$course1 = $_SESSION['course1'];
$course2 = $_SESSION['course2'];
$course3 = $_SESSION['course3'];
$course4 = $_SESSION['course4'];
?>
<!DOCTYPE html>
<html lang="En-US">
<head>
<body>
<div class="container">
<table >
<tr>
<td><p><b>My Facebook profile:</b></td>
<td><p id="editprofile"><?php print($profile); ?></p></td>
<td><p onclick="return editprofilefunction()" id="editprofileblank"><a href>Edit</a></p></td>
</tr>
</table>
</div>
<script>
function editprofilefunction() {
document.getElementById("editprofile").innerHTML = '<form name="emailForm" method="post" onsubmit="return !!(saveProfile() & updateProfile())"><input type="text" name="fbProfile" placeholder="Insert your Facebook URL"/> <input id="submit" type="submit" value="Save"></form>';
document.getElementById("editprofileblank").innerHTML = "";
return false;
}
function saveProfile() {
<?php
$x = $_POST["fbProfile"];
define('DB_NAME', 'DATABASENAME');
define('DB_USER', '1956218_students');
define('DB_PASSWORD', 'Password');
define('DB_HOST','HOST');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
$sql = "UPDATE `DATABASENAME`.`Students` SET `Fbprofile` = '$x' WHERE `Students`.`Email` = '$email' ";
?>
}
function updateProfile() {
document.getElementByID("editprofile") = ********PROFILE STRING I HAVE JUST SAVED***********;
return true;
}
</script>
</div>
</body>
</html>