0

I am self-learning MySQL and PHP, so please bear with me. I am trying to set up a DB with values being input through a PHP form. I am following along in a book, but cannot find why I am getting the error:

Error Connecting to MySQL server.

I am running a local host, root username, no password, and table called alien_abductions.

$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_happened = $_POST['whenithappened'];
$how_long_gone = $_POST['howlongwereyougone'];
$howmany = $_POST['howmany'];
$description = $_POST['description'];
$whattheydid = $_POST['whattheydid'];           
$fangspotted = $_POST['fangspotted'];
$email = $_POST['email'];

$dbc = mysqli_connect('localhost', 'root', '', 'up_amd_running')
or die('Error connecting to MySQL server');

$query = "INSERT INTO alien_abductions (first_name, last_name, " .
"when_happened, how_long_gone, howmany, description, " .
"whattheydid, fangspotted, email " .
"VALUES ('$first_name', '$last_name', 
'$when_happened','$how_long_gone', '$howmany', '$description', 
'$whattheydid', `'$fangspotted', '$email')";

echo $query;

$result = mysqli_query($dbc, $query)
or die('Error querying database');

mysqli_close($dbc);
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • 1
    use `$dbc = mysqli_connect('localhost', 'root', '', 'up_amd_running') or die(mysqli_connect_error());` and check the real error – Alive to die - Anant Apr 01 '16 at 17:53
  • 1
    Maybe a spell mistake (up_amd_running), maybe this should be up_and_running instead ? – Jesper Apr 01 '16 at 17:55
  • I found the typo the connect command, but that didnt make a difference – Mike Crowe Apr 01 '16 at 17:59
  • Try , $con = mysqli_connect("localhost","root","",'up_amd_running') or die("Error " . mysqli_error($con)); To Get Real Error! Or if db goes wrong check mysqli_select_db($con,"up_amd_running") or die ("no database"); – Shashank Shah Apr 01 '16 at 18:01
  • @Anant, I inserted that command and still came back with the generic error. – Mike Crowe Apr 01 '16 at 18:03
  • @Anant Should work with your given function as then mysqli_connect_error() function returns the error description from the last connection error. – Shashank Shah Apr 01 '16 at 18:05
  • `I inserted that command and still came back with the generic error.`? what generic error? `Error Connecting to MySQL server.` no its not possible at all – Alive to die - Anant Apr 01 '16 at 18:06
  • 1
    Look this problem is impossible to guess and debug remotely, you obviously have a typo or mismatch somewhere. See also [Reference - What does this error mean in PHP?](http://stackoverflow.com/a/32681786) – mario Apr 01 '16 at 18:07
  • do you mean `up_and_running` rather than: `up_amd_running` - yes, they are different: see '_and_' vs '_amd_'. _N_ not _M_? Please tell me you copied and pasted the actual code that you use? – Ryan Vincent Apr 01 '16 at 18:18

0 Answers0