.NET(C#) 与 PHP 笔记

.NET(C#) 与 PHP 笔记

一、连接数据库

php->mysql插入

<?php
//连接数据库
$servername = "MySQL连接地址";
$username = "MySQL用户名";
$password = "MySQL数据库名密码";
$dbname = "MySQL数据库名";
 
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 

//uid表名 id,pwd列名
$sql = "INSERT INTO uid (id,pwd)
VALUES ($uid,$pwd)";
 
if ($conn->query($sql) === TRUE) {
    echo "新记录插入成功";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
 //断开连接
$conn->close();
?>

c#->sql server读取(对比用户密码)

//windows 身份验证 连接数据库
//string constr1 = "server=(local); user id=sa; pwd=sa; database=cs";
//SqlConnection con1 = new SqlConnection(constr1);


//SQL Server 身份验证 连接数据库 
string constr1 = "server=(local); Trusted_Connection=SSPI;  database=数据库名";
SqlConnection con1 = new SqlConnection(constr1);
//判断登录
string sqlstr1 = "select * from 表名 where 列1='" + zh + "'and 列2='" + mm + "'";
SqlDataAdapter ada1 = new SqlDataAdapter(sqlstr1, con1);
con1.Open();
DataSet ds1 = new DataSet();
ada1.Fill(ds1);

if (ds1.Tables[0].Rows.Count <= 0){
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('输入账号密码不正确!');</script>");
}else{
//弹窗
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('登录成功!');</script>");
//跳转
Response.Redirect("aaa.aspx");
            }

前端&后端 数据转换连接

Php & html

html数据->php

<?php
//取传递过来的数据
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
?>
<form action="chuli.php" method="post"> <!--传值到chuli.php页面进行处理-->
<div>用户名:<input type="text" name="uid" /></div>
<div>&nbsp;码:<input type="password" name="pwd" /></div>
<div><input type="submit" value="登录" /></div>
</form>
c# & .asqx

.aspx -> c#

 <form id="form1" runat="server">
    <div>
    	账号:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="登录" onclick="Button1_Click" />
        <br />
        密码:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button2" runat="server" Text="取消" onclick="Button2_Click" />
    </div>
</form>
//c#
string zh = TextBox1.Text.ToString();
string mm = TextBox2.Text.ToString();

Css

例如

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <!--图标+页名-->
  <title>上传+</title>
	<link rel="icon" href="images/logo.jpg" sizes="32x32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
  <!--使用内部样式表引入CSS-->
  <style type="text/css">
    .file-box{ position:relative;width:340px;margin:20px;}
	.txt{ height:28px;line-height:28px; border:1px solid #cdcdcd; width:180px;}
	.btn{width:70px; color:#fff;background-color:#3598dc; border:0 none;height:28px; line-height:16px!important;cursor:pointer;}
	.btn:hover{background-color:#63bfff;color:#fff;}
	.file{ position:absolute; top:0; right:85px; height:30px;line-height:30px; filter:alpha(opacity:0);opacity: 0;width:254px }
  </style>
</head>
 <div class="file-box"> 
    <form action="upload_file.php" method="post" enctype="multipart/form-data"> 
        <input type="text" id="textfield" class="txt" />
        <input type="button" class="btn" value="浏览..." /> 
        <input type="file" name="file" class="file" id="fileField" onchange="document.getElementById('textfield').value=this.files[0].name"/> 
        <input type="submit" class="btn" value="上传" /> 
    </form> 
</div>
<body>
</body>
</html>


上传css代码来自
input type="file"获取文件名方法 作者:已被格式化的叔叔

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

推演者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值