插入时出现Mysql错误

时间:2014-09-27 06:56:58

标签: php mysql xampp

我使用xampp服务器。插入值时出错。错误说: 解析错误:语法错误,意外' INSERT#39;第6行的C:\ xampp \ htdocs \ App1 \ App1 \ abc.php中的(T_STRING)

<?php
    $mail = $_POST['mail'];
    $pas = $_POST['pass'];
    mysql_connect("localhost","root","");
    mysql_select_db("abc);
    mysql_query("INSERT INTO abc(mail,password) VALUES ('$mail','$pas')");
    $reg = mysql_affected_rows();
    echo "$reg was inserted.";
    ?>

2 个答案:

答案 0 :(得分:0)

mysql_select_db("abc);
mysql_query("INSERT INTO abc(mail,password) VALUES ('$mail','$pas')");

应该是

mysql_select_db("abc");
// Make Sure you have table with name abc in abc database
mysql_query("INSERT INTO abc (mail,password) VALUES ('$mail','$pas')");

有很多方法可以调试你自己的

$query = mysql_query("INSERT INTO abc (mail,password) VALUES ('$mail','$pas')") or die( mysql_error() );

对于受影响的行:

if( mysql_affected_rows( $query ) > 0 ) {
  // Your message
}

答案 1 :(得分:0)

试试这个

 <?php 
$link=  mysqli_connect('localhost', 'root', '', 'abc');
$mail = $_POST['mail'];
$pas = $_POST['pass'];

echo $mail;
$query="INSERT INTO abc (mail,password) VALUES ('$mail','$pas')";
$result=  mysqli_query($link, $query) or die(mysqli_error($link));


if(mysqli_affected_rows($link)>0)
{
    echo 'done';
}
?>