0

I am trying to a items to my database (sql) using php and a form, however the data is not being added and nothing seems to happening i just stay on the create.php page.

php code

<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "PolyTest";

// Create connection
$conn = mysql_connect($servername, $username, $password);
mysql_select_db($dbname)

$doorName = $_POST['doorName'];
$doorDes = $_POST['doorDes'];
$doorPrice = $_POST('doorPrice');
$doorColour = $_POST('doorColour');
$doorImage = $_POST['doorImage'];

if(!$_POST['submit']){
   echo "please fill in the boxs";
   header('Location: dooradd.php');
} else {
   mysql_query("INSERT INTO Doors ('ID', 'name', 'description', 'price', 'colour', 'image') VALUES(NULL, '$doorName', '$doorDes', '$doorPrice', '$doorColour', '$doorImage')") or die(mysql_error());
   echo "Door been added!";
   header('Location: doorlist.php');
 }
?>

HTML FORM

<form class="add" action="doorCreate.php" method="post">
  <input type="text" name="doorName" value="doorName">
  <input type="text" name="doorDes" value="doorDes">
  <input type="text" name="doorPrice" value="doorPrice">
  <input type="text" name="doorColour" value="doorColour">
  <input type="text" name="doorImage" value="doorImage">
  <input type="submit" name="submit">
</form>
gurps
  • 121
  • 1
  • 4
  • 10
  • 1
    It's kinda sad how many times we need to say this but **do not use the mysql_** functions... Deprecated for so long... Use **mysqli**. – Luke Joshua Park Dec 23 '15 at 22:21
  • Try to add a value to the `submit` in your form. Does that help? As you check the value of submit which should be false if no value is submitted. – Daniel Dec 23 '15 at 22:21
  • [mysql_query](http://php.net/manual/en/function.mysql-query.php) is deprecated. Also, you should be doing some kind of validation of your POST variables before sending them off to your database in order to mitigate [SQL Injection](http://bobby-tables.com/), errors in your data and SQL errors. – devlin carnate Dec 23 '15 at 22:22
  • 2
    Don't `echo` if you use `header`. It will make it do nothing. – trincot Dec 23 '15 at 22:22
  • Do something happens when you click on submit? Does the page change? Do you have any output? – Keyne Viana Dec 23 '15 at 22:23
  • 1
    `$doorPrice = $_POST('doorPrice');` `$doorColour = $_POST('doorColour');` These two should really be `$doorPrice = $_POST['doorPrice'];` `$doorColour = $_POST['doorColour'];` – Matt Dec 23 '15 at 22:24
  • 2
    You may want to try turn on error reporting `error_reporting(-1);` `ini_set('display_errors', 'On');` – Matt Dec 23 '15 at 22:25
  • It should rise an error, there are many errors. How are you getting nothing? – Keyne Viana Dec 23 '15 at 22:25
  • I am getting nothing – gurps Dec 23 '15 at 22:30
  • @gurps Nothing is a blank page or no action when cliking on submit? – Keyne Viana Dec 23 '15 at 22:31
  • @KV Nothing is a blank page sorry – gurps Dec 23 '15 at 22:31
  • @gurps Do this http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Keyne Viana Dec 23 '15 at 22:32
  • Check the PHP error log on the server. – Barmar Dec 23 '15 at 22:37

1 Answers1

3

change mysql_select_db($dbname) with mysql_select_db($dbname);

and change;

$doorPrice = $_POST('doorPrice');
$doorColour = $_POST('doorColour');

with

$doorPrice = $_POST['doorPrice'];
$doorColour = $_POST['doorColour'];
LetsSeo
  • 875
  • 7
  • 20