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

Issue

$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

Solution

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

Answered By – emrez

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published