0

I have already looked at various other SO answers and still cannot get this to work. I know that my summonerid get's through fine as I can echo it back. I also can reach my MySQL table, so it has to be my query syntax.

$query="SELECT FROM UserTable (summonerid) WHERE summonerid='$usersummonerid'";
if(mysql_num_rows($query)<1) 
{
   //register name
} else {
   //name exists already
}

The errors I am getting back


Warning: mysql_query(): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\GVLegends\Scripts\check.php on line 21

Warning: mysql_query(): A link to the server could not be established in C:\xampp\htdocs\GVLegends\Scripts\check.php on line 21

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\GVLegends\Scripts\check.php on line 22

Here is my entire PHP for context (sorry if it seems poorly coded, I am newer to PHP)

<?php
//login details

$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

$username = $_POST['user'];
$userpassword = $_POST['pass'];
$usersummoner = $_POST['summoner'];
$usersummonerid = $_POST['summonerid'];
$useremail = $_POST['email'];

$query="SELECT FROM UserTable (summonerid) WHERE summonerid='$usersummonerid'";
if(mysql_num_rows($query)<1) {
  $sql = "INSERT INTO UserTable (name, password, summonerid, summonername,email)
  VALUES ('$username', '$userpassword', '$usersummonerid', '$usersummoner',$useremail')";
  if ($conn->query($sql) === TRUE) {
    echo '{"success":true}';
  } else {
    echo '{"success":false}';
  }
} else {
  echo '{"success":false}';
}

$conn->close();
?>
Austin
  • 3,010
  • 23
  • 62
  • 97
  • Stop using `mysql_*` function as they are deprecated: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – D4V1D Mar 27 '15 at 14:22
  • try `$query="SELECT summonerid FROM UserTable WHERE summonerid='$usersummonerid'";` – Tamil Selvan C Mar 27 '15 at 14:22

1 Answers1

0
$query="SELECT FROM UserTable (summonerid) WHERE summonerid='$usersummonerid'";
if(mysql_num_rows($query)<1) {...}

Where exactly are you executing this query? Besides the horrendous security issues, all you're doing is defining a string

mysql_num_rows() expects the result of an executed query as its argument, not simply a PHP string value.... you need to execute the query that you have defined in your string to get a result

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • sorry I am new to PHP, it is in a protected Scripts folder. I am doing an AngularJS callback to see if the summoner (name) exists or not. :/ – Austin Mar 27 '15 at 14:25