php - I'm making a newsletter for a website and it does not connect to the server -
i'm making newsletter promo website , doesn't work me, simple form, register.php , connect.php connect database php. code looks this:
the connect.php
<?php $servername = "localhost"; $username = "root"; $password = "laidinis69"; $database = "promo"; $con = mysqli_connect($servername, $username, $password, $database); ?>
the register.php
<?php include('connect.php'); $form_name = $_post['name']; $form_email = $_post['email']; $query = 'select * subscribers name="' .$form_name. '";'; if($result = mysqli_query($con, $query)) { if(mysqli_num_rows($result) == 0) { $query = 'insert subscribers (name, email) values("'.$form_name.'","'.$form_email.'")'; if(mysqli_query($con, $query)) { echo "registered"; } } else { echo "already exists"; } } header('location: register.php'); ?>
the form on index.html file:
<form action="register.php" method="post"> name: <input type="text" name="name"><br> email: <input type="text" name="email"><br> <input type="submit" name="register" value="subscribe"> </form>
when press on subscribe button, redirects me register.php , not put in data in database.
i believe need try changing line
if($result = mysqli_query($con, $query)) { ...
to this
$result = mysqli_query($con, $query); if(mysqli_num_rows($result) == 0) { $query = 'insert subscribers (name, email) values ("'.$form_name.'","'.$form_email.'")';
and sure delete }
goes if-satement
you'll deleting.