oha055 Posted September 29, 2011 Share Posted September 29, 2011 Hi! I am new to PHP, and have got a problem when trying to insert some info into an sql table. $cat = 'architecture'; $fName = basename($_FILES['uploadedFile']['name']); // filename from image located locally on computer $capt = 'cool image'; require_once('includes/connection.inc.php'); $conn = dbConnect('write'); $sql = 'INSERT INTO images (category, filename, caption) VALUES ("'.$cat.', '.$fName.', '.$capt.'")'; $stmt = $conn->stmt_init(); $stmt = $conn->prepare($sql); $stmt->execute(); This is the error I'm getting: "Fatal error: Call to a member function execute() on a non-object in C:\xampp\htdocs\photoblog\upload.php on line 23" Must be something wrong with the SQL statement, I guess... Any help is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/248108-regarding-an-sql-query/ Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 The first issue is your SQL query, it is wrapping all the values into a single string. $sql = 'INSERT INTO images (category, filename, caption) VALUES ("'.$cat.'", "'.$fName.'", "'.$capt.'")'; The error you are getting is because the variable, $stmt, does not have a function called execute(); Without knowing what the $conn class is or what is contained in $stmt, I will be only guessing. Try $conn->execute() instead (again, this is only a guess) Quote Link to comment https://forums.phpfreaks.com/topic/248108-regarding-an-sql-query/#findComment-1274022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.