解析错误:语法错误,意外' pname' (T_STRING)在第22行的C:\ XAMPP \ htdocs \ testsubmit.php中

时间:2015-02-19 16:36:03

标签: php mysql database forms post

我正在尝试将数据从php表单存储到MySql数据库(phpMyAdmin),我收到以下错误: 第22行C:\ XAMPP \ htdocs \ testsubmit.php中意外的'pname'(T_STRING)

我该如何解决这个问题?

adminform.php

<form action="testsubmit.php" method="POST">
Program Name: <input type="text" name= "pname" size="40" maxlength="80">
<br/>
<br/>
Year: <input type="text" name="py" size="20">
<br/>
<br/>
Criteria: <input type="text"  name= "pcrit" size="40" maxlength="80">
<br/>
<br/>
Score: <input type="text" name="psco" size="20">
<br/>
<br/>
<input type="submit" name="formSubmit" value="Submit"/>
</form>

testsubmit.php

<?php

 define ('DB_NAME','mynewdb');
 define ('DB_USER','root');
 define ('DB_PASSWORD','');
 define ('DB_HOST','localhost');


 $link=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);

  if(!$link){
      die('Could not connect:'.mysql_error());
  }


 $db_selected=mysql_select_db(DB_NAME, $link);

 if(!$db_selected){
     die('Can\'t use' .DB_NAME.':".mysql_error());
 }

 $value=$_POST['pname'];
 $value2=$_POST[ 'py' ];
 $value3=$_POST['pcrit'];
 $value4=$_POST['psco'];


 $sql="INSERT INTO new(pname,py,pcrit,psco)              VALUES('$value','$value2','$value3','$value4')";

  if(!mysql_query($sql)){

       die('Error:'.mysql_error());
  }

  mysql_close();

&GT;

1 个答案:

答案 0 :(得分:0)

你必须改变

die('Can\'t use' .DB_NAME.':".mysql_error());  

  die('Can\'t use' . DB_NAME . ':' . mysql_error());

问题是“by”

的变化