[PHP][MSSQL]Select and Delete Statements

Experienced Elementalist
Joined
Sep 11, 2007
Messages
295
Reaction score
2
Hey Guys..

Well im having ALOT OF TROUBLE here and now im in desperate need in getting this done

can some one help me out a bit

this script is supposed to Search for the character name. If php finds the character name

odbc will fetch the row that the character's CID is in. Once it fetches the Character's CID well... it will search into the Table Called

Character Item

in character Item has the item id's for special weapons for a character. Once php finds the character item that corresponds with the correct CID of the row

it will delete the row and out put "row has been deleted"

But thats not happening for me unfortunately =[

here is the code

Code:
<form action = <?php $_SERVER['PHP_SELF']; ?> "?act=delete" method = "post">
<br>
<br>

Character Name: <input type="text" name="name"/>
<br>
<br>
Current Item ID To Delete:
<br><br>
<input type="text" name="id"/>
<br><br>
<input type="submit" Value="delete Item" name="delete"/>

</form>

PHP:
<?php

$dsn = 'GunZDB';
$user = '';
$pass = '';

$conn = odbc_connect($dsn, $user, $pass) or die ('Cannot Connect To MSSQL Server');

function antiinj($sql)
 {
$sql = strip_tags($sql);
$sql = htmlspecialchars($sql);
$sql = str_replace("'", "''", $sql);
$sql = str_replace("\"", "\"\"", $sql);
  }

 @$name = antiinj($_POST['name']);
 @$id = antiinj ($_POST['id']);

 $query = odbc_do($conn, "SELECT * FROM Character (nolock) Where (Name='$name')");
 odbc_fetch_row($query);
 $nick = odbc_result($query, (int)3);
 $CID = odbc_result ($query, (int)1);


 if($name == $nick)

{
 $sql = odbc_do($conn, "SELECT * FROM CharacterItem Where CID = '" . $CID . "'");
 odbc_fetch_row($sql);
 $itemdelete = odbc_result($sql, (int)2);
 odbc_result_all($sql);



}





?>

All im getting from ODBC_RESULT_ALL is

NO ROWS FOUND

so can some one sorta help xD i didnt finish the script because there is no point if php cannot find the row you want to work with.
 
PHP:
<?php

$dsn = 'gunzdb';
$user = '';
$pass = '';

$conn = odbc_connect($dsn, $user, $pass) or die ('cannot connect to mssql server');

function antiinj($sql)
 {
$sql = strip_tags($sql);
$sql = htmlspecialchars($sql);
$sql = str_replace("'", "''", $sql);
$sql = str_replace("\"", "\"\"", $sql);
  }
$name = antiinj($_post['name']);
$id = antiinj ($_post['id']);

 $query = odbc_do($conn, "select * from character (nolock) where name = '$name' ");
 odbc_fetch_row($query);
 $nick = odbc_result($query, (int)3);
 $cid = odbc_result ($query, (int)1);


 if($name == $nick)

{
$sql = odbc_do($conn, "delete * from characteritem where cid = '" . $cid . "'"); 
 odbc_fetch_row($sql);
 $itemdelete = odbc_result($sql, (int)2);
 odbc_result_all($sql);



}





?>

all im getting from odbc_result_all is

no rows found

so can some one sorta help xd i didnt finish the script because there is no point if php cannot find the row you want to work with.
try this
 
Last edited:
for the delete function... i want it to search for the item id also so i just put

AND ItemID = '$id'

btw does it matter where the delete function goes? in the if statement ?

thanks for the reply i will test as soon as i get home =]
 
Re:
PHP:
[MSSQL]Select and Delete Statements
for the delete function... i want it to search for the item id also so i just put

AND ItemID = '$id'[/quote]

that's correct.

[quote]btw does it matter where the delete function goes? in the if statement ?[/quote] 
I don't understand you correctly, I think the if statement [COLOR="Blue"]if($name == $nick)[/COLOR] it's redundant, the first select statement has a where clause doing the same thing.

[quote]All im getting from ODBC_RESULT_ALL is

NO ROWS FOUND[/quote]
First thing you should do, always you get a problem like this, is print out the complete select statement and run it on SQL query analyzer, check them there it's easier, maybe there is no item for that character in the table.

Corrected script:
[php]   <?php

$dsn = 'gunzdb';
$user = '';
$pass = '';

$conn = odbc_connect($dsn, $user, $pass) or die ('cannot connect to mssql server');

function antiinj($sql)
 {
$sql = strip_tags($sql);
$sql = htmlspecialchars($sql);
$sql = str_replace("'", "''", $sql);
$sql = str_replace("\"", "\"\"", $sql);
  }
$name = antiinj($_post['name']);
$id = antiinj ($_post['id']);

 $query = odbc_do($conn, "select * from character (nolock) where name = '$name' ");
 if(odbc_fetch_row($query))
{
     $cid = odbc_result ($query, (int)1);
     $sql = odbc_do($conn, "delete from characteritem where cid = '" . $cid . "'"); 
     $deleted_items = odbc_num_rows($sql);
     if($deleted_items)
    {
        //print out that there where no items to delete for that character
     }
     else
     {
        //print out how many items where deleted.
      } 
}
else
{
//print out that the character does not exists.
}

?>
 
Back