8 Replies - 952 Views - Last Post: 21 July 2016 - 04:41 AM Rate Topic: -----

#1 kentasoro   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-July 16

Need help from old php to new php pdo

Posted 18 July 2016 - 07:30 PM

i have no idea how to recode this with new pdo..
index
<?php

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

include_once 'dbConnect.php';

if(isset($_POST['signup_btn'])) {
$username = $_POST['username'];
$password = $_POST['password'];

if(mssql_query("INSERT INTO dnmembership.dbo.Accounts (AccountName, AccountLevelCode, GameOption, CharacterCreateLimit, LastCharacterCreateDate, CharacterMaxCount, LastLoginDate, LastLogoutDate, LastLoginIP, LastSessionID, JoinIP, RegisterDate, PublisherCode, GenderCode, BirthDate, Passphrase, NationalityCode, ChannelPartnerCode,NxLoginPwd)VALUES ('$username', '0', NULL, '7', NULL, '4', NULL, NULL, NULL, NULL, NULL, GETDATE(), '4', NULL, NULL, NULL, NULL, NULL, (SELECT substring(sys.fn_VarBinToHexStr(hashbytes('MD5','$password')),3,32)))")){
header("Location: home.php");
echo("Registration Successful");
}
else{
echo("Registration Failed");
}

}
?>
<?php
session_start();
include_once 'dbconnect.php';

if(isset($_SESSION['user'])!="")
{
    header("Location: home.php");
}
if(isset($_POST['login_btn']))
{
    $username = $_POST['username'];
    $password = $_POST['password'];

    $query = "SELECT * FROM dnmembership.dbo.Accounts WHERE AccountName='$username'";

    $response = mssql_query($query);
    $row = mssql_fetch_array($response);

    if($row['NxLoginPwd']==md5($password))
    {
        $_SESSION['user'] = $row['AccountName'];
        header("Location: home.php");
    }
    else{
        echo("Wrong Credentials");
    }

}
?>




<doctype html>
<header>
	<title>TsukiDN</title>
<link href="css/main.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<img src="images/bg.png" id="bg" alt="">
<nav>
	<ul class="nav nav-pills">
		<li role="presentation" class="active"><a href="#">Home</a></li>
			<li><a href="#">Download</a></li>
			<li><a href="https://www.facebook.com/groups/1606566483004459/">Facebook</a></li>
	</ul>
</nav>
</header>

	<body>
		

				<div class="col-sm-2 col-xs-2">
					<div class="panel panel-default">
					<div class="panel-heading"><b>Register|Login</b></div>
					<div class="panel-body">
					<div>
						<form method="post">
						<table align="left" border="0px" >
						<tr>
							<td><input type="text" name="username" placeholder="username" required /></td>
						</tr>
							<td><input type="password" name="password" placeholder="password" required /></td>
							<button class="l btn btn-default" type="submit" name="login_btn">Login</button>
							<button class="l btn btn-default" type="submit" name="signup_btn">Sign Up</button>
						</table>
						</form>
				</div>
			</div>
		</div>
	</div>
	
<div class="col-sm-5 col-xs-6">
				<div class="p panel panel-primary">
				<div class="panel-heading"><b>Welcome</b></div>
				<div class="panel-body">
				<center>
				<p>Welcome to TsukiDN !</p>
				<p><img src="images/post1.jpg" class="postimg" alt=""></p>
				</center>
		</div>
	</div>
</div>
 

	</body>
	
	<footer>
	</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: Need help from old php to new php pdo

#2 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3151
  • View blog
  • Posts: 11,956
  • Joined: 03-December 12

Re: Need help from old php to new php pdo

Posted 18 July 2016 - 07:54 PM

First step, there is a well done PDO tutorial in my signature.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,573
  • Joined: 08-June 10

Re: Need help from old php to new php pdo

Posted 19 July 2016 - 12:56 AM

note: MD5 is not a secure hash for passwords. use PHP's password_hash()!
Was This Post Helpful? 0
  • +
  • -

#4 kentasoro   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-July 16

Re: Need help from old php to new php pdo

Posted 19 July 2016 - 01:50 AM

my database for game is in MD5, also i get error with php pdo

Quote

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

<?php
$hostdb = '.\SQLExpress';
$namedb = 'DNMEMBERSHIP';
$userdb = 'DragonNest';
$passdb = 'FD9D60B133f498b';

try {
  $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
  echo 'Connected to database';
}
catch(PDOException $e) {
  echo $e->getMessage();
}
?>

Was This Post Helpful? 0
  • +
  • -

#5 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3151
  • View blog
  • Posts: 11,956
  • Joined: 03-December 12

Re: Need help from old php to new php pdo

Posted 19 July 2016 - 04:39 AM

connectionstrings.com
Was This Post Helpful? 0
  • +
  • -

#6 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4241
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Need help from old php to new php pdo

Posted 19 July 2016 - 06:48 AM

View Postkentasoro, on 19 July 2016 - 08:50 AM, said:

my database for game is in MD5

It's still not a good enough hashing algorithm. Not even close.
Look at: Update Users Passwords To A More Secure Hash, Secretly.


View Postkentasoro, on 19 July 2016 - 08:50 AM, said:

also i get error with php pdo

Quote

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

Look closely at your PDO connection string:
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);


Given that you're using Microsoft SQL Server, starting the connection string with the word "MySQL" is not likely to work. PDO works with a number of databases, but you need to pick the right driver; the MySQL driver doesn't work for all of them.

See the manual entry for the PDO_SQLSRV driver, and check out this example code in Microsoft's docs for it. That should get you down the right path.
Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3837
  • View blog
  • Posts: 13,998
  • Joined: 08-August 08

Re: Need help from old php to new php pdo

Posted 20 July 2016 - 04:14 AM

Why are you escaping the "S" in $hostdb = '.\SQLExpress';?
Was This Post Helpful? 0
  • +
  • -

#8 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4241
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Need help from old php to new php pdo

Posted 20 July 2016 - 05:10 AM

I don't know much about SQLExpress databases, but it's probably just the Windows "current directory" path symbol.

The "S" isn't being escaped there, in any case.

Most escape sequences aren't recognized in single-quoted strings. Only \' and \\. Everything else is printed literally.

\S also has no special meaning in double-quoted strings, so (as of 5.1) it will be printed literally there too.
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3837
  • View blog
  • Posts: 13,998
  • Joined: 08-August 08

Re: Need help from old php to new php pdo

Posted 21 July 2016 - 04:41 AM

Yes, but there is no "Windows" on the internet. The single quote means the escape sequence will not be executed by PHP, but passed (printed literally) to the MySQL server, where it will attempt to escape and fail. The correct path should be $hostdb = './SQLExpress';.

Hmm, since SQLExpress is a Microsoft product and they clearly think anything they do is automatically a standard, it's possible they've chosen to force their pathnames on the web. So glad I don't have to deal with that!

This post has been edited by CTphpnwb: 21 July 2016 - 04:46 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1