Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ($_SERVER['REQUEST_METHOD'] == 'POST') //was da form submitted?
- //Let's get the things big brother sent
- $address = $_POST["addy"];
- $name = $_POST["fname"];
- //start mysql thingie
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "contacts";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //your code is actually good, let's keep it
- $sql = "INSERT INTO list ( firstname, lastname, organization, addy, phone1, phone2, email ) VALUES ($fname,'{conn->real_escape_string($_POST["Lastname"] )}','{conn->real_escape_string($_POST["organization"] )}','{conn->real_escape_string($_POST["addy"] )}', '{conn->real_escape_string($_POST["phone1"] )}', '{conn->real_escape_string($_POST["phone1"] )}', '{conn->real_escape_string($_POST["phone2"] )}','{conn->real_escape_string($_POST["email"] )}') ";
- $insert = $mysqli -> query($sql);
- if ($insert){
- echo "Success! Row ID: {mysqli-> insert_id}";
- }else {
- die("Error: {$mysqli->errno} : {$mysqli->error}");
- }
- $conn->close();
- }//closing that if (form submited)
- else {
- //default page - if nothing was submited or it's first access
- ?>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Contact List</title>
- </head>
- <body>
- <form method="post" action="">
- First name:<br>
- <input type="text" name="firstname"><br>
- Last name:<br>
- <input type="text" name="lastname"><br>
- Organization:<br>
- <input type="text" name="organization"><br>
- Address:<br>
- <input type="text" name="addy"><br>
- Phone 1:<br>
- <input type="text" name="phone1"><br>
- Phone 2:<br>
- <input type="text" name="phone2"><br>
- Email:<br>
- <input type="text" name="email"><br><br>
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
- <? } >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement