Hello Friends,

i return a database connectivity like this.

function db_conn()
{
  $mysqli = new mysqli("localhost", "root", "", "test");
  if (mysqli_connect_errno()) 
  {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
  }
  return $mysqli;
}

with this upto now i used to insert records successfully. but now i have an problem with Delete and Update records.

the query i retrurned to delete records

if(!empty($_POST['del_btn']) && $_POST['del_btn'] == 'Delete')
{

  $delids =  explode('`#`',$_POST[delid]); 
  for($x=0;$x<count($delids);$x++)
  {
    if(isset($_POST['del_'.$delids[$x]]) && $_POST['del_'.$delids[$x]]!='')
 {
// mysqli_query($mysqli, "DELETE FROM resource_tasks where id=".$delids);
//printf("Affected rows (DELETE): %d\n", mysqli_affected_rows($link));
    $dquery = "delete from resource_tasks where id=".$delids;
   //echo $dquery;exit;
	$dresp    =  mysqli_query($dquery);
	//printf("Affected rows (DELETE): %d\n", mysqli_affected_rows($mysqli)); exit;
    $affecrows = mysqli_affected_rows($dquery);
 }//end of if
  //onClick="alert(document.form1.length);"
  }///end of for
  echo $affecrows;exit;
 //if($affecrows > 0)
  if($dresp)
	{
		echo '<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=report_form.php?res=1">';
		exit;
	}
	else
	{
		echo '<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=report_form.php?res=2">';
		exit;
	}
}

but it showing warnings like this
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\mis\timesheets\report.php on line 16

Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\mis\timesheets\report.php on line 18

so plz can anybody help on this soon.

iam using to delete multiple records by putting in array but iam geeting this error.

Array ( [del_60] => 60 [del_80] => 80 [del_btn] => Delete [delid] => 71`#`61`#`51`#`41`#`31`#`21`#`11`#`1`#`32`#`42`#`22`#`52`#`62`#`2`#`12`#`72`#`63`#`33`#`53`#`73`#`43`#`23`#`3`#`13`#`44`#`64`#`4`#`54`#`34`#`74`#`24`#`14`#`75`#`15`#`35`#`25`#`55`#`45`#`5`#`65`#`76`#`56`#`66`#`26`#`16`#`46`#`6`#`36`#`47`#`77`#`17`#`67`#`27`#`7`#`57`#`37`#`68`#`48`#`28`#`18`#`38`#`78`#`8`#`58`#`39`#`49`#`29`#`69`#`9`#`19`#`59`#`79`#`30`#`10`#`70`#`40`#`20`#`50`#`60`#`80 [project] => [start_date] => 2-5-2008 [end_date] => 5-9-2008 [groupby] => on ) Affected rows (DELETE): -1


can any body suggest .

if(!empty($_POST['del_btn']) && $_POST['del_btn'] == 'Delete')
{

  $delids =  explode('`#`',$_POST[delid]); 
  for($x=0;$x<count($delids);$x++)
  {
    if(isset($_POST['del_'.$delids[$x]]) && $_POST['del_'.$delids[$x]]!='')
 {
 
$delquery=mysqli_query($dbObj, "delete from resource_tasks where id=".$_POST['del_'.$delids[$x]]);
//printf("Affected rows (DELETE): %d\n", mysqli_affected_rows($dbObj));
//$affecrows = mysqli_affected_rows($dbObj);
//$dquery="delete from resource_tasks where id=".$delids;
$affecrows=mysqli_affected_rows($dbObj);
//echo $delquery;
 }//end of if
  //onClick="alert(document.form1.length);"
  }///end of for
//echo $affecrows;exit;
// if($affecrows > 0)
mysqli_close($dbObj);
 //if($delquery)
    if($affecrows > 0)
	{
		echo '<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=report_form.php?res=1">';
		exit;
	}
	else
	{
		echo '<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=report_form.php?res=2">';
		exit;
	}
}

this is the correct way now i found out.

This question has already been answered. Start a new discussion instead.