日期:2014-05-17 浏览次数:20423 次
<?php include "manage_heads.php"; ?> <link rel="stylesheet" type="text/css" href="manage.css" /> <script language="javascript"> function CheckPost(){ if(window.confirm("确定增加")){ myform.action="addstudent.php"; return true; } else { myform.id.focus(); return false; } } </script> <?php include 'conn.php'; ?> <?php //增加学生 if (isset( $_POST["phone"])){ $id=$_POST['id']; $name=$_POST['name']; $phone=$_POST['phone']; $sql="insert into people values(20,".$name.",".$phone."0);"; if(mysql_query($sql)){ echo '<script type="text/javascript">alert("操作成功");</script>'; } else{ echo '<script type="text/javascript">alert("操作失败");</script>'; } } ?> <form id="addform" action="" name="myform" method="post" onsubmit="return CheckPost();" > i d: <input type="text" name="id" size="30"/><br> name :<input type="text" name="name" size="30"/><br> phone: <input type="text" name="phone" size="30"/><br> <input id="addbtn" type="submit" value="确定增加" name="btn"></form>
$sql="insert into people values(20,".'$name'.",".'$phone'.",0)";
------解决方案--------------------
为什么它可以写入到int型的数据库里面呢
--mysql会自动转换类型的
外层是双引号,里面用当引号可以。但是反之不可以。即
$sql='insert into people values(20,"$name","$phone",0)'; 这样写是解析不了的
需要这样写 $sql='insert into people values(20,"'.$name.'","'.$phone.'",0)';
------解决方案--------------------