Justafriend Posted January 16, 2017 Share Posted January 16, 2017 I have this code that pulls data from a form and is supposed to check if the neptune and username are inserted 2 times it replies back with an error if not it posts the data to 2 lines with neptune username and email on one line and just email and username on the other The issue is the code i have gives me an error saying unexpected end of file below is my code any help will be appreciated <?php if(isset($_POST['choices']) && !empty($_POST['choices'])){ if($_POST['choices'] == 'four'){ //variables from form entered $username = $_POST['username']; $neptune = $_POST['neptune']; $email = $_POST['useremail']; //connect to the database $dbc = mysqli_connect('localhost', 'root', '', 'happygam_main') or die('Error connecting to MySQL server'); $check=mysqli_query($dbc,"select * from ballot where username='$username' and neptune='$neptune'"); $checkrows=mysqli_num_rows($check); if($checkrows>0) { echo "This combination of neptune and username has already been processed"; } else { //insert results from the form input in 2 rows one with neptune one without $query = "INSERT IGNORE INTO ballot(username, useremail, neptune) VALUES('$username', '$email', '$neptune')"; $query1 = "INSERT IGNORE INTO ballot(username, neptune) VALUES('$username', '$neptune')"; $result = mysqli_query($dbc, $query, $query1) or die('Error querying database.'); mysqli_close($dbc); } } ?> Quote Link to comment Share on other sites More sharing options...
Solution benanamen Posted January 16, 2017 Solution Share Posted January 16, 2017 (edited) You are missing the closing } There are other problems. You need to use prepared statements. You never insert user supplied data directly to the DB. Dont SELECT *. Specify the columns you want. You also do not need to manually close the connection. It closes automatically. It would appear your logic is flawed. You can't throw two query parameters into mysql like that. And don't create variables for no reason. I formatted your code so it is more readable but it still needs fixing aside from the missing bracket I put in. I would recommend you use PDO. https://phpdelusions.net/pdo <?php if (isset($_POST['choices']) && !empty($_POST['choices'])) { if ($_POST['choices'] == 'four') { //variables from form entered $username = $_POST['username']; $neptune = $_POST['neptune']; $email = $_POST['useremail']; //connect to the database $dbc = mysqli_connect('localhost', 'root', '', 'happygam_main') or die('Error connecting to MySQL server'); $check = mysqli_query($dbc, "select * from ballot where username='$username' and neptune='$neptune'"); $checkrows = mysqli_num_rows($check); if ($checkrows > 0) { echo "This combination of neptune and username has already been processed"; } else { //insert results from the form input in 2 rows one with neptune one without $query = "INSERT IGNORE INTO ballot(username, useremail, neptune) VALUES('$username', '$email', '$neptune')"; $query1 = "INSERT IGNORE INTO ballot(username, neptune) VALUES('$username', '$neptune')"; $result = mysqli_query($dbc, $query, $query1) or die('Error querying database.'); mysqli_close($dbc); } } } ?> Edited January 16, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.