0

I am trying to fetch a value from one of my tables, however it doesn't appear to be retrieving it as when I echo the variable nothing is displayed.

Here is my code

<?php
$conn = new mysqli('localhost','root','root','neadatabase'); //Creating 
connection to database



//Connection Error Checking
if ($conn->connect_error) 
{
    die("Connection Failed: " . $conn->connect_error);
}

echo ("Connection Successful");

//selecting bookings
$sqlSelectBookings = "
    SELECT ActivID, DateRequired, TimeRequired
    FROM activbooking
    WHERE ActivID = '$_POST[ActivID]' AND DateRequired = 
   '$_POST[DateRequired]' AND '$_POST[DateRequired]' AND 'TimeRequired = ' 
   $_POST[TimeRequired]'
";

$sqlSelectBookings = $conn->que($sqlSelectBookings);

//getting member limit
$sqlGetMemberLimit = "
    SELECT memberLimit
    FROM activity
    WHERE activID = '$_POST[ActivID]'
";

$sqlGetMemberLimit = ($conn->query($sqlGetMemberLimit)-
>fetchObject(memberLimit));

echo $sqlGetMemberLimit;

Any ideas?

This is what happens when I run the page

Thanks

  • 1
    Your code is vulnerable to SQL injection attacks. You should use [mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) or [PDO](http://php.net/manual/en/pdo.prepared-statements.php) prepared statements as described in [this post](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – Alex Howansky Apr 05 '17 at 15:19
  • beside what @Alex says, have you checked value of 'ActivID' before the query ? where does it come from, and how did it get there ? – OldPadawan Apr 05 '17 at 15:23
  • Ok, i've added the rest of my code - I wasn't fully sure what you meant @OldPadawan – Jamie Blacknell Apr 05 '17 at 15:29
  • 1st of all : where do $_POST[ActivID] come from ? any form with method=post ? then, on the page -> – OldPadawan Apr 05 '17 at 15:59
  • The ActivID is a field in the Activity table, the user inputs this on the page before using a method=post form. I am selecting the activity record that has the activID of whatever the user inputs. Inside the Activity table there is another field called MemberLimit. I am trying to retrieve this variable, however the user would not know what this value is @OldPadawan – Jamie Blacknell Apr 05 '17 at 16:30
  • ok, seems that it *should not* be empty then, but nevertheless, have you tried and echo'd as stated in the previous comment ? – OldPadawan Apr 05 '17 at 16:33

0 Answers0