简单的php中的sql问题
各位高手帮忙看一下,非常感谢!我的sql的字段名和值为什么不能用for来输出,其中for($a=2;$a<count($row_subject);$a++){echo$f...
各位高手帮忙看一下,非常感谢! 我的sql的字段名和值为什么不能用for来输出,其中for($a=2;$a<count($row_subject);$a++){echo $field[$a];echo ",";}的结果是chinese,English,math,C_language, for($a=2;$a<count($row_subject);$a++){echo $_POST["$field[$a]"];echo ",";}的结果是99,88,77,66, 他是这样报错的Parse error: syntax error, unexpected ',' in C:\VertrigoServ\www\text2.php on line 15 $sql = "INSERT INTO table_mark (id,username,name,password,for($a=2;$a<count($row_subject);$a++){echo $field[$a];echo ",";}type) VALUES(NULL,'".$username."','".$name."','".$passcode."',for($a=2;$a<count($row_subject);$a++){echo $_POST["$field[$a]"];echo ",";}'student') ";
展开
1个回答
展开全部
$sql = "INSERT INTO table_mark (id,username,name,password,for($a=2;$a<count($row_subject);$a++){echo $field[$a];echo ",";}type) VALUES(NULL,'".$username."','".$name."','".$passcode."',for($a=2;$a<count($row_subject);$a++){echo $_POST["$field[$a]"];echo ",";}'student') "; 不应该这样写,应该这样写才对: $sql="INSERT INTO table_mark(id,username,name,password,"; for($a=2;$a<count($row_subject);$a++) $sql.=$field[$a].","; $sql.="type) VALUES(NULL,'$username','$name','$passcode',"; for($a=2;$a<count($row_subject);$a++) $sql.="'".$_POST[$field[$a]]."',"; $sql.="'student') ";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询