Note that there are some explanatory texts on larger screens.

plurals
  1. POinserting variable into database with php
    primarykey
    data
    text
    <p>I'm editing part of a user login system and I'm very confused on one issue. I'm trying to allow the user to change their username using their email as a reference for the lookup. For some reason I can't get the $email variable to set properly. When I change the variable $email to an address that I know is in my database (meaning I remove $email and change it to an address that exists) the username is properly changed. When I swap it back to $email, nothing happens.</p> <p>The strange part is when I echo $email, the correct email address is displayed. I can't figure out why it won't let me do this despite it being echoed properly. Is it possible to not be a string despite an email address being displayed?</p> <p>I understand about sql injections. I'm just trying to keep the code as simple as possible for now so I can get the functionality working first.</p> <pre><code>&lt;? if (isset($_POST['submit'])) { $email = $user-&gt;get_email($username); $newuser = $_POST['newusername']; $server = 'localhost'; $usern = 'root'; $pass = ''; $connection = mysql_connect($server, $usern, $pass) or die(mysql_error()); mysql_select_db(testdb, $connection) or die(mysql_error()); if(isset($username)) { mysql_query("UPDATE users SET username='$newuser' WHERE email = '$email'") or die(mysql_error()); } } ?&gt; </code></pre> <p>Also, when I change the query statement so that the reference value is the userid, the username is correctly inserted. From this I know that $email isn't being set properly. </p> <pre><code>mysql_query("UPDATE users SET username='$newuser' WHERE userid = '$userid'") or die(mysql_error()); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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