目前,我有我有下面的代碼有問題..PDOException錯誤PHP SQL「名字不能爲空」
口口聲聲說
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]:
Integrity constraint violation: 1048 Column 'Firstname' cannot be null'
in C:\xampp\htdocs\clubresults\checkregister.php:30 Stack trace: #0
C:\xampp\htdocs\clubresults\checkregister.php(30): PDOStatement->execute()
#1 {main} thrown in C:\xampp\htdocs\clubresults\checkregister.php on line 30
我嘗試了一切,但我知道我只是不能刪除錯誤...任何形式的幫助是非常讚賞:d 這個PHP文件被稱爲checkregister.php
$pdo = new PDO('mysql:host=localhost;dbname=clubresults', 'root', '12345678');
#Set Error Mode to ERRMODE_EXCEPTION.
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('INSERT INTO members
(firstname, surname, DD, MM, YYYY,
email, Player1, Player2, Player3, Player4, Player5)
VALUES
(:firstname, :surname, :DD, :MM, :YYYY,
:email, :Player1, :Player2, :Player3, :Player4, :Player5)');
$stmt->bindParam(':firstname', $_GET['firstname']);
$stmt->bindParam(':surname', $_GET['surname']);
$stmt->bindParam(':DD', $_GET['DD']);
$stmt->bindParam(':MM', $_GET['MM']);
$stmt->bindParam(':YYYY', $_GET['YYYY']);
$stmt->bindParam(':email', $_GET['email']);
$stmt->bindParam(':Player1', $_GET['Player1']);
$stmt->bindParam(':Player2', $_GET['Player2']);
$stmt->bindParam(':Player3', $_GET['Player3']);
$stmt->bindParam(':Player4', $_GET['Player4']);
$stmt->bindParam(':Player5', $_GET['Player5']);
$stmt->execute();
這是我在另一個PHP文件格式:
<form name="register" method="post" action="checkregister.php">
<!--Text, using <p> tag for new line-->
Main Account Registration <p>
* All Fields Mandatory <P>
<div class="required_field">
<label for="leadername">Team Leader's First Name</label>
<input name="firstname" type="text" value="hihi"><p>
<span id="firstnameerror" class="error"></span>
</div>
the same code repeats for each of the other ones such as Surname, DD MM YY, etc
<input type="submit" name="submitbutton" id="submitbutton" value="Register">
<input type="reset" name="resetbutton" id="resetbutton" value="Clear all Fields">
</form>
什麼是您的查詢字符串中的網址? –
如果這有幫助..我使用Dreamweaver來製作代碼和即時通訊使用XAMPP(PHPmyadmin,MySQL,APACHE) – Tuzki
您的代碼將無法正常工作,除非您查詢字符串包含每個參數的'key = value'對。 –