0

I have some forms submitting to my db table without hiccups but the data within the forms is not. Thus, new rows are generated but they are blank. I am using MAMP (Mac Apache MySQL PHP) stack in local development.

This is the end of my html page to give an example. I've included my email form and submit button.

<div class="col-md-4">
<div class="div1">
<h2>Step 6</h2><p>Email: REQUIRED </p>
<form action="upload_file.php" method="post">  
<input type="text" id="email" name="email" class="form-control" placeholder="kookmeyer@gmail.com"></br>
</form>
</div>
</div>


<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-4">
<div class="submit">
<form action="upload_file.php" method="post"> 
<button type="submit" class="btn btn-primary btn-lg btn-block" name="submit" >Submit</button>
</form>
</div> <!--End div col-md-5-->
</div> <!--End div Submit-->

The php page (upload_file.php) is,

<?php
//connecting to db
$dbc = mysqli_connect('localhost', 'root', 'root', 'surfboardhub')
or die('Error connecting to MySQL server');
//Get values from  
$email = "";
$brand = "";
$model = "";
$height ="";
$width = "";
$thick = "";
$price = "";
$location = "";
if(isset($_POST['location'])){ $location = $_POST['location']; }
if(isset($_POST['price'])){ $price = $_POST['price']; }
if(isset($_POST['thick'])){ $thick = $_POST['thick']; }
if(isset($_POST['width'])){ $width = $_POST['width']; }
if(isset($_POST['height'])){ $height = $_POST['height']; }
if(isset($_POST['model'])){ $model = $_POST['model']; }
if(isset($_POST['brand'])){ $brand = $_POST['brand']; }
if(isset($_POST['email'])){ $email = $_POST['email']; }  


$query = "INSERT INTO uploads (brand, model, height, width, thick, price, location, email) 
VALUES ('$brand', '$model', '$height', '$width', '$thick', '$price', '$location', '$email')";


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

mysqli_close($dbc);


echo 'Thanks for submitting your stick! An email has been sent to you with a link to your ad!<br    />';
echo 'Clicking here will send you back to the homepage';

?>

Any help is much appreciated. Thanks in advance!!! Dan

Daniel
  • 19
  • 6

2 Answers2

0

In your submit form you have just the submit button. So the only POST var that will arrive your Script upload_file.php is $_POST['submit'].

hellcode
  • 2,678
  • 1
  • 17
  • 21
0

Two things that are wrong with your scripts:

  1. Everything you want to send to your web server must be in the same form container.
  2. Your submit button must be an input with the type submit instead of a button.

HTML

<form action="upload_file.php" method="post"> 
    <input type="text" id="email" name="email" class="form-control" placeholder="kookmeyer@gmail.com" />
    <input type="submit" class="btn btn-primary btn-lg btn-block" name="submit" value="Submit" />
</form>

Also escape your variables before inserting them into your SQL query to prevent injection attacks, see here: How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Ke Vin
  • 2,004
  • 1
  • 18
  • 28