Problem with Insert using mysql_query()

Asked

Viewed 674 times

0

I’m working on an old system, in which makes the connection to the bank still with mysql_query.

I used very little mysql_query and the last time I used it a long time ago, I’m more used to PDO.

I’m trying to give a insert in the bank, but the function mysql_query is returning false and I cannot identify the error. I have already looked at the documentation relating to mysql_query and saw nothing wrong in my code. Someone could help me?

Follows the code:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $nomeVideo    = $_POST['nomeVideo'];
  $urlVideo     = $_POST['urlVideo'];
  $dataPostagem = date('d/m/Y');

  $sql = "INSERT into video (nomeVideo, urlVideo, dataPostagem)
          VALUES($nomeVideo, $urlVideo, $dataPostagem)";

  $insert = mysql_query($sql);
  var_dump($insert); exit;

  if ($insert) {
    header('Location: video.php');
  } else {
    header('Location: video.php?return=2');
  }
}

I even changed in the BD the field dataPostagem of DATE for VARCHAR thinking this was it but it didn’t solve.

1 answer

2


I think the quotation marks are missing string and at the date:

$sql = "INSERT into video (nomeVideo, urlVideo, dataPostagem)
        VALUES('$nomeVideo', '$urlVideo', '$dataPostagem')";
  • -_-' That’s right @Wendel Rodrigues. Thank you very much, I didn’t know that I should have the single quotes in the variables.

  • 1

    To string should always use quotes in SQL. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.