Hallo Leute
Ich habe hier ein PHP-Skript .. allerdings passiert nix wenn ich auf den Button "Register" klicke.
Ich hoffe ihr könnt euch Zeit nehmen und den Fehler villeicht finden.
Wie gesagt .. es passiert nichts, eigentlich sollte ein Eintrag in die Datenbank gemacht werde :c
Bin noch ein Anfänger in PHP Sachen ..
Mit freundlichen Grüßen.
Ich habe hier ein PHP-Skript .. allerdings passiert nix wenn ich auf den Button "Register" klicke.
PHP-Code:
<?php
// CONFIG
$_Config['Debug'] = true;
$_Config['SQL']['Host'] = 'SERVERNAME\SQLEXPRESS';
$_Config['SQL']['User'] = 'sa';
$_Config['SQL']['Pass'] = 'password';
$_Config['SQL']['Database'] = 'database';
$_Config['SQL_Error_Display'] = true;
if (isset($_POST['reg']))
{
function ValidE( $email ){
return filter_var( $email, FILTER_VALIDATE_EMAIL );
}
function generateSalt()
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < 10; $i++)
{
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
class ES_Database
{
public $conn = NULL;
private $query = NULL;
private $sql_resource = NULL;
public $query_count = 0;
private $query_parameters = array();
private $_Config = NULL;
//Construct
public function ES_Database()
{
global $_Config;
$this->_Config = $_Config;
//$this->Connect($db);
}
public function Connect($db)
{
//Build the connection array
$conn_array = array( "UID" => $this->_Config['SQL']['User'] , "PWD" => $this->_Config['SQL']['Pass'] , "Database" => $db );
//Connect or die
$this->conn = sqlsrv_connect( $this->_Config['SQL']['Host'] , $conn_array ) or $this->OnDBError();
}
public function OnDBError()
{
if( $this->_Config['SQL_Error_Display'] )
{
$k = (array) sqlsrv_errors();
foreach( $k as $error => $message )
{
echo "[$error] " . $message[2] . "<br>" ;
}
}
}
public function query( $sql , $type = 0 )
{
if( $type == 0 )
{
$type = array( "Scrollable" => 'forward' );
}
elseif( $type == 1 )
{
$type = array( "Scrollable" => 'static' );
}
elseif( $type == 2 )
{
$type = array( "Scrollable" => 'dynamic' );
}
elseif( $type == 3 )
{
$type = array( "Scrollable" => 'keyset' );
}
elseif( $type == 4 )
{
$type = array( "Scrollable" => 'buffered' );
}
$this->query = $sql;
$this->sql_resource = sqlsrv_query( $this->conn , $this->query , array() , $type );
if( ! $this->sql_resource )
{
$this->OnDbError();
}
$this->query_count++;
}
public function fetchResult()
{
if( $this->sql_resource )
{
sqlsrv_fetch( $this->sql_resource );
$k = sqlsrv_get_field( $this->sql_resource , 0 );
$this->Free();
return $k;
}
else
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "There is nothing to fetch or there was an error with your query. - " , __FUNCTION__ ;
}
}
$this->sql_resource = NULL;
}
public function fetchAssoc()
{
if( $this->sql_resource )
{
$r = Array();
$count = 0;
$stop = false;
/*$k = sqlsrv_fetch_array( $this->sql_resource );
$this->Free();
return $k;*/
while (!$stop)
{
$row = sqlsrv_fetch_array($this->sql_resource);
if ($row === false) die("Account has been registered.");
$stop = !$row;
if (!$stop) $r[$count] = $row;
$count++;
}
return $r;
}
else
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "There is nothing to fetch or there was an error with your query. - " , __FUNCTION__ ;
}
}
$this->sql_resource = NULL;
}
public function fetchObject($silent = false)
{
if( $this->sql_resource )
{
$k = sqlsrv_fetch_object( $this->sql_resource );
$this->Free();
return $k;
}
else
{
if( $this->_Config['SQL_Error_Display'] )
{
if (!$silent)
echo "There is nothing to fetch or an error with your query. - " , __FUNCTION__;
}
}
$this->sql_resource = NULL;
}
public function prepare( $sql , array $parameters )
{
$this->query = $sql;
$this->query_parameters = $parameters;
$arr = array();
foreach( $this->query_parameters as $key => $value )
{
$arr[$key] = &$this->query_parameters[$key];
}
$this->sql_resource = sqlsrv_prepare( $this->conn , $this->query , $arr );
$this->query_count++;
if( ! $this->sql_resource )
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "Prepared statement failed, check your query.";
}
}
}
public function execute()
{
if( $this->sql_resource )
{
return sqlsrv_execute( $this->sql_resource );
}
else
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "There is nothing to execute or an error with your prepared statement.";
}
}
}
public function prepareAndFetch( $sql , array $parameters , $type = 0 )
{
$this->prepare( $sql , $parameters );
$this->execute();
if( $type == 0 )
{
return $this->fetchAssoc();
}
elseif( $type == 1 )
{
return $this->fetchResult();
}
elseif( $type == 2 )
{
return $this->fetchObject();
}
}
public function prepareAndExecute( $sql , array $parameters , $type = 0 )
{
$this->prepare( $sql , $parameters );
$this->execute();
}
public function queryAndFetch( $sql , $type = 0 , $pquery = false , $parameters = NULL )
{
if( $pquery == false )
{
$this->query( $sql );
}
else
{
$this->pquery( $sql , $parameters );
}
if( $type == 0 )
{
return $this->fetchAssoc();
}
elseif( $type == 1 )
{
return $this->fetchResult();
}
elseif( $type == 2 )
{
return $this->fetchObject();
}
}
public function NumRows()
{
if( $this->sql_resource )
{
return sqlsrv_num_rows( $this->sql_resource );
}
else
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "There is no query set or an error with your query. - " , __FUNCTION__;
}
}
}
public function pquery( $sql , array $parameters , $type = 0 )
{
if( $type == 1 )
{
$type = array( "Scrollable" => 'forward' );
}
elseif( $type == 2 )
{
$type = array( "Scrollable" => 'static' );
}
elseif( $type == 3 )
{
$type = array( "Scrollable" => 'dynamic' );
}
elseif( $type == 4 )
{
$type = array( "Scrollable" => 'keyset' );
}
elseif( $type == 5 )
{
$type = array( "Scrollable" => 'buffered' );
}
else
{
unset( $type );
}
$this->query = $sql;
if( isset( $type ) )
{
$this->sql_resource = sqlsrv_query( $this->conn , $this->query , $parameters , $type );
}
else
{
$this->sql_resource = sqlsrv_query( $this->conn , $this->query , $parameters );
}
if( ! $this->sql_resource )
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "Query Failed";
}
}
$this->query_count++;
}
public function HasRows()
{
if( $this->sql_resource )
{
return sqlsrv_has_rows( $this->sql_resource );
}
else
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "There is no query set or an error with your query. - " , __FUNCTION__;
}
}
}
public function RowsAffected()
{
if( $this->sql_resource )
{
return sqlsrv_rows_affected( $this->sql_resource );
}
else
{
if( $this->_Config['SQL_Error_Display'] )
{
echo "There is no query set or an error with your query.";
}
}
}
public function Free()
{
$this->query = NULL;
$this->query_parameters = array();
if( $this->sql_resource )
{
sqlsrv_free_stmt( $this->sql_resource );
}
}
public function Disconnect()
{
( $this->conn == NULL ) ? NULL : sqlsrv_close( $this->conn );
}
public function Escape( $str )
{
$str = str_replace( "'", "''", $str );
return trim( $str );
}
}
function error($s)
{
echo $s;
exit;
}
if (!isset($_POST['user']) || !isset($_POST['pass']) || !isset($_POST['email']))
{
}
$sUser = $_POST['user'];
$sPass = $_POST['pass'];
$sEmail = $_POST['email'];
if (!ctype_alnum($sUser))
{
error("Invalid Username. Alpha-Numeric characters only.");
}
if (!ctype_alnum($sPass))
{
error("Invalid Password. Alpha-Numeric characters only.");
}
if (!ValidE($sEmail))
{
error("Invalid Username. Alpha-Numeric characters only.");
}
if (strlen($sUser) <= 3)
{
error("Invalid Username. Must be atleast 4 characters.");
}
if (strlen($sPass) <= 3)
{
error("Invalid Password. Must be atleast 4 characters.");
}
$DB = new ES_Database();
$DB->connect($_Config['SQL']['Database']);
$TopUserArray = $DB->queryAndFetch("SELECT TOP 1 * FROM tAccounts ORDER BY nEMID DESC", 0, true, array());
$UserExistArray = $DB->queryAndFetch("SELECT * FROM tAccounts WHERE sUsername = ?", 0, true, array($sUser));
if (count($TopUserArray) == 0)
{
$nID = 1;
}
else
{
$nID = $TopUserArray[0]['nEMID'];
}
if(count($UserExistArray) > 0)
{
error("Username already taken, please try again.");
die();
}
$nID = intval($nID) + 1;
$sSalt = generateSalt();
$sSafePass = MD5(MD5($sPass) . $sSalt);
$sIP = $_SERVER['REMOTE_ADDR'];
$params = array( $nID , $sUser , $sPass , $sSalt , $sEmail, $sIP );
$sql = "INSERT INTO tAccounts([Spalte],[Spalte],[Spalte],[Spalte],[Spalte],[Spalte],[Spalte],[Spalte],[Spalte]) VALUES ( ? , ? , ? , ? , ? , 1 , ? , CURRENT_TIMESTAMP, '-' );";
$DB->queryAndFetch($sql, 0, true, $params);
die("Your account has been created!");
exit;
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="link">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center>
<div id="login">
<form name="loginform" id="loginform" action="#" method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="modal-logo"></div>
<fieldset id="max">
<div class="control-group">
<div class="controls">
<input type="text" name="user" id="user" class="input" value="Username" style="height:2em" />
</p>
<p>
<div class="control-group">
<div class="controls">
<input type="password" name="pass" id="pass" class="input" value="Password" style="height:2em" />
</div>
</div>
</p>
<p>
<div class="control-group">
<div class="controls">
<input type="text" name="email" id="email" class="input" value="Email" style="height:2em" />
</div>
</div>
</p>
<p class="submit">
<input type="button" id="GoBtn" class="btn btn-large btn-block btn-cupid-green" onClick="doSignup()" value="Register" tabindex="100" style="width:15em" />
</p>
</fieldset>
</center>
</div>
</div>
</div>
</div>
</div></form><br><br><script language = "javascript">
function doSignup()
{
user = document.getElementById("user").value;
pass = document.getElementById("pass").value;
email = document.getElementById("email").value;
xUrl = "?r=" + Math.floor(Math.random()*132165321);
document.getElementById("registerform").innerHTML = "<br><br><center><img src='/images/loading.gif'><br><br>";
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
setTimeout("ShowResponse(xmlhttp.responseText)",2000);
}
}
xmlhttp.open("POST", xUrl, true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("reg=1&user=" + user + "&pass=" + pass + "&email=" + email);
if (navigator.userAgent.indexOf("Firefox") != -1)
{
setTimeout("ShowResponse(xmlhttp.responseText)",2000);
}
}
function ResetForm(u)
{
window.location = window.location;
}
function ShowResponse(ResponseText)
{
alert(ResponseText);
window.location = window.location;
}
</script>
</div>
</body>
</html>
Wie gesagt .. es passiert nichts, eigentlich sollte ein Eintrag in die Datenbank gemacht werde :c
Bin noch ein Anfänger in PHP Sachen ..
Mit freundlichen Grüßen.
Kommentar