简体   繁体   中英

Retrieving data from SQL on PHP and showing it on 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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM