通过TCP连接PHP mysql服务器 [英] Connect with PHP mysql server via TCP

查看:63
本文介绍了通过TCP连接PHP mysql服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
include_once 'connection.php';

if(isset($_SESSION['user'])!="")
{
	header("Location: userhome.php");
}

if(isset($_POST['btn-login']))
{
	$email = mysql_real_escape_string($_POST['email']);
	$upass = mysql_real_escape_string($_POST['pass']);
	
	$email = trim($email);
	$upass = trim($upass);
	
	$res=mysql_query("SELECT user_id, user_name, user_pass FROM users WHERE user_email='$email'");
	$row=mysql_fetch_array($res);
	
	$count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row
	
	if($count == 1 && $row['user_pass']==md5($upass))
	{
		$_SESSION['user'] = $row['user_id'];
		header("Location: userhome.php");
	}
	else
	{
		?>
        <script>alert('Username / Password Seems Wrong !');</script>
        <?php
	}
	
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Member and Admin login</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="login-form">
<form method="post">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="email" placeholder="Your Email" required /></td>
</tr>
<tr>
<td><input type="password" name="pass" placeholder="Your Password" required /></td>
</tr>
<tr>
<td><button type="submit" name="btn-login">Sign In</button></td>
</tr>
<tr>
<td><a href="admin/adminlogin.php">Click here for Admin Login</a></td>
</tr>
<tr>
<td><a href="register.php">Sign Up Here</a></td>
</tr>
</table>
</form>
</div>
</center>
<br><br>
<div id="Div_Footer">
		
		<a href="home.php">HOME</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		
		<a href="usermovies.php">MOVIES</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		
		<a href="contactus.php">CONTACT US</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
		<a href="aboutus.php">ABOUT US</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		
		<a href="usernews.php">NEWS</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		
		
</div>
</body>
</html>





我的尝试:



谁能告诉我我的代码有什么问题。不知怎的,我设法连接xampp mysql服务器。

我的所有页面都工作正常,我的登录,注册。



但是当通过tcp / ip(202.20)与另一台主机服务器进行测试时。 5.105),我无法连接。



我更改了主机名,用户名,密码和数据库。我的登录页面显示,除了我连接到数据库。



这是我的connection.php代码



//连接到我们的数据库

mysql_connect(202.20.5.105,21402449,21402449)或die(mysql_error());

mysql_select_db(21402449)或死(mysql_error());



echo< h>连接到数据库;

?>



What I have tried:

Can anyone tell me whats wrong with my code. Somehow I managed to connect with xampp mysql server.
All my pages works fine, my logins , register.

But when test with with another host server via tcp/ip (202.20.5.105), I wasnt able to connect.

I have changed the hostname, username, password and database. my login pages shows up, except I am connect to database.

Here is my connection.php code

// Connects to Our Database
mysql_connect("202.20.5.105", "21402449", "21402449") or die(mysql_error());
mysql_select_db("21402449") or die(mysql_error());

echo "<h>Connected to database";
?>

推荐答案

_SESSION [' user'])!=
{
header( < span class =code-string>位置:userhome.php);
}

if(isset(
_SESSION['user'])!="") { header("Location: userhome.php"); } if(isset(


_POST [' btn-login']))
{
_POST['btn-login'])) {


email = mysql_real_escape_string(
email = mysql_real_escape_string(


这篇关于通过TCP连接PHP mysql服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆