I have been trying to figure this out for hours but haven't succeeded. I'm making a registration page in PHP for a MSSQL Database. I figured out how to insert the username in the database, however I'm not sure how to check if it exists. Here's my code:
<?php
$server = "----";
$user = "----";
$pass = "----";
$db = "----";
$link = mssql_connect($server, $user, $pass);
$selected = mssql_select_db ($db, $link);
?>
--------------------------------
<html>
<head>
</head>
<body>
<center>
<form action="register.php" method="post">
<div style="border: 1px solid black; width:320px; font-family:arial;">
<center>
<table cellspacing="5">
<tr>
<td>Account:</td><td><input type="text" name="username" value="" /></td>
</tr>
<tr>
<td>Password:</td><td><input type="text" name="password" value="" /></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="submit" /></center></td>
</tr>
</table>
</center>
</div>
</form>
</center>
</body>
</html>
--------------------------------
<?php
require_once('config.php');
$username=$_POST['username'];
$password=$_POST['password'];
$query = "INSERT INTO Accounts (AccountName, Password) VALUES ('$username', '$password')";
//if username exists {}
//else {
$result = mssql_query($query);
// }
?>