Im trying to enter certain values to a db table and although its going through, not all
the values are being populated.
im going to skip some parts because again, its not that im not connecting etc, the problem is that although i am getting through and communicating with the db, on info upload, only certain fields are being populated.
so for example,
My “username / password ” fields have the same values within the db so im not sure
why one field is being populated and the other is not…
but here is some code..theres alot of it so im gonna copy/paste the important parts
the html for example is
<input type="text" name="uname" id="uname" value="Enter Desired Username"/><br/>
<input type="text" name="upass" id="upass" value="Enter Desired Password"/><br/>
etc...you know same old html
the php
the connection works etc..
the variables
$c2d = "the db connection here";
$userName = mysql_real_escape_string($_POST['uname']);
$userPass = mysql_real_escape_string($_POST['upass']);
//here i set up all my vars but this is the problematic one.
$addDetails2DbQueryS = "INSERT INTO accounts (appUname, appUpass)VALUES('$userName','$userPass')";
$addDetails2DbQueryS = "INSERT INTO accounts (appUname, appUpass) VALUES('$userName','$userPass')";
//perform some checks here like if the account thats being created already exist etc..
and this works as well too blah blah
then when all is good, add the account to the db
to which im using this
$addDetails2DbQuerySDoIt = mysqli_query($c2d, $addDetails2DbQueryS) or die("error [003] could not add acc to db" . mysqli_error);
And whats happening is, The username is logged but the password field is empty
Any ideas what im doing wrong? thanks in advance and
ANY help i gladly and humbly appreciate. Thank you
Youre using the wrong escaping function… youre using
mysql_real_escape_stringfrom theext/mysqlextension, but youre actually using theMySQLiextension to do youre insert, so you should be using its version of the functionmysqli_real_escape_string.Use one DB driver or the other, not both 🙂
I would actually expect you to get
falsefor both values because if you havent established a db connection withmysql_connectthe callingmysql_real_escape_stringshould return false and generate a waring:If you have estabished a
mysql_connect()connection then i would expect yourmysqli_query()to fail because you never established a connection withmysqli_connect().I think once you pick one of the 3 DB drivers and only use the classes/functions of ONE of those most of your issues are going to disapear:
PDO(my favorite, elegant, pretty easy to use, easier to port code to a diff. db if needed)MySQLi(offers the best range of MySQL specific features, but is clunkier to use)ext/mysql(avoid like the plague when possible)