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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.