php里衔接变量和字符串用【.】
如
echo $name."<br>";
echo $name.$age;
php连接数据库:
1、建立链接
2、数据操作
3、结果处理
mysql_connect(); php和mysql连接,apache解析
1、在html表单中post、get传输数据;
<form action="getregister.php" method="post"> //html代码
2、建立php文件,如下:php语句可以写在<body>标签中
<?php
//a、创建与数据库连接
$con=mysql_connect("localhost:13306","root","123456");
if($con){
echo "sucess<br>";
}else{
echo "fail".mysql_error();
}
//b、选择数据库和编码方式
mysql_select_db("stu");
mysql_query("set names utf8");
//c、操作语句:这里是查询语句
$query="select * from stu" ;
$rest=mysql_query($query);
echo "<table border='1'>";
while($row=mysql_fetch_row($rest)){
echo "<tr>";
echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
/*$uname=$_GET['username'];
$umobile=$_GET['tel'];
$uid=$_GET['code'];*/
/*$uname=$_POST['username'];
$umobile=$_POST['tel'];
$uid=$_POST['code'];*/
//插入
$con=mysql_connect("localhost:13306","root","123456");
if($con){
echo "sucess<br>";
}else{
echo "fail".mysql_error();//
}
mysql_select_db("stu");
mysql_query("set names utf8");
/*$sql="insert into stu values('$uid','$uname','$umobile')";
$res=mysql_query($sql);
if($res){
echo "sucess01";
}else{
echo "fail01".mysql_error();
}*/
//查询语句
$query="select * from stu" ;
$rest=mysql_query($query);
echo "<table border='1'>";
while($row=mysql_fetch_row($rest)){
echo "<tr>";
echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
echo "</tr>";
}
echo "</table>";
?>