关于php中利用sql语句创建表的有关问题
Jun 13, 2016 am 10:54 AM
default
echo
fav
mysql
quot
关于php中利用sql语句创建表的问题
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $con=mysql_connect("localhost","root","");if($con){ mysql_select_db("text",$con); mysql_query("set name gtf8"); $sql="create table user_date ( id int(5) not null auto_increment primary key, name char(10) not null default '', password char(12) not null default '', age int(3) not null default 0, sex char(10) not null default 'man', mail char(50) not null default '', qq char(10) not null default '', gedree char(10) not null default '', fav char(50) not null default '' )"; $do=mysql_query($sql,$con); if($do) { echo "create user data successful!!"; } else echo "create error!!!!!";}else { echo "connect error!!!!";}?>
Copy after login
求大神找找问题,一直报错 create error的问题..但是将sql语句复制出来之后,在phpmyadmin中,又可以完美创建,这是什么原因造成的?下面还有一个类似的情况.就是插入有问题..
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpecho "<style type=\"text/css\"><!--body {color:#000099;font-size:10pt; text-align:center}-->";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;$i0) { 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 "<p>"; }}else { echo "nothing upload!<br>";}echo "<br>click<a href="reg.html">there</a> return";?></p>
Copy after login
------解决方案--------------------
$do=mysql_query($sql,$con) or die(mysql_error()); //改成这样看报错了没有,下面也是如此
------解决方案--------------------
第一段代码,经测试没有问题,表能正确创建
第二段代码中sql指令有误
$sql="insert into user2(name,password,age,sex,mail,qq,degree,fav)value('$user','$pass','$age','$sex','$mail','$qq','$degree','$fav_z')";
即 $qq 前少了个单引号
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP?

What are the application scenarios of Java enumeration types in databases?

How to insert data into a MySQL table using PHP?

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP?

How to create a MySQL table using PHP?
