Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By following that tutorial your current user id is stored in </p> <pre><code>$_SESSION['user_id'] </code></pre> <p>The tutorial's login functions are <a href="http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL#Create_PHP_Functions" rel="nofollow">here</a></p> <p>You need to add a userid field in you MySQL table called "mytable"</p> <p>then execute an SQL statement like this.</p> <pre><code>$stmt = $mysqli -&gt; prepare('INSERT INTO mytable (category, contents, date, userid) VALUES (?,?,NOW(),?)'); $stmt -&gt; bind_param('ssi', $_POST['category'], $_POST['contents'], $_SESSION['user_id']); $stmt -&gt; execute(); </code></pre> <p><strong>EDIT</strong></p> <p>After reading the tutorial more they cleared the <code>$_SESSION['user_id']</code> when executing <code>login_check($mysqli)</code> so before you call that insert</p> <pre><code>$userId = $_SESSION['user_id']; </code></pre> <p>Your code should be like this</p> <pre><code>&lt;?php include 'db_connect.php'; include 'functions.php'; sec_session_start(); $userId = $_SESSION['user_id']; if(login_check($mysqli) == true) { //Connecting to sql db. $connect=mysqli_connect("localhost","mydbusername","mydbpass","mysqldb"); header("Location: http://mysite.com/1.php"); if (mysqli_connect_errno()) { echo "Fail"; } else { echo "Success"; } //Sending form data to sql db. $stmt = $mysqli -&gt; prepare('INSERT INTO mytable (category, contents, date, userid) VALUES (?,?,NOW(),?)'); $stmt -&gt; bind_param('ssi', $_POST['category'], $_POST['contents'], $userId); $stmt -&gt; execute(); $stmt -&gt; close(); } else { echo 'Access denied. &lt;br/&gt;'; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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