Why doesn't my sql query add to database, with remote_addr IP in PHP? (Do I need an IP type in database, or a VARCHAR)?
Also need help with sessions, how do they work?
Here's full code for 1 file
Also need help with sessions, how do they work?
Here's full code for 1 file
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
background-color: #333;
margin: 0 auto;
font-family: Verdana;
}
.maincontent {
margin: 0 auto;
width:1000px;
font-family: Verdana;
color:#669900;
}
.top {
margin: 0 auto;
width:1000px;
}
.maincontentnews {
width: 1000px;
height: 500px;
position: relative;
top: -1000px;
margin: 0 auto;
}
.bglinks {
width: 1000px;
margin: 0 auto;
}
.newsAdd {
position: absolute;
margin: 0 auto;
}
.newsAddButton {
position: absolute;
margin: -20 auto;
}
th {
padding-left: 1em;
text-align: left;
}
</style>
</head>
<body>
<div class="top"><img src="maintop.png" width="1000" height="227" border="5" /> </div>
<div class="bglinks">
<table width="1000" height="50" border="0">
<tr>
<th width="1000" align="center" bgcolor="#CCCCCC" scope="col"><a href="index.php"><img src="home.png" width="139" height="41"></a> <a href="account.php"><img src="account.png" width="139" height="41"></a> <a href="topscore.php"><img src="topscore.png" width="139" height="41"></a> <img src="on.png" width="50" height="50"><a href="houses.php"><img src="houses.png" width="139" height="41"></a> <a href="guilds.php"><img src="guilds.png" width="139" height="41"></a> <a href="shop.php"><img src="shop.png" width="139" height="41"></a></th>
</tr>
</table>
<img src="maincontent.png" width="1000" height="1000" border="5" /> </div>
<div class="maincontent" align="center">
</div>
<div align="center" class="maincontentnews">
<p> </p>
<table width="800" height="500" border="1">
<tr>
<th valign="top" bgcolor="#FFFFFF" scope="col"><p> </p>
<?php
$ip = $_SERVER["REMOTE_ADDR"];
$logintries = 0;
$ipINdb = false;
$pass = mysql_real_escape_string($_POST['pazz']);
$accountName = mysql_real_escape_string($_POST['accName']);
$ip = mysql_real_escape_string($ip);
$con = mysql_connect("localhost", "marcus", "--------");
mysql_select_db("otserv", $con);
if(mysql_num_rows(mysql_query("SELECT ip FROM logintries WHERE ip = '" .$_SERVER["REMOTE_ADDR"]."'"))>0) {
$ipINdb = true;
$result = mysql_query("SELECT logintriez FROM `logintries` WHERE ip = '" .$_SERVER["REMOTE_ADDR"]."';");
while($row = mysql_fetch_row($result)) {
echo $row['logintries'];
}
}
else {
$ipINdb = false;
}
if(mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE name = '" .$accountName."';")) > 0) {
if(mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE password= '" . sha1($pass) . "';")) > 0) {
echo 'Logged in!';
session_start();
session_regenerate_id();
}
else {
die ("Wrong username or password.");
if($ipINdb == true) {
mysql_query("INSERT INTO `logintries` VALUES ('".$ip."', '".$logintries."'");
}
else {
mysql_query("UPDATE `logintries` SET logintriez = logintriez + 1 WHERE ip = '" .$_SERVER["REMOTE_ADDR"]."';");
}
}
}
else {
die ("Wrong username or password");
mysql_query("INSERT INTO `logintries` VALUES ('".$ip."', '".$logintries."'");
if($ipINdb == true) {
mysql_query("INSERT INTO `logintries` VALUES ('".$ip."', '".$logintries."'");
}
else {
mysql_query("UPDATE `logintries` SET logintriez = logintriez + 1 WHERE ip = '" .$_SERVER["REMOTE_ADDR"]."';");
}
}
?>
</th>
</tr>
</table>
</div>
</body>
</html>