2017-01-13 3 views
-2

Моя страница имеет форму и как только я нажимаю кнопку отправки, форма исчезает. Это файл add_cars.php, который у меня есть. Я пробовал все, что мог, но я немного новичок, когда речь идет о PHP.Формы исчезают со страницы PHP

<?php 
$content = "<h1>Add a name</h1>"; 
// define a variable with path to the script which will process form 
// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) 
$action = $_SERVER["PHP_SELF"]."?page=add_cars"; 
// fetch the albums so that we have access to their names and prices 
$sql = "SELECT manufacturer, model 
     FROM cars"; 
$result = mysqli_query($link, $sql); 
// check query returned a result 
if ($result === false) { 
    echo mysqli_error($link); 
} 
// define the form HTML (would ideally be in a template) 
$form_html = "<form action='".$action."' method='POST'> 
<fieldset> 
<label for='manufacturer'>Client First Name:</label> 
<input type='text' name='manufacturer' required> 
</fieldset> 
       <fieldset> 
        <label for='model'>Client Surname:</label> 
<input type='text' name='model' required> 
       </fieldset> 
       <button type='submit'>Submit</button> 
       </form>"; 
// append form HTML to content string 
$content .= $form_html; 
// ------- START form processing code... ------- 
// define variables and set to empty values 
$manufacturer = $model = ""; 
// check if there was a POST request 
if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    // validate the form data 
    $manufacturer = mysqli_real_escape_string($link, clean_input($_POST["manufacturer"])); 
    $model = mysqli_real_escape_string($link, clean_input($_POST["model"])); 
    // define the insertion query 
    $sql = sprintf("INSERT INTO cars (manufacturer, model) 
VALUES ('%s', '%s')", $manufacturer, $model); 
    // run the query to insert the data 
    $result = mysqli_query($link, $sql); 
    // check if the query went ok 
    if ($result === false) { 
     // handle specific errors based on mysli error number code 
     // (in order to output more useful message to user!) 
     $errno = mysqli_errno($link); 
     switch ($errno) { 
      case 1062 : // case for duplicate entry 
       $content .= "NoName."; 
       break; 
      default : 
       echo mysqli_error($link); 
     } 
    } else { 
     $content .= "Name successfully added."; 
    } 
} 
// ------- END form processing code... ------- 
?> 

Помощь будет значительно

+1

любые ошибки http://php.net/manual/en/function.error-reporting.php - и из запроса? –

+0

Что-нибудь появляется вообще? И где вы повторяете свой контент? – aynber

+0

вам нужно эхо '$ content', если вы этого еще не сделали. Вы просто назначаете эту переменную, но ничего не делаете с ней. –

ответ

0

оценили Попробуйте echo $action;die; , чтобы увидеть, где форма перенаправляет. Если вы добавили error_reporting, чтобы скрыть ошибки, попробуйте удалить его, чтобы узнать, какое уведомление вы получите.