我的问题是我无法从表单插入数据并插入到phpmyadmin数据库中。 如果有人可以检查代码会很好。
编辑: 错误:
列数与第1行的值计数不匹配
与它一起表:
CREATE TABLE IF NOT EXISTS `members` (
`Memberid` int(10) NOT NULL AUTO_INCREMENT,
`Username` varchar(20) NOT NULL,
`Lastname` varchar(20) NOT NULL,
`Year` varchar(10) NOT NULL,
`Email` varchar(20) NOT NULL,
`Password` varchar(40) NOT NULL,
`Activation` varchar(40) DEFAULT NULL,
PRIMARY KEY (`Memberid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;
数据库连接:
<?php
/*Define constant to connect to database */
DEFINE('DATABASE_USER', 'db username');
DEFINE('DATABASE_PASSWORD', 'db password');
DEFINE('DATABASE_HOST', 'db host');
DEFINE('DATABASE_NAME', 'db name');
/*Default time zone ,to be able to send mail */
date_default_timezone_set('UTC');
//This is the address that will appear coming from ( Sender )
define('EMAIL', '*****@gmail.com');
/*Define the root url where the script will be found such as http://website.com or http://website.com/Folder/ */
DEFINE('WEBSITE_URL', 'http://****.herobo.com/');
// Make the connection:
$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);
if (!$dbc) {
trigger_error('Could not connect to MySQL: ');
}
?>
包括数据库连接
include ('database_connection.php');
在这里我认为我有些不对劲:
if (empty($error)) //send to Database if there's no error '
{ // If everything's OK...
// Make sure the email address is available:
$query_verify_email = "SELECT * FROM members WHERE Email ='$Email'";
$result_verify_email = mysqli_query($dbc, $query_verify_email);
if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false)
echo ' Ilmes andmebaasi viga ';
}
if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email .
// Create a unique activation code:
$activation = md5(uniqid(rand(), true));
$query_insert_user = "INSERT INTO `members` ( `Username` , `Lastname` , `Year` , `Email` , `Password` , `Activation` ) VALUES ( '$name', '$Lastname', '$Year', '$Email' '$Password', '$activation')";
$result_insert_user = mysqli_query($dbc, $query_insert_user);
echo mysqli_error($dbc);
if (!$result_insert_user) {
echo 'Query Failed ';
}
一些代码更多但它的活动帐户,但首先我需要将我的数据插入数据库。
我获取数据的表单在数据库中插入什么
<form action="registeeri.php" method="POST" class="registration_form" id="login">
<h1>Registeerimine</h1>
<fieldset id="inputs">
<input class="email" name="e-mail" type="hidden" value="TRUE" />
<input class="name" name="name" type="text" placeholder="Eesnimi" autofocus required/>
<input class="name" name="lastname" type="text" placeholder="Perekonnanimi" required/>
<input class="name" name="year" type="text" placeholder="Synniaasta nt: 1995" required/>
<input class="email" name="e-mail" type="text" placeholder="E-mail" required/>
<input class="password" name="Password" type="password" placeholder="Parool" required />
</fieldset>
<fieldset id="actions">
<input type="hidden" name="formsubmitted" value="TRUE" />
<input type="submit" id="submit" value="Registeeri" />
<a href="index.php">Pealehele</a><a href="login.php">Oled juba kasutaja?</a>
</fieldset>
答案 0 :(得分:0)
你的问题在于这一行:
$query_insert_user = "INSERT INTO `members` ( `Username` , `Lastname` , `Year` , `Email` , `Password` , `Activation` ) VALUES ( '$name', '$Lastname', '$Year', '$Email' '$Password', '$activation')";
请注意'$Email' '$Password'
部分VALUES
之间缺少逗号。因此,您已经说过要插入6列数据,但它认为您只提供了5个。因此您的错误。
其他评论: 理想情况下,在与数据库通信时应使用PDO。