php - form input submitting to DB, but not showing content -
i have forms submitting db table without hiccups data within forms not. thus, new rows generated blank. using mamp (mac apache mysql php) stack in local development.
this end of html page give example. i've included email form , 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 db $dbc = mysqli_connect('localhost', 'root', 'root', 'surfboardhub') or die('error connecting mysql server'); //get values $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 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 submitting stick! email has been sent link ad!<br />'; echo 'clicking here send homepage'; ?> any appreciated. in advance!!! dan
two things wrong scripts:
- everything want send web server must in same form container.
- your submit button must
inputtype submit instead ofbutton.
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 variables before inserting them sql query prevent injection attacks, see here: how can prevent sql injection in php?
Comments
Post a Comment