1

Hey guys I'm still learning PHP and need help. I have 3 files that require a database.php file to connect to MySQL. when I execute the files only two of them work. For the last file, I get an HTTP error 500.

    <?php

      require( 'database.php');  

   // inserting information from the form into the database
   $sql = ("INSERT INTO guestlist (firstName, lastName, phoneNumber,guests,event)
      VALUES (?,?,?,?,?)"); 
      // values are prepared to bind
    $stmt = mysqli_prepare($con,$sql);

    mysqli_stmt_bind_param($stmt,"sssss",$_POST['first_name'],$_POST['last_name'], $_POST['phonenumber'], $_POST['guest'], $_POST['event']);

  $stmt->execute();




   if (!$stmt)// Was not updated
   {
       // shows error


           echo("There was an error with your RSVP.  Please try again.");

           mysqli_stmt_close($stmt);
   }

   else //Was updated
   {
           echo("Your RSVP has been completed.");
   }

   //End database connection   
  mysqli_close($con);

   ?>

this is my database file that was provided by my professor

    <?php

    $myHost = "localhost"; // localhost, do not change this string
    $myUserName = "cmorales";   // CHANGE TO YOUR USERNAME
    $myPassword = "";   // CHANGE TO YOUR PASSWORD
    $myDataBaseName = "cmorales_project"; // CHANGE USERNAME 
       username_project

   $con = mysqli_connect( "$myHost", "$myUserName", "$myPassword", 
       "$myDataBaseName" );

   if( !$con ) // == null if creation of connection object failed
     {
  // report the error to the user, then exit program
     die("connection object not created: ".mysqli_error($con));
     }

   if( mysqli_connect_errno() )  // returns false if no error occurred
     {
 // report the error to the user, then exit program
die("Connect failed: ".mysqli_connect_errno()." : ". 
mysqli_connect_error());
   }
  ?>
ceemorales
  • 11
  • 2

1 Answers1

1

Because there is a syntax error in your database.php

Cause : No semicolon end of username_project 7th line.

Solution:

remove undefined constant username_project on the 7th line.

as @Antonio Teh Sumtin mentioned in the comments, Always check the error log or enable the display error during development.

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71
  • I don't have line 7 in my file, that's part of the comment in line 6, it must have moved to line 7 when I copied and pasted the code on here – ceemorales Jun 06 '18 at 07:41
  • Then no syntax error on your code. use this to see exact error. https://stackoverflow.com/a/47641796/2975952 – Thamaraiselvam Jun 06 '18 at 07:42