stack_Ptr
stack_Ptr

Reputation: 23

Simple MYSQL insert statement not working, what am i NOT seeing

This is what I currently have, super basic. Still cant get it working :/

 $connection = mysql_connect("localhost","root","")
    or die ("Couldn't connect to server");
 $db = mysql_select_db("streetRider",$connection)
    or die ("Couldn't select database");




 $result = mysql_query(sprintf("INSERT INTO video(id, parent_id, video, coverImage, 
    ts_created, is_void) VALUES('%s','%s','%s', '%s', '%s','%s')", $unique_id,           $parent_id,$videoDirectory,$imageDirectory,  $ts_created,  $is_void));

 What am i Missing???? :(

OK Guys so if one of my variables I'm storing is equal to this it works:

    $videoDirectory = 'userVideos/'.$unique_id;

When my variable is equal to this, the insert FAILS: $videoDirectory = 'userVideos/'.$unique_id.'.mp4';

Its really puzzling and frustrating, but thats what I figured out.video is datatype varchar(50).

Upvotes: 0

Views: 90

Answers (2)

M Khalid Junaid
M Khalid Junaid

Reputation: 64476

You have assigned the columns with %s but your query function does have the sprintf() call in it? Try this

$result = mysql_query(sprintf("INSERT INTO video(id, parent_id, video, coverImage, 
ts_created, is_void) 
VALUES('%s','%s','%s', '%s', '%s','%s')",
$unique_id, $parent_id,$videoDirectory,$imageDirectory,  $ts_created,  $is_void));

sprintf manual


Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Upvotes: 1

echo_Me
echo_Me

Reputation: 37233

i dont know you are using prepared statment or mysql anyway if you are tagged mysql then try this

    $result = mysql_query("INSERT INTO video(id, parent_id, video, coverImage, ts_created, is_void) VALUES ($unique_id, $parent_id,$videoDirectory,$imageDirectory,  $ts_created,  $is_void ) ")

Upvotes: 0

Related Questions