Connection to Database

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

i have checked your code and found that you have successfully connected with the mysqli and there is no insertion error and all that type error the errors are only with the displaying of the messages like in the last line you have written code like this

echo ‘Regards ’ .$first_name.’ ‘.$last_name’;

which is written like this

echo ‘Regards ’ .$first_name. $last_name’;

check this in you code and let me know if you have any other problem in this

Sponsor our Newsletter | Privacy Policy | Terms of Service