duanlisha2335 2015-10-27 00:48
浏览 69

从PHP上的SQL中检索数据并在HTML上显示它

I have a little problem with HTML and SQL.

I am in a login session, I am saving some user info via SQL, and the function saveProfile works fine.

What I want to do though, is that when the form below submits, it runs the database updating function, but also inserts the newly registered string submitted by the form right there where the form was.

For instance, if the user submits www.google.com, I would like the updateProfile function to go get the newly submitted www.google.com from somewhere (I've tried getting it directly from

$x = $_POST["fbProfile"] 

but can't manage to retrieve that value) and insert it back there. Is there any way to do this? Thank you very much

<?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>
  • 写回答

1条回答 默认 最新

  • doushi4864 2015-10-27 01:02
    关注

    Follow my firstgoogled example.

    Idea is to post form via ajax and return needed value from php script. It will be handled in ajax succes function.

    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线