ODBC未连接HTML/PHP
标题可能具有误导性。我为此道歉。 无论如何,我对SQL和ODBC感到困惑 在我的网站上,我正在尝试设置一个注册页面。 基本上,在运行MYSQL的专用服务器上,我设置了一些register.php文件,这样当一个人在站点上注册时,它就会被放入SQL中的某个数据库中。当我尝试注册时,odbc未连接是否需要添加新的数据源? html/php文件的示例:Register.phpODBC未连接HTML/PHP,php,html,mysql,web,odbc,Php,Html,Mysql,Web,Odbc,标题可能具有误导性。我为此道歉。 无论如何,我对SQL和ODBC感到困惑 在我的网站上,我正在尝试设置一个注册页面。 基本上,在运行MYSQL的专用服务器上,我设置了一些register.php文件,这样当一个人在站点上注册时,它就会被放入SQL中的某个数据库中。当我尝试注册时,odbc未连接是否需要添加新的数据源? html/php文件的示例:Register.php <?php $aw=$_GET["q"]; $aws=$_GET["q2"]; $awts=$_GET["q3"
<?php
$aw=$_GET["q"];
$aws=$_GET["q2"];
$awts=$_GET["q3"];
$conn = odbc_connect('USER_MEMBERDB','Test','Test123');
//$sql="SELECT * FROM chr_log_info WHERE id_loginid = '$q'";
if ($conn)
{
$query = "select * from chr_log_info where id_loginid = '$aw'";
//perform the query
$result=odbc_exec($conn, $query)or die("Error Here!");;
// $aw = mssql_escape_string($aw);
// $aws = mssql_escape_string($aws);
$slashRead1 = "";
$slashRead2 = "";
for($i = 0; $i < strlen($aw); $i++){
if($aw[$i] == '\\'){
$slashRead1 = 'yah';
}
}
for($i = 0; $i < strlen($aws); $i++){
if($aws[$i] == '\\'){
$slashRead2 = 'yah';
}
}
if(!empty($slashRead1) && !empty($slashRead2)){
echo "Username and Password values cannot be accepted. Please change your Username and Password!";
}else if(!empty($slashRead1)){
echo "Username value cannot be accepted. Please change your Username!";
}else if(!empty($slashRead2)){
echo "Password value cannot be accepted. Please change your Password!";
}else{
if(empty($aws)){
echo "Please fill-in the form completely!";
}else{
$count = 0;
//fetch tha data from the database by row
while(odbc_fetch_row($result)){
for($i=1;$i<=odbc_num_fields($result);$i++){
$row = odbc_result($result, $i);
if(!empty($row)){
$count++;
}
}
}
if(empty($aw)){
echo "Please fill-in the form completely!";
}else if($count != 0){
echo "Sorry, the username you entered is not available!";
}else if(strlen($aws) < 6){
echo "Please enter more than 6 characters for your password!";
}else{
$query1 = "Select id_idx from chr_log_info";
$result1=odbc_exec($conn, $query1)or die("Error Here!");;
while(odbc_fetch_row($result1)){
for($i=1;$i<=odbc_num_fields($result1);$i++){
$row = odbc_result($result1, $i);
}
}
$row++;
$query2 = "Select propid from chr_log_info";
$result2=odbc_exec($conn, $query2)or die("Error Here!");;
while(odbc_fetch_row($result2)){
for($i=1;$i<=odbc_num_fields($result2);$i++){
$row2 = odbc_result($result2, $i);
}
}
$row2++;
$query3 = "Insert into chr_log_info(id_idx, propid, id_loginid, id_passwd, id_sexType) values('$row', '$row2', '$aw', '$aws', '$awts')";
$result=odbc_exec($conn, $query3) or die("Error Here!");
echo "Congratulations! You have successfully registered!";
}
}
}
//close the connection
odbc_close ($conn);
}
else echo "odbc not connected";
?>
使用的另一个HTML文件是:responsexml.HTML
<?php
$q=$_GET["q"];
$conn = odbc_connect('USER_MEMBERDB','Test','Test123');
if ($conn)
{
$q = mysql_escape_string($q);
$slashRead = "";
for($i = 0; $i < strlen($q); $i++){
if($q[$i] == '\\'){
$slashRead = 'yah';
}
}
if(!empty($slashRead)){
echo "Username value cannot be accepted!";
}else{
//the SQL statement that will query the database
$query = "select * from chr_log_info where id_loginid = '$q'";
//perform the query
$result=odbc_exec($conn, $query) or die("Wrong!");
//fetch tha data from the database
$count = 0;
while($row = odbc_fetch_row($result))
{
for($i=1;$i<=odbc_num_fields($result);$i++)
{
$row = odbc_result($result, $i);
if(!empty($row)){
$count++;
}
}
}
if(empty($q)){
echo "";
}else if($count != 0){
echo "Sorry, the username is not available!";
}else{
echo "Username is available!";
}
}
//close the connection
odbc_close ($conn);
}
else echo "odbc not connected";
?>
我错过什么了吗?或者我需要为我的专用服务器下载某些驱动程序才能运行。有什么建议吗?我的假设是,odbc连接中的USER\u MEMBERDB是您尝试连接到的MSSQL数据库的名称
你可以试试:
// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
但是,我建议在ODBC上使用内置MSSQL函数:
$conn = mssql_connect('SERVER', 'username', 'password');
.html?您是否指示您的服务器将.html视为.php?您可以使用.php文件使用mysql\u connect而不是odbc\u connectMy bad,我的意思是放置.php,我更改了它。@priya786我更改了您告诉我的内容,但仍然没有连接。您还可以选择特定的数据库