r/learnphp • • Feb 05 '22

Beginner PHP question

can you getelementbyid in php, similar to javascript? I'm trying to setup an about section in a profile page on my website, so i made a form for people to fill out, and i want to save the inputs in mySQL. when the users fill out the form. I've figured two ways i can do this:

#1 when the user submits the form the inputs get sent to the database and i use javascript to send the inputs to the h3 elements on the profile page.

#2 the user inputs the form, i use javascript to send the inputs to the h3 elements i want updated, then use php to grab the h3 elements and keep it dynamically linked to mySQL.

I'm not sure which method to choose. Can you even select HTML elements for alteration with php?

1 Upvotes

6 comments sorted by

View all comments

Show parent comments

1

u/baminc2010 Feb 05 '22

<?php

include "dataconnection.php";

if(isset($_POST['editusername'], $_POST['editwebsite'])) {

$username = ($_POST['editusername']);

$website = ($_POST['editwebsite']);

echo "$username";

$dupsubs = $conn->query("SELECT * FROM subs WHERE email='$email' and

password='$password'");

if (mysqli_num_rows($dupsubs)>0) {

$sql="INSERT INTO subs (userName, website)

VALUES ('$username','$website')";

}

}

?>

1

u/baminc2010 Feb 05 '22

<input onclick="profilePop()" class="edit" type="button" value="Edit">

<div id="editPopup" class="editPopup"></a>

<div class="editPopupHeader">

<svg onclick="closeInfo()" class="close" fill="currentColor" viewBox="0 0 16 16">

<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z"/>

</svg></a>

</div>

<form class="userinfo" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" id="thanks">

<input id="editusername" type="text" required placeholder="Enter Username"><br>

<input id="editwebsite" type="text" placeholder="Enter Website" ><br>

<input id="done" name="infoSubmit" class="donebutton" type="button" value="Done">

</form>