Skip to content
Advertisement

I’m trying to get a single value (an email address) from a html input to mysql using php

$host = "localhost";
$dbname = "";
$username = "";
$password = "";
$db = mysql_connect($host, $username, $password);
        
  if (mysql_error() > "") print mysql_error() . "<br>";
  mysql_select_db($dbname, $db);
  if (mysql_error() > "") print mysql_error() . "<br>";

  $email = $_POST["email"];
  // Inserting these values into the MySQL table
  // we created above
  $query = "INSERT INTO Emails-prelaunch (Email) VALUES (" . $email . "')";
  $result = mysql_query($query);
  // mysql_query() is a PHP function for executing
  // MySQL queries
  echo "<p>Thank you for entering an email!</p>";

This is what’ve done so far but it gives giving me HTTPs 500 error or a syntax error in insert into value line

Advertisement

Answer

During the test phases, you can add the following code to the beginning of the file and find out the reason for the errors.

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement