質問

I am trying to create a login page so that certain users within our organization will have access to a form with sensitive information. I decided to use PHP and MySQL to do this and believe I am very close, but am having issues getting the two to connect to one another. I am using WAMP server so I have a localhost setup.

Here is my very basic html form:

<form method="post" action="addemail.php">
   <label for="firstname">First Name:</label>
   <input type="text" id="firstname" name="firstname" /> <br/>
   <label for="lastname">Last Name:</label>
   <input type="text" id="lastname" name="lastname" /> <br/>
   <label for="email">Email:</label>
   <input type="text" id="email" name="email" /> <br/>
   <input type="submit" value="submit" name="submit"/>
</form>

On my PHP form, I have this:

$dbc = mysqli_connect('localhost', 'root', 'password', 'leadmen') 
or die('Error connection to MySQL server.');

$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];

$query ="INSERT INTO leadmen_usernames (first_name, last_name, email)" .
"VALUES ('$first_name', '$last_name', '$email')";

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

echo 'Username Added.';

mysqli_close($dbc);

I don't know too much about these technologies but believe the problem lies either within my connection info to $dbc = mysqli_connect, or maybe there's an error with mysqli vs mysql?

Not sure if this matters, but I used phpmyadmin to create the table.

正しい解決策はありません

他のヒント

If you see just the PHP code you probably forgot the opening PHP tag before you start to write actual PHP code.

<?php
$dbc = mysqli_connect('localhost', 'root', 'password', 'leadmen') 
or die('Error connection to MySQL server.');

$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];

$query ="INSERT INTO leadmen_usernames (first_name, last_name, email)" .
"VALUES ('$first_name', '$last_name', '$email')";

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

echo 'Username Added.';

mysqli_close($dbc);

?>

You can close it again with '?>'

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top