2017-02-06 2 views
-2

Meine PHP-Datei fügt die Informationen aus einem HTML-Formular nicht in meine Datenbanktabelle ein.INSERT INTO konnte nicht ausgeführt werden

Ich erhalte die Informationen aus dem Formular ok, wie sie in der Fehlermeldung erscheinen, und ich führe dies auf MAMP.

<?php 

$server_name = "localhost:2243"; 
$username = "root"; 
$password = "root"; 
$dbname = "studentinfo"; 

$conn = mysqli_connect($server_name,$username,$password,$dbname); 

if ($conn->connect_error){ 
    die("Connection failed: " . $conn->connect_error); 
} 

//retrieving the data 
$first_name = $_POST['firstname']; 
$last_name = $_POST['lastname']; 
$email = $_POST['email']; 
$school = $_POST['field4']; 



$sql = "INSERT INTO studentlist (firstname,lastname,email,school) 
VALUES ('$first_name','$last_name','$email','$school')"; 

if(mysqli_query($conn, $sql)){ 
    echo "Records added successfully."; 
} else{ 
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn); 
} 

?> 

das ist die Form, die ich

<!DOCTYPE html> 
<html lang="en"> 

<head> 
    <meta charset="UTF-8"> 
    <title>Submission Form</title> 
    <meta name="description" content="DESCRIPTION"> 

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> 
    <!--[if lt IE 9]> 
     <script src = "http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif]--> 
    <link href="style.css" rel="stylesheet" type="text/css" /> 
</head> 

<body> 
    <div class="form-style-5"> 
    <form action="addData.php" method="post"> 
    <fieldset> 
    <legend><span class="number">1</span> Candidate Info</legend> 
    <input type="text" name="firstname" id="firstname" placeholder="Your First Name *"> 
    <input type="text" name = "lastname" id="lastname" placeholder="Your Last Name" /> 
    <input type="email" name="email" id="email" placeholder="Your Email *"> 
    <label for="school">Your School</label> 
    <select id="school" name="field4"> 
    <optgroup name = "school" label="School"> 
    <option value="LHS">Lisnaskea High School</option> 
    <option value="Potora">Potora Royal Grammer</option> 
    <option value="OU">The Open University</option> 
    </optgroup> 
    </select> 
    </fieldset> 

    <input type="submit" name="submitstudent" value="submit" onclick="return validate()"/> 
    </form> 
    </div> 
+0

Wetten Ihre unbekannte Form gescheitert. –

+0

Was ist die Fehlermeldung? – jhmckimm

+0

Ohne zu wissen, welche Art von Fehlern Sie bekommen, ist es schwer zu sagen - was gibt mysqli_error ($ conn) aus? – Qirel

Antwort

1

Posting als Community Wiki verwende. Es sollte keine Wiederholung geben.

" the issue was the servername as i removed the port number thanks for the comments @Fred-ii- – bighead 1 min ago"

"@bighead Aahhhhh I should have followed another of my instincts earlier, being the port!!! aughh!! lol hey, you're welcome. – Fred -ii- 27 secs ago"

Also die Antwort auf all dies war die Portnummer zu entfernen:

$server_name = "localhost"; 

Statt:

$server_name = "localhost:2243";