0

I am sending the IP into the database by storing $_SERVER(REMOTE_ADDR) into a global variable, but I am having trouble trying to check if the IP of the host exists or not.

Following is the script I am trying to work with.

<?php
    include_once('./db.php');
?>  
<?php
$_SESSION[“sidIP”] = $_SERVER["REMOTE_ADDR"];

$checkIP = mysql_query("SELECT * FROM guardiansInfo WHERE sidIP = '".$_SESSION["sidIP"] . "'");

 if(mysql_numrows($checkIP) > 0) {
  echo 'It exists!';
 } else {
  echo 'It does not exist';
 }

 ?>


<html>
    <body>
        nothing


    </body>
</html>

This currently gives me this error in apache's log:

PHP Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in ... DIRECTORY

What am I doing wrong?

I am a beginner... Go easy on me. '

EDIT: To those people that are here for answers and don't want to deal with idiotic comments: https://ghostbin.com/paste/kxa4v - I am a beginner, something stackoverflow does not have a concept of.

  • 3
    it's the funky quotes and is *off-topic* – Funk Forty Niner Jan 12 '16 at 22:31
  • Put dots to concatenate the strings: `' . $_SESSION["sidIP"] . '` – user4035 Jan 12 '16 at 22:33
  • 2
    The `"` are wrong. Also, don't use "smart" quotes, `$_SESSION[“sidIP”]`. Currently your assignment says this `SELECT * FROM guardiansInfo WHERE sidIP = '$_SESSION[` is a string because of your quote encapsulation. – chris85 Jan 12 '16 at 22:33
  • 3
    Don't use MS Word for development. – AbraCadaver Jan 12 '16 at 22:36
  • @Fred-ii- how is this off-topic if my tag specifically says php and mysql, I will try that user4035. And I will attempt to fix this chris85. Thank you for your replies. I will let you guys know what works. I have spent the past 2 days on this. :| – ShakeSpear94 Jan 12 '16 at 22:37
  • @chris85 i removed smart quotes. error still exists. – ShakeSpear94 Jan 12 '16 at 22:42
  • 1
    That was my second comment. The first being `The " are wrong.`. I expanded on that in the latter part of that comment..."Currently your assignment says this `SELECT * FROM guardiansInfo WHERE sidIP = '$_SESSION[` is a string because of your quote encapsulation". – chris85 Jan 13 '16 at 00:38
  • I actually disagree with the duplicate mark, but there's no point re-opening this question just to close it with a different duplicate. The problem is use of smart quotes; something we have to teach every new developer these days. – Joshua Jan 13 '16 at 03:40

1 Answers1

2

This string literal is incorrectly formed.

Arrays will not automatically expand inside double quotes without help.

$checkIP = mysql_query("SELECT * FROM guardiansInfo WHERE sidIP = '{$_SESSION["sidIP"]}'"); 

Please dont use the mysql_ database extension, it is deprecated (gone for ever in PHP7) Especially if you are just learning PHP, spend your energies learning the PDO or mysqli_ database extensions, and here is some help to decide which to use

Community
  • 1
  • 1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149