2017-02-06 8 views
-2

私のPHPファイルはHTMLフォームの情報をデータベーステーブルに挿入していません。INSERT INTOを実行できません

エラーメッセージに表示されるように、フォームからokの情報を受け取りましたが、これを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); 
} 

?> 

これは私がコミュニティのwikiとして

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

:代わりの

$server_name = "localhost"; 

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

だから、すべてこれに対する答えは、ポート番号を削除することでした。 –

+0

エラーメッセージは何ですか? – jhmckimm

+0

あなたはどんな種類のエラーが発生しているか知らずに、mysqli_error($ conn)が出力するものは何ですか? – Qirel

答えて

1

ポスティングを使用していますフォームです。これは何者でもないはずです。ご不明なフォームが失敗した賭け

$server_name = "localhost:2243"; 
関連する問題