Struggling to see the problem [Solved]

I’m struggling to see the problem at $sql->bind_param(‘i’, $memberid) as I have tried multiple ways to change it…I dont know the problem, also Dataofbirth is actually a typo I made in my database but I kept it.

<?php    
    // attempt to connect to the DB
    $dbconn = mysqli_connect("localhost", "root", "", "gamerental");
    if ($dbconn->connect_error > 0) {
        die('Could not connect: ' . $dbconn->connect_error);
        exit(); 
    }
 

    $memberid = 0;
    if (isset($_GET['memberid']))
        $memberid = $_GET['memberid'];
    
    if ($memberid == 0)
    {
        $redirect = "location: http://localhost/gamerental/customers";
        header($redirect);
    }

    
    $sql = $dbconn->prepare("SELECT MemberID as memberid,
									Title as title,
                                    Forename as forename, 
									Surname as surname,
                                    Address1 as address1, 
                                    Address2 as address2, 
									Postcode as postcode,
									Telephone as telephone,
									Email as email,
									DataOfBirth as dateofbirth,
									Gender as gender,								
                                    where MemberID = ?");
    $sql->bind_param('i', $memberid);	
    // execute the query 
    $sql->execute(); 
    
    // we have the data, bind the fields
    $sql->bind_result($memberid, $title, $forename, $surname, $address1, $address2, $postcode, $telephone, $email, $dateofbirth, $gender);
    $sql->store_result();
    $sql->fetch();

  
    //close connection
    mysqli_close($dbconn);
?>

What error messages are you getting?

How are you handling errors? I see no try/catch

You know, you can always check $sql->error to see what it is complaining about. I suspect that either $memberid is not what you expect it to be, the value is out of range for what you have setup in the database or there is a type mismatch. This will account for 98% of the things that go wrong in statements like this.

This is the error I have been getting.

I will look into it!

Your query doesnt tell the database what table to query…EDIT: or is it MASS joining all those tables???

Either way, there’s an errant comma before the WHERE.

$sql is a bool because your query is invalid.

I’m mainly trying to get one table.

then you need a FROM clause in your query…

SELECT MemberID as memberid,
	   Title as title,
	   Forename as forename, 
	   Surname as surname,
	   Address1 as address1, 
	   Address2 as address2, 
	   Postcode as postcode,
	   Telephone as telephone,
	   Email as email,
	   DataOfBirth as dateofbirth,
	   Gender as gender
FROM   YourTableNameHere								
WHERE  MemberID = ?

(But brownie points for not doing SELECT *)

2 Likes

Thank youuu! I got it working now

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.