php


Why is my sql prepared statement not giving correct responses?


I'm trying to create a login account system for my website and when a user registers, I check if there is already an account in the database. I created a function called 'check_user_exists' and here is the code for that
function check_account_exists($username, $conn){
if($stmt = $conn->prepare("SELECT * FROM users WHERE username=?")){
$stmt->bind_param('s', $username);
$stmt->execute();
echo $stmt->num_rows;
if($stmt->num_rows == 1){
return true;
}else{
return false;
}
}else{
//couldn't prepare statement
return false;
}
}
However when I go run this it returns false every time even when I know that a value in the database already exists. I haven't had any MySQL errors before this but I checked the error log and it doesn't show any errors. I added echo stmt->num_rows; but it always outputs 0. What is the matter?
Ok turns out I need to use $stmt->store_result(); after $stmt->execute(); That was preventing correct responses.

Related Links

Check If Many-to-Many Relationship Exists
dispatch software with inventory of products with variable prices
Database schema for user reviews
Two forms, one PHP page and no action
Laravel schedule command with cron
Best way to use One Note API to GET specific pages in specific section in specific notebook?
use session username to get data from mysql
Not able to get the actual values from SQL result php
Doctrine persist saving in the database without flush
Unable to block error traces in a Symfony 3 controller
IN statment on a MySQL INNER JOIN php pdo
While exporting report in excel using php, it works locally but not on the server?
How to edit the fields in Woocommerce?
PHPDoc Blocks For array keys [duplicate]
Laravel Authentication on Backpaging through History
I'm trying to create an unordered list in php and display it to html file

Categories

HOME
google-chrome
webview
firebase
dotnetnuke
jms
bokeh
bots
semantic-web
tibco
turbojpeg
jint
phpmqtt
mutation-testing
siesta
vimeo
max-msp-jitter
pickle
tfsbuild
psql
deepfreeze
spyder
angular2-highcharts
jitsi
workday
liferay-6.2
websphere-portal
ini
pubxml
webviewclient
python-imageio
basex
acrobat
adapter
laravel-4.2
sfml
tightvnc
progid
osx-lion
nest
cordys-opentext
xvfb
jade4j
uipickerview
rightnow-crm
swift2.3
deployd
image-registration
jgrapht
amazon-elastic-beanstalk
nslayoutconstraint
mobile-angular-ui
case-when
alertify
gmaps.js
msxml
qtextedit
researchkit
livecycle
dmarc
bbc-micro
codecharge
swiffy
textblock
utf-16
polymerfire
i2b2
enunciate
servicestack-bsd
deeplink
bayesglm
arbre
highest
blank-line
jnlp
green-threads
roxygen2
sequence-sql
cache-manifest
text-align
findersync
tkx
lifetime
hp-idol-ondemand
symja
cakephp-2.2
angular-ui-select
full-text-indexing
otl
miglayout
jack
principalcontext
revmob
django-facebook
html-frames
spiral
chefspec
semantic-merge
idispatch
onconfigurationchanged
playorm
arrow
struts2-s2hibernate
kext
outlook-2007-addin
tessellation
rational-unified-process
html-components
iphone-sdk-3.1.3
remote-working

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App