-2

This is my form

<html>
<head><title>Hawkins Car Records</title></head>
<body><h1>Add New Car</h1></body>
<form action="carNewBack.php" method="POST">
Car Name: <input type="text" name="carName"/>
<br>
Make: <input type="text" name="make"/>
<br>
Model: <input type="text" name="model"/>
<br>
Year: <input type="text" name="year"/>
<br>
Last 5 digits of VIN: <input type="text" name="lastVIN"/>
<br>
Plate: <input type="text" name="plate"/>
<br><br>
<input type="submit" value="Submit"/>
</form>
</html>

When I hit the submit button, nothing happens. No white screen, no 404, nothing. It doesn not execute carNewBack.php. Can someone share any ideas?

Here is the action file. Im trying to build a data base of service records of my family's cars and this is the form that takes input and creates a new car record.

<?php

$carconnect = mysqli_connect("localhost", "carUser", "caps271:snows", "cars");

if (mysqli_connect_errno()) {
    printf("connect failed: %s\n", mysqli_connect_error());
    exit();
} else {
    $carName = mysqli_real_escape_string($_POST['carName']);
    $make = mysqli_real_escape_string($_POST['make']);
    $model = mysqli_real_escape_string($_POST['model']);
    $year = mysqli_real_escape_string($_POST['year']);
    $lastVIN = mysqli_real_escape_string($_POST['lastVIN']);
    $plate = mysqli_real_escaped_string($_POST['plate']);

   $sql = "INSERT INTO cars (carName, make, model, year, lastVIN, plate) VALUES ('".               $carName."', '".$make."', '".$model."', '".$year."', '".$lastVIN."', '".       $plate."')"; 
    $res = mysqli_query($carconnect, $sql);

    if ($res === TRUE) {
    echo "Car added";
    } else {
        printf ("Could not insert car: %s\n", mysqli_error($carconnect));
    }
   mysqli_close($carconnect);
}

?>

Edit: Code fixes.

Andrew
  • 53
  • 6

4 Answers4

5

your <body> tag is closed too early (on line 3), you should close it right before </html> so on line 18

Adrian
  • 904
  • 1
  • 11
  • 17
  • hm, and the html form is the only code in the first file? Because it´s working fine for me... (Working on jsFiddle too - http://jsfiddle.net/ZgYe2/) – Adrian Aug 18 '13 at 22:25
  • another point: mysqli_real_escaped_string() function doesnt take your db connection as parameter - http://php.net/manual/en/function.mysql-real-escape-string.php – Adrian Aug 18 '13 at 22:38
  • the escape funtion is wrong. causing `Fatal error: Call to undefined function mysqli_real_escaped_string()` reffer to the link I gave in previous comment. it should look like this: `$carName = mysqli_real_escaped_string($_POST['carName']);` – Adrian Aug 18 '13 at 22:44
  • Lol, you are right. Inak absolutely missed the "d" in the function.. who knows where he has got it.. however the link was correct... and in my opinion its not a good practice because pdo is better :-) – Adrian Aug 18 '13 at 23:24
  • It is still throwing a 500 error even with the prescribed fixes (see above). – Andrew Aug 30 '13 at 19:06
0

if carNewBack.php is not printing anything back to the screen or redirecting the page. What are using to host the website? If you do not have a web service that does not have php support then this could be an issue.

Daniel Samson
  • 718
  • 4
  • 18
0

The form you submitted looks correct (http://www.w3schools.com/php/php_forms.asp), I imagine the real issue could lie in the php handler. If you do not get an error, that means that it does find the php handler.

I also tested your code and it looks fine, so another option could be the browser you are using or even the zoom (I use Google Chrome).

gusbeto37
  • 3
  • 2
  • Switched to chrome and it submitted but now it cant find the action... And yes it is in the document root. HTTP error 500 – Andrew Aug 18 '13 at 22:24
0

Dear brother its simple..

  1. check out your header there must be something like: error_reporting(0); or something like that in your php.ini file to Suppress the errors.

2.There is no valid default function as mysqli_real_escaped_string(); unless you have it user defined.

It is mysqli_real_escape_string();

kindly have a look at mysqli_real_escape_string()

hope it was helpful :)

Rahul
  • 1,181
  • 1
  • 11
  • 20