Question By
Unsolved

Create a PHP Login Script 2015(youtube).

serhiy-the-who

Nov 27th, 2016 01:43 PM

<p>hi there, i have some problems with simple login php script.<br />actually i have problem like this -&nbsp;Notice: Only variables should be passed by reference in D:\X_AMPP\htdocs\www\register.php on line 15.</p> <p>and my code on that lines (line 15 is -&nbsp;<span style="background-color: #272822; color: #f8f8f2; font-family: 'Courier New';">$stmt</span><span style="font-family: 'Courier New'; color: #f92672;">-&gt;</span><span style="font-family: 'Courier New'; color: #a6e22e;">bindParam</span><span style="background-color: #272822; color: #f8f8f2; font-family: 'Courier New';">(</span><span style="font-family: 'Courier New'; color: #e6db74;">':password'</span><span style="background-color: #272822; color: #f8f8f2; font-family: 'Courier New';">, </span><span style="font-family: 'Courier New'; color: #a6e22e;">password_hash</span><span style="background-color: #272822; color: #f8f8f2; font-family: 'Courier New';">($_POST[</span><span style="font-family: 'Courier New'; color: #e6db74;">'password'</span><span style="background-color: #272822; color: #f8f8f2; font-family: 'Courier New';">], PASSWORD_BCRYPT));</span>&nbsp;looks like -</p> <p>&nbsp;</p> <pre style="background-color: #272822; color: #f8f8f2; font-family: 'Courier New'; font-size: 11,3pt;"><!--?php &lt;br ?--><span style="color: #75715e;">//error_reporting(0);<br /></span><span style="color: #75715e;"><br /></span><span style="color: #f92672;">require </span><span style="color: #e6db74;">'database.php'</span>;<br /><br />$message <span style="color: #f92672;">= </span><span style="color: #e6db74;">''</span>;<br /><br /><span style="color: #f92672;">if</span>(<span style="color: #f92672;">!empty</span>($_POST[<span style="color: #e6db74;">'email'</span>]) <span style="color: #f92672;">&amp;&amp; !empty</span>($_POST[<span style="color: #e6db74;">'password'</span>]))<span style="color: #f92672;">:<br /></span><span style="color: #f92672;"><br /></span> <span style="color: #75715e;">//Enter new user into DB!<br /></span> $sql <span style="color: #f92672;">= </span><span style="color: #e6db74;">"INSERT INTO users (email, password) VALUES (</span><span style="color: #fd971f; font-style: italic;">:email</span><span style="color: #e6db74;">, </span><span style="color: #fd971f; font-style: italic;">:password</span><span style="color: #e6db74;">)"</span>;<br /> $stmt <span style="color: #f92672;">= </span>$conn<span style="color: #f92672;">-&gt;</span><span style="color: #a6e22e;">prepare</span>($sql);<br /><br /> $stmt<span style="color: #f92672;">-&gt;</span><span style="color: #a6e22e;">bindParam</span>(<span style="color: #e6db74;">':email'</span>, $_POST[<span style="color: #e6db74;">'email'</span>]);<br /> $stmt<span style="color: #f92672;">-&gt;</span><span style="color: #a6e22e;">bindParam</span>(<span style="color: #e6db74;">':password'</span>, <span style="color: #a6e22e;">password_hash</span>($_POST[<span style="color: #e6db74;">'password'</span>], PASSWORD_BCRYPT));<br /><br /> <span style="color: #f92672;">if</span>($stmt<span style="color: #f92672;">-&gt;</span><span style="color: #a6e22e;">execute</span>())<span style="color: #f92672;">:<br /></span> $message <span style="color: #f92672;">= </span><span style="color: #e6db74;">'Successfully crated new user'</span>;<br /> <span style="color: #f92672;">else:<br /></span> $message <span style="color: #f92672;">= </span><span style="color: #e6db74;">'Sorry there must have been an issue to create an account!'</span>;<br /> <span style="color: #f92672;">endif</span>;<br /><br /><span style="color: #f92672;">endif</span>;<br /><br /><span style="color: #f92672;">?&gt;<br /></span></pre> <p>&nbsp;</p>
serhiy-the-who

Nov 27th, 2016 01:53 PM

<p>alright my bad , already find the answer below :)</p>
mark

Nov 27th, 2016 03:05 PM

<p>To others finding same issue, the solution is simple to change:</p> <pre class="language-php"><code>$stmt-&gt;bindParam(':email', $_POST['email']); $stmt-&gt;bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));</code></pre> <p>to</p> <pre class="language-php"><code>$email = $_POST['email']; $password = password_hash($_POST['password'], PASSWORD_BCRYPT);

$stmt->bindParam(':email', $email); $stmt->bindParam(':password', $password);</code></pre>

mark

Jan 12th, 2017 08:27 AM

<p>Just use PDO. PDO supports multiple drivers, including MySQL.<br />Drivers supported: http://php.net/manual/en/pdo.drivers.php</p>
jake-lower

Jan 22nd, 2019 05:45 AM

Login scripts will always be really had to create from the different parts of the page in the You Tube channels. If problem from the references on the superiorpapers com website only be compact then register will be need only password and username.

anika-digital

Mar 1st, 2019 04:00 PM

I read that Post and got it fine and informative. Please share more like that...Great Article it it's really informative and innovative keep here:<a href="http://www.Anikadigital.com/"> Quality web design & development services london </a> with new updates. Its was really valuable. Thanks a lot.