1

I am a novice trying to do the site for a non profit I volunteer with. Most of the code was gleened from You tube. Below is the code. The db name is cani the table is contact. When ever I submit is doesn't give me a success message, no data shows up in the database, and it doesn't return back to newentry.php. My brain hurts!

<?php

if (isset($_POST['submit'])){

include_once('dbh.inc.php');

$type = mysqli_real_escape_string($conn, $_POST['type']);
$first = mysqli_real_escape_string($conn, $_POST['first']);
$last = mysqli_real_escape_string($conn, $_POST['last']);
$company = mysqli_real_escape_string($conn, $_POST['company']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$phone = mysqli_real_escape_string($conn, $_POST['phone']);
$add1 = mysqli_real_escape_string($conn, $_POST['add1']);
$add2 = mysqli_real_escape_string($conn, $_POST['add2']);
$city = mysqli_real_escape_string($conn, $_POST['city']);
$state = mysqli_real_escape_string($conn, $_POST['state']);
$zip = mysqli_real_escape_string($conn, $_POST['zip']);

$sql = "INSERT INTO contact (contact_type, contact_first, contact_last,       contact_company, contact_email, contact_phone, contact_add1, contact_add2, contact_city, contact_state, contact_zip) VALUES ('$type', '$first', '$last', '$company', '$email', '$phone', '$add1', '$add2', '$city', '$state', '$zip')";

mysqli_query($conn, $sql);
header("Location: ../newentry.php?Success!");
}else{

header("Location: ../index.html");
exit();
} 
?>

Grr I partially fixed it...now everything works, except nothing is showing up in the database...it is connecting, I made sure the table name is correct. It says success. But whe I open phpAdmin and open the table, it is blank.

Chip
  • 11
  • 3
  • 1
    You're still vulnerable to SQL Injections. For your safety, please use prepared statements. – Darren Jul 19 '18 at 01:17
  • See https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments for how to get the reason for a MySQL error. – Barmar Jul 19 '18 at 01:35
  • echo $sql; die(); than run the query on the database and see what is the problem – Unix von Bash Jul 20 '18 at 07:14
  • Remember your talking to a rookie...where in my code would I insert this? – Chip Jul 20 '18 at 15:31

1 Answers1

0

Check if the variable $_POST['submit'] exists

Neal
  • 36
  • 2