samedi 28 février 2015

ODBC not connected HTML/PHP

The title may be misleading. I apologize for that. Anyways, I am confused about SQL and ODBC.


On my website, I am trying to setup a register page. Basically, on my dedicated server with MYSQL running on it, I setup some register.php files so that when a person registers on the site, it gets put into a certain database in SQL. When I try to register, I get "odbc not connected" Do I need to add a new data source? Example of the html/php file: "Register.php"



<?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";
?>


Another HTML file that is used is this: "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";
?>


Am I missing something? Or do I need to download certain drivers for my dedicated server for it to run. Any suggestions?





Aucun commentaire:

Enregistrer un commentaire