16行目でエラーになります。 この行がエラーを出している理由を理解するのを手伝ってください。 コードは以下の通りです 固有でない電子メールはテーブルに挿入されないので、エラーを理解できません。
<?php
if (isset($_POST["submit"]))
{
$conn=mysql_connect("localhost","root","");
if($conn)
{
$sql=mysql_select_db("user",$conn)
or die("database not found".mysql_error());
$fname=$_POST["firstname"];
$lname=$_POST["lastname"];
$email=$_POST["email"];
$age=$_POST["age"];
$check=mysql_query("select email from reg where email = "$email"");
if(!$check) // if email not insert before then insert new value into database
{
$insert="insert into reg values ("","$fname","$lname","$email","$age") ";
$result= mysql_query($insert);
if($result)
{
echo "thank you for information entered";
}
}
else echo "this email already exist !" ;
}
else
die("server not found".mysql_error());
}
回答:
回答№1は0あなたのコード:
$insert="insert into reg values ("","$fname","$lname","$email","$age") ";
最初のフィールドがPRIMARY番号とAUTOINCREMENTの場合は、空の文字列を変更してください。 "" に ヌル このような:
$insert="insert into reg values (NULL,"$fname","$lname","$email","$age") ";
新しく作成した行の次の有効な番号を取得するための結果として
回答№2の場合は-1
このチェックで何を達成しようとしているのかわからない
$check=mysql_query("select email from reg where email = "$email"");
if ($check)
ただし、選択要求に一致するものがあるかどうかを確認したい場合は、返された行数を確認してください
$check=mysql_query("select email from reg where email = "$email"");
$num_rows = mysql_num_rows($check);
if ($num_rows==0)
{
$insert="insert into reg values ("","$fname","$lname","$email","$age") ";
$result= mysql_query($insert);
if($result)
{
echo "thank you for information entered";
}
}
else echo "this email already exist !" ;
}
else
die("server not found".mysql_error());
}