-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.

7
  • is there any javascript on the page? Aug 18, 2013 at 22:10
  • 2
    My bet is you have an error in your PHP page but your configuration (php.ini or some sort) is hiding the error message.
    – luiscubal
    Aug 18, 2013 at 22:12
  • You should indent your code a little. It makes it MUCH easier to read Aug 18, 2013 at 22:13
  • i do in compilers but it doesnt play nicely in here. will try right now.
    – Andrew
    Aug 18, 2013 at 22:18
  • See this question
    – Luc M
    Aug 19, 2013 at 1:10

4 Answers 4

5

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

5
  • hm, and the html form is the only code in the first file? Because it´s working fine for me... (Working on jsFiddle too - jsfiddle.net/ZgYe2)
    – Adrian
    Aug 18, 2013 at 22:25
  • another point: mysqli_real_escaped_string() function doesnt take your db connection as parameter - php.net/manual/en/function.mysql-real-escape-string.php
    – Adrian
    Aug 18, 2013 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, 2013 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, 2013 at 23:24
  • It is still throwing a 500 error even with the prescribed fixes (see above).
    – Andrew
    Aug 30, 2013 at 19:06
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 :)

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.

1
  • i am using AMP on my computer at home. im not hosting yet.
    – Andrew
    Aug 18, 2013 at 22:15
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).

1
  • 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, 2013 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.