Ye its there, I just didn’t add it in sorry.
Ye am using var_dump and its showing the correct value to the variable $username and all looks fine there.
This is it now
<?php
if (isset($_POST["username"]))
{
require_once('config.php');
$connectionInfo = array( "Database"=>$databaseName);
$conn = sqlsrv_connect($hostName , $connectionInfo);
$username = $_POST["username"];
var_dump ("SELECT COUNT(*) AS Counting from Users where Username='$username'");
$query = "SELECT COUNT(*) AS Counting from Users where Username='$username'";
$fathom = $query['Counting'];
echo $fathom;
$res = sqlsrv_query($conn, $query) or die(sqlsrv_errors());
echo $res."lui";
$username_exist = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC);
$rowID=$username_exist[0];
//if returned value is more than 0, username is not available
if($rowID) {
die('<img src="images/not-available.png" />');
} else { ?>
<script>
$('#submitNew').css('visibility', 'visible');
</script>
<?php die('<img src="images/available.png" />');
}
}
?>
$fathom is echoing the letter ‘s’
$res is echoing nothing
it should also give you an “invalid string offset” warning.
multichild:
$res is echoing nothing
$res
is a resource (if it makes it past the die()). and sqlsrv_errors()
either returns NULL (no error) or an array (of errors), not a string.
I don’t understand what you expect to see in $fathom as you haven’t executed the query at that point. $query is just a string, so trying to access it as an indexed array doesn’t seem correct to me.
var_dump($username_exist) would be my next suggestion, see why $rowID is blank.
Well this is my problem, I don’t seem to be able to get anything to echo out after
$res = sqlsrv_query($conn, $query) or die(sqlsrv_errors());
With $fathom, shouldn’t I be able to get the value of count, or am I miles off.
you have to query the database for that. a simple string cannot tell you that.
Have changed it a bit and made a bit of progress but its still not working and am trying to echo out $rowID and again nothing.
<?php
if (isset($_POST["username"]))
{
require_once('config.php');
$connectionInfo = array("UID" => $username, "PWD" => $password, "Database" => $databaseName);
$conn = sqlsrv_connect($hostName, $connectionInfo);
$username = $_POST["username"];
$query = sqlsrv_query($conn,"SELECT COUNT(*) AS Upturn from Users where Username=".$username."");
while ($username_exist = sqlsrv_fetch_array($query)){
$rowID=$username_exist['Upturn'];
echo $rowID;
}
//if returned value is more than 0, username is not available
if($rowID) {
die('<img src="images/not-available.png" />');
} else { echo $rowID."house"; ?>
<script>
$('#submitNew').css('visibility', 'visible');
</script>
<?php die('<img src="images/available.png" />');
}
}
?>
Bing looks like I got it finally
<?php
if (isset($_POST["username"]))
{
require_once('config.php');
$connectionInfo = array("UID" => $username, "PWD" => $password, "Database" => $databaseName);
$conn = sqlsrv_connect($hostName, $connectionInfo);
$username = $_POST["username"];
$query = sqlsrv_query($conn,"SELECT COUNT(*) AS Upturn from Users where Username='".$username."'") or die(sqlsrv_errors());
while ($username_exist = sqlsrv_fetch_array($query)){
$rowID=$username_exist['Upturn'];
}
if($rowID) {
die('<img src="images/not-available.png" />');
} else {
?>
<script>
$('#submitNew').css('visibility', 'visible');
</script>
<?php die('<img src="images/available.png" />');
}
}
?>
Thanks for the help guys
system
Closed
September 23, 2015, 5:55pm
29
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.