Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql value to html form
    text
    copied!<p>on my website i got a firebase chat running with username + PIN authentication required after logging in to the site and opening the chat box, (here is the most important three tags in this post:</p> <pre><code> &lt;div id='messagesDiv'&gt;&lt;/div&gt; &lt;input type='hidden' id='nameInput' value=''&gt; &lt;input type='text' id='messageInput' placeholder='Message'&gt; </code></pre> <p>) i want the <code>id='nameInput'</code> value to be the username in the sql database. the sql structure is</p> <pre><code>Database: "xxxx_usr" User: "xxxx_usr" Host: "Localhost" Table: "Users" Table; Users: ------------------------------ id | username | password | 1 | Name | ****** | 2 | Name2 | ****** | ------------------------------ </code></pre> <p>and the end of the login script is</p> <pre><code> session_register("myusername"); session_register("mypassword"); header("location:sucsess.html"); </code></pre> <p>so is there any way to use this</p> <pre><code> session.register("myusername") </code></pre> <p>to change</p> <pre><code> &lt;input type='hidden' id='nameInput' value=''&gt; </code></pre> <p>value to the php registered username two pages earlier let's say Name so all chat messages the logged in user will send comes from Name.</p> <p>and what should the complete controll.php be? now it looks like</p> <p>after suggested edits it looks like</p> <pre><code>&lt;?php $host="localhost"; // Host name $username="*******_usr"; // Mysql username $password="*******"; // Mysql password $db_name="*******_usr"; // Database name $tbl_name="Users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['username']; $mypassword=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success. if (!isset ($_SESSION)) session_start(); $_SESSION["myusername"] = $username; $_SESSION["mypassword"] = $password; header("Location:sucsess.html"); } else { echo "Wrong Username or Password"; } ?&gt; </code></pre> <p>becuase after the edits i can accsess sucsess.html without logging in or may it be the logout code that is wrong?</p> <pre><code>&lt;?php session_destroy(); ?&lt; </code></pre> <p>or the code that redirects non authhorisised users?</p> <pre><code>&lt;?php session_start(); if(!session_is_registred(myusername)) { header("Location:index.html") } ?&gt; </code></pre> <p>Thank you for your answer</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload