我正在尝试将数据从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;
答案 0 :(得分:0)
你必须改变
die('Can\'t use' .DB_NAME.':".mysql_error());
到
die('Can\'t use' . DB_NAME . ':' . mysql_error());
问题是“by”
的变化