0

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

stack_Ptr
  • 23
  • 1
  • 8
  • What is the error message generated by MySQL? – Hidde Jul 21 '13 at 16:56
  • 1
    What is "query"? A function that you wrote yourself? How does it handle errors? – Joni Jul 21 '13 at 16:56
  • A function I found online, and works for other inserts. It only returns this if the query failed('error'=>'Database error'); – stack_Ptr Jul 21 '13 at 17:04
  • What language are you working in? I assume PHP because of the dollar signs, but that definitely has a native mysql function, which you should be able to get the error from – RT_34 Jul 21 '13 at 17:08
  • 1
    I think I will just not use that function and instead write an insert statement see what happens – stack_Ptr Jul 21 '13 at 17:09
  • you missed `sprintf()` call – M Khalid Junaid Jul 21 '13 at 17:15
  • I started using native mysql function, I still cant get it working :( – stack_Ptr Jul 21 '13 at 19:37
  • `mysql_*()` functions are deprecated. Better use `mysqli_()` or PDO, and use their prepared statement stuff. If you can't, use at least `mysql_real_escape_string()` in order to sanitize your input. – glglgl Jul 21 '13 at 20:04
  • What does "not working" mean? It throws an error? We need to see the error message. Or do you mean it has unexpected behavior? What did you expect? What is it doing instead? Why do you think what it is doing is not what you expect? – Dour High Arch Jul 21 '13 at 22:51
  • Dour, I edited my question. Its really strange whats going on. – stack_Ptr Jul 21 '13 at 23:38

2 Answers2

1

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
0

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 ) ")
echo_Me
  • 37,078
  • 5
  • 58
  • 78