PHPcode & lt ;? Php $ con = mysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot;); if ($ con) {mysql_select_db (& quot; about using SQL statements to create tables in php
PHP code
Please look for the problem. The error "create error" is reported all the time. but after the SQL statement is copied out, it can be created perfectly in phpmyadmin. why? The following is a similar case. there is a problem with insertion ..
PHP code
";if($_POST){ $user=$_POST["user"]; $pass=$_POST["pass"]; $age=$_POST["age"]; $sex=$_POST["sex"]; $mail=$_POST["mail"]; $qq=$_POST["qq"]; $degree=$_POST["degree"]; $fav=$_POST["fav"]; $len=count($fav); $fav_z=""; for($i=0;$i<$len;$i++) { $fav_z=$fav_z.$fav[$i]; if($i<$len-1) $fav_z=$fav_z.","; } $con=mysql_connect("localhost","root",""); mysql_select_db("ceshi"); mysql_query("set names GB2312"); $sql="select count(*) from user2 where name='$user'"; $result=mysql_query($sql); $num=mysql_fetch_row($result); if($num[0]>0) { echo "have the same name!try another one."; } else { $sql="insert into user2(name,password,age,sex,mail,qq,degree,fav)value('$user','$pass','$age','$sex','$mail',$qq','$degree','$fav_z')"; $re=mysql_query($sql); if($re) echo "insert successful!"; else echo "insert error~!"; echo ""; }}else { echo "nothing upload!
";}echo "
clickthere return";?>
------ Solution --------------------
$ Do = mysql_query ($ SQL, $ con) or die (mysql_error (); // if this is the case, no error is reported. The same is true for this case.
------ Solution --------------------
The first piece of code has been tested. The table can be correctly created.
The SQL command in the second code is incorrect.
$ SQL = "insert into user2 (name, password, age, sex, mail, qq, degree, fav) value ('$ user',' $ pass ', '$ age',' $ sex', '$ mail',' $ QQ', '$ degree', '$ fav_z ')";
That is, a single quotation mark is missing before $ qq.