[PHP][ODBC][Help]No Rows Found in PHP query
PHP Code:
<?php
$dsn = 'GunzDB';
$user = '';
$pass = '';
$conn = odbc_connect($dsn , $user , $pass);
if(!$conn)
{
die("Error Connecting To Database");
}
/*Anti Injection Method Coded by Girbicid */
function antiinj($valor)
{
$valor1 = str_replace("'","''",$valor);
$banlist = array("insert", "select", "update", "delete", "distinct", "having", "truncate", "replace","handler", "like", "exec", "order by", "group by", "from", "where", "--", "*");
$valor2 = trim ( str_replace ( $banlist, '', strtolower ($valor1) ) );
if (strtolower($valor1) == $valor2){
return $valor1; }else{return $valor2;} }
@$name = antiinj($_POST['name']);
@$item = antiinj($_POST['item']);
if(empty($name))
{
die ("Please Input Character's Name");
}
echo "<br>";
if(empty($item))
{
die("Please Input ItemID");
}
if(!empty($name) && !empty($item))
{
$query = "SELECT * FROM Character Where Name = '$name'";
$exec=odbc_do($conn, $query);
$cid = odbc_result($exec, (int)1);
odbc_result_all($exec); //Out Puts NO ROWS FOUND
}
?>
Ok guys im working on a deletion item script. The items i want to delete are in the table dbo.CharacterItem. (using mssql)
and the cid to search for the character's ItemID is in db.Character
so i have to fetch the cid from the dbo.character that correspondnds with the character name in the character table to match the cid in the CharacterItem Table
like this
here are the tables in the db.
Code:
CID AID Name
1 3 Sniper
<--Character
Code:
CCID CID ItemID
1 1 2015
CharacterItem
I want to delete that row but. it must corresponds with the character cid
if its possible to update that row with a new item id also
help is greatly appreciated =]
Re: [PHP][ODBC][Help]No Rows Found in PHP query
Well I don't use MsSQL, so I don't really know, but usually when dealing arrays, 0 is the first item.
PHP Code:
$cid = odbc_result($exec, (int)0);
Though I'm not sure because I never use MsSQL..
Re: [PHP][ODBC][Help]No Rows Found in PHP query
Quote:
Originally Posted by
s-p-n
Well I don't use MsSQL, so I don't really know, but usually when dealing arrays, 0 is the first item.
PHP Code:
$cid = odbc_result($exec, (int)0);
Though I'm not sure because I never use MsSQL..
isnt mssql queries the same as mysql queries?
TY IT WOKRS!!!!! =]
Re: [PHP][ODBC][Help]No Rows Found in PHP query
I can't handle some of Microsoft's code design with anything. It's different. Like in JavaScript, 99% of the time I need to optimize for IE, I don't know what I'm even doing. I'm just going with the flow from knowing snippet a.) does a certain thing, and snippet b.) does another. I don't really get what their functions mean, and I find it very hard to understand. I started with Flash, so my program logic is reversed from Microsoft, though it tends to keep in line with PHP, Java, and open source languages pretty well.
Like the odbc stuff, I have no idea what they mean by it.. I know what ob_flush() and ob_get_contents() do and those things, but I just don't get some of the things.
So like, you know how you have to strip out the words "having" and "distinct"? Well what if a user types those words in they're text? How would you conserve those key, popular terms within a sentence while protecting from injections? I would design things much differently, and part of my adversarial attitude prevents me from learning their special code.
I have issues, I suppose. ;)
The queries do look exactly the same though, it's just the way you talk to the database that gets me. Well the queries also do get little different, and when they do, I get lost with that as well ;)
Re: [PHP][ODBC][Help]No Rows Found in PHP query
oh wow
so you have been web developing for years now i guess ..ive only web developing for 3 months.. =\
well im getting another problem i had to adjust the code to fit the idea i want to do ..
PHP Code:
$query = odbc_do($conn,"SELECT * FROM Character Where Name = '$name'");
odbc_fetch_row($query);
$cid=odbc_result($query, (int)0);
odbc_result_all($query); //outputs NO ROWS FOUND
any help?
Code:
Warning: odbc_result() [function.odbc-result]: Field index is larger than the number of fields in C:\wamp\www\project\donor\delete.php on line 63
Re: [PHP][ODBC][Help]No Rows Found in PHP query
Lol, okay I looked it up. I was wrong at my attempts to figure it out by winging it.
http://us2.php.net/manual/en/function.odbc-result.php
odbc_result($result_id, $field);
Quote:
Originally Posted by PHP.net
The field name being retrieved. It can either be an integer containing the column number of the field you want; or it can be a string containing the name of the field.
So it would be,
PHP Code:
odbc_result($result, (string) 'CID');
Right?
[edit] Or wait, woudn't 0, and the first field 'CID' be the same thing?
Re: [PHP][ODBC][Help]No Rows Found in PHP query
well come to think of it
0 isnt a column choice thats why php was giving us that error
so its 1 is the cid row
what do you mean by (string) ?.
the odbc_do function?
btw thanks for helping me out =]
so it would be
PHP Code:
$query = odbc_do($conn,"SELECT * FROM Character Where Name = '$name'");
odbc_fetch_row($query);
$cid=odbc_result($query, 'CID');
odbc_result_all($query); // Still....outputs NO ROWS FOUND =[
doesnt output my character row =[
my character row is
CID = 1
AID = 5
Name = Sniper
so its supposed to out put in a table
CID AID Name
1 5 Sniper
Re: [PHP][ODBC][Help]No Rows Found in PHP query
Code:
$query = odbc_do($conn,"SELECT TOP 1000 CID, AID, Name FROM Character Where Name = '$name'");
while( odbc_fetch_row($query) )
{
printf(odbc_result($query, 1), odbc_result($query, 2), odbc_result($query, 3));
}
Hope this shld work
Edit :-
Nice antiSql you got there
Re: [PHP][ODBC][Help]No Rows Found in PHP query
thanks i didnt code the antisql tho...Girbicid did =]
i will test later and i will edit my post saying that it worked
thanks =]
EDIT IT WORKS!!!
THANK YOU!!