0

I'm trying to inert into some table, and i get the genral error. Here's my code below.

NOTE: I used this very connection on another update query and it works fine.

Another thing, What's the difference between bindParam() and bindValue() ?

$query = $dbh->query("INSERT INTO music SET
                      uid = ?,  title = ?,
                      album = ?, artist = ?,
                      year = ?, genre = ?,
                      albumart = ?, audio = ?,
                      time = ?, perms = ?
 ");    


$query->bindParam(1, $uid);
$query->bindParam(2, $title);
$query->bindParam(3, $album);
$query->bindParam(4, $artist);
$query->bindParam(5, $year);
$query->bindParam(6, $genre);
$query->bindParam(7, $art);
$query->bindParam(8, $song);
$query->bindParam(9, now());
$query->bindParam(10, $download);
$query->execute();

$check_exc = $query->execute();

if ($check_exc) {
    $new_id = $dbh->lastInsertId('sid');

Thanks.

user3109875
  • 828
  • 12
  • 35

1 Answers1

0
  1. Use prepare instead of query call.
  2. If it is PDO, use PDO error handler and not the mysqli one.
  3. For differences between bindParam and bindValue, a previous duplicate exists.
$query = $dbh->prepare("INSERT INTO music SET
                      uid = ?,  title = ?,
                      album = ?, artist = ?,
                      year = ?, genre = ?,
                      albumart = ?, audio = ?,
                      time = ?, perms = ?");
if( !$query ) {
    die( print_r($dbh->errorInfo()) );
}
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • Ok this is good that for that prepare correction, i ddnt remove it yet, i want to try and get the right error from that instead of the general one. I'll accept this answer. – user3109875 Aug 07 '14 at 07:51
  • i didn't know this is also a valid mysql insert syntax, i though this format is only allowed: `INSERT INTO tbl_name (col1,col2) VALUES(?, ?)` – Kevin Aug 07 '14 at 07:54
  • @user3109875 maybe for some fuzzy users haha, no prob for me, every one makes mistakes at some time. my votes are exhausted anyway – Kevin Aug 07 '14 at 08:00