Hello Everyone,
I new to PHP and facing an issue that am close to quitting learning. I have been looking for a solution for days, hoping that i will find it here
Am using MAMP and having a problem connecting to the database. I made sure that there is no problem with connecting to mysql using the following code;
<?php DEFINE ('DB_USER', 'root'); DEFINE ('DB_PSWD','root'); DEFINE ('DB_HOST','localhost'); DEFINE ('DB_NAME', 'alienabduction'); $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME); if(!$dbcon) { die('Could Not Connect'); } echo 'Connected Successfully'; mysql_close($dbcon); ?>when putting the url, i see “Connected Successfully”, this means that the connection is good. However when i use the following code, nothing happens, what could be wrong?
<?php $first_name = $_POST['firstname']; $last_name = $_POST['lastname']; $when_it_happened = $_POST['whenithappened']; $how_long = $_POST['howlong']; $how_many = $_POST['howmany']; $alien_description = $_POST['aliendescription']; $what_they_did = $_POST['whattheydid']; $fang_spotted = $_POST['fangspotted']; $email = $_POST['email']; $other = $_POST['other']; $dbc = mysqli_connect ('localhost', 'root', 'root', 'alienabduction') or die ('Error connecting to MySQL Server.'); $query = "INSERT INTO aliens_abduction (first_name, last_name, " . "when_it_happened, how_long, how_many, alien_description, " . "what_they_did, fang_spotted, other, email) " . "VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " . "'$alien_description', '$what_they_did', '$fang_spotted', '$other', " . "'email')"; $result = mysqli_query($dbc, $query) of die ('Error querying database.'); mysqli_close($dbc); echo 'Thanks for submitting the form.'; echo 'You were abducted on' . $when_it_happened; echo ' and you were gone for ' . $how_long . '
'; echo 'Number if Aliens: ' . $how_many . '
'; echo 'Describe them: ' . $alien_description . '
'; echo 'The aliens did this: ' . $they_did . '
'; echo 'Was Fang there? ' . $fang_spotted . '
'; echo 'Other Comments: ' . $other . '
'; echo 'Your email address is ' .$email . '
'; echo 'Regards ' .$first_name.' '.$last_name'; ?>
I greatly appreciate your help
thanks