"hi, I am trying to make one user with username and password to edit the text on a page; I have a database with a table "users" with only one user and a table "save_text" where I save the text; now I am trying to save the text in the page with the next php code; please let me know if it is posible in this way and how ? I cannot save the text on the page untill next modify for example, thanks"
<?php
require_once 'connect.php';
if (isset($_POST['submit'])){
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbname="edit text";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE username='$username' and password='$password'";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$count = mysqli_num_rows($result);
if ($count == 1){
$username = $_POST['username'];
$password = $_POST['password'];
$text = $_POST['text'];
$query = "Insert into save_text (username,password,text) VALUES ('".$username."','".$password."','".$text."')";
$result = mysqli_query($conn, $query);
echo '<div id="section"><section>'.$text.'</section></div>';
}
else {
echo '<div id="section"><section>fail modify text</section></div>';
}
}
?>