Jump to content

regarding an SQL query


oha055

Recommended Posts

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! :)

Link to comment
https://forums.phpfreaks.com/topic/248108-regarding-an-sql-query/
Share on other sites

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.