Jump to content

Should be a easy fix.. Help please

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
I am trying to make a DELETE button. Well when i click refresh it deletes its self.. also an error at the bottom before it deletes..

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\kazi\user.php on line 12


<?php

include("header.inc");

if(!$_GET['view']) 

    {

	header("location:index.php");

	}

else

{

$query = "SELECT * FROM profiles where ID = ". $_GET['view'];

$result = mysql_query($query, @mysql_connect(DB_SERVER, DB_USER, DB_PASS)) or die(mysql_error());

	

	for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1)

	{

		$ID = mysql_result($result, $i, "ID");

		$name = mysql_result($result, $i, "name");

		$image_news = mysql_result($result, $i, "image");

		$body = mysql_result($result, $i, "body");

		$body = nl2br($body);

		$date = mysql_result($result, $i, "Date");

		$show_date = date("M/d/Y", $date);

		$extra = mysql_result($result, $i, "extra");

		$iwidth = mysql_result($result, $i, "iwidth");

		$iheight = mysql_result($result, $i, "iheight");

		$ewidth = mysql_result($result, $i, "ewidth");

		$eheight = mysql_result($result, $i, "eheight");

?>


<link href="style.css" rel="stylesheet" type="text/css">

<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td align="center" valign="top"><div align="center" class="name"><?php echo($name); ?> </div></td>

  </tr>

  <tr>

    <td align="left" valign="top">

	<div align="left" class="body">

      <p>

	  <?php

	  ?>

	  <img src="<?php echo($image_news); ?>" width="<?php echo($ewidth); ?>" height="<?php echo($eheight); ?>" align="left" /><?php echo($body); ?></p>

      </div></td>

  </tr>

  <tr>

    <td align="left" valign="top"><div align="center"><img src="<?php echo($extra); ?>" width="<?php echo($iwidth); ?>" height="<?php echo($iheight); ?>" align="center" /></div></td>

  </tr>

  <tr>

    <td align="left" valign="top"><div align="center">

      <form id="for1" name="form" method="post" action="<?php

	  $query = "DELETE FROM profiles WHERE ID = ".$ID;

	  $result = mysql_query($query, @mysql_connect(DB_SERVER, DB_USER, DB_PASS)) or die(mysql_error()); ?>">

        <input type="submit" name="Submit" value="Submit" />

      </form>

      </div></td>

  </tr>

</table>

<?php

}

}

include("footer.inc");

?>


#2
Guest_Jaan_*

Guest_Jaan_*
  • Guests
<?php
include("header.inc");
if(!$_GET['view']) 
    {
    header("location:index.php");
    }
else
{
$query = "SELECT * FROM profiles where ID = ". $_GET['view'];
$result = mysql_query($query, @mysql_connect(DB_SERVER, DB_USER, DB_PASS)) or die(mysql_error());
    
    for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1)
    {
        $ID = mysql_result($result, $i, "ID");
        $name = mysql_result($result, $i, "name");
        $image_news = mysql_result($result, $i, "image");
        $body = mysql_result($result, $i, "body");
        $body = nl2br($body);
        $date = mysql_result($result, $i, "Date");
        $show_date = date("M/d/Y", $date);
        $extra = mysql_result($result, $i, "extra");
        $iwidth = mysql_result($result, $i, "iwidth");
        $iheight = mysql_result($result, $i, "iheight");
        $ewidth = mysql_result($result, $i, "ewidth");
        $eheight = mysql_result($result, $i, "eheight");
?>

<link href="style.css" rel="stylesheet" type="text/css">
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="top"><div align="center" class="name"><?php echo($name); ?> </div></td>
  </tr>
  <tr>
    <td align="left" valign="top">
    <div align="left" class="body">
      <p>
      <?php
      ?>
      <img src="<?php echo($image_news); ?>" width="<?php echo($ewidth); ?>" height="<?php echo($eheight); ?>" align="left" /><?php echo($body); ?></p>
      </div></td>
  </tr>
  <tr>
    <td align="left" valign="top"><div align="center"><img src="<?php echo($extra); ?>" width="<?php echo($iwidth); ?>" height="<?php echo($iheight); ?>" align="center" /></div></td>
  </tr>
  <tr>
    <td align="left" valign="top"><div align="center">
    <?php
	$submit = $_GET['Submit'];
	$act = $_GET['act'];
	if(isset($submit) && (isset($act) && $act == "del")){
	$query = "DELETE FROM profiles WHERE ID = ".$ID;
    $result = mysql_query($query, @mysql_connect(DB_SERVER, DB_USER, DB_PASS)) or die(mysql_error());
	}
	?>
      <form id="for1" name="form" method="post" action="?act=del">
        <input type="submit" name="Submit" value="Submit" />
      </form>
      </div></td>
  </tr>
</table>
<?php
}
}
include("footer.inc");
?>  

this should fix that deleting problemo..

and this error tells you that there's something wrong with your query.. it can't get info from it

#3
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
Man it didn't work :( If you get this before me let me know how to fix.. But i will toy around with it till you get this message =D

EDIT:

I think this doesn't work because i am already on a view.. At the top its $_GET['view'].. so it cant add another view to it?

#4
Guest_Jaan_*

Guest_Jaan_*
  • Guests
uumm.. wierd..
but.. well.. you can add more words next to view..

blabla.php?view=something&anotherview=anothersomething&andso=on

Quote

Well when i click refresh it deletes its self

it's deleting it because you're submitting it again and again.. don't press refresh ;)

#5
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
Still not working.. it goes to user.php?view=13&act=del and all of that but nothing happens..
I also put die() inside the if statement and nothing happened so
isset($submit) && (isset($act) && $act == "del")
is comming up false.. =(

<?php

include("header.inc");

if(!$_GET['view']) 

    {

    header("location:index.php");

    }

else

{

$query = "SELECT * FROM profiles where ID = ". $_GET['view'];

$result = mysql_query($query, @mysql_connect(DB_SERVER, DB_USER, DB_PASS)) or die(mysql_error());

    

    for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1)

    {

        $ID = mysql_result($result, $i, "ID");

        $name = mysql_result($result, $i, "name");

        $image_news = mysql_result($result, $i, "image");

        $body = mysql_result($result, $i, "body");

        $body = nl2br($body);

        $date = mysql_result($result, $i, "Date");

        $show_date = date("M/d/Y", $date);

        $extra = mysql_result($result, $i, "extra");

        $iwidth = mysql_result($result, $i, "iwidth");

        $iheight = mysql_result($result, $i, "iheight");

        $ewidth = mysql_result($result, $i, "ewidth");

        $eheight = mysql_result($result, $i, "eheight");

?>


<link href="style.css" rel="stylesheet" type="text/css">

<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td align="center" valign="top"><div align="center" class="name"><?php echo($name); ?> </div></td>

  </tr>

  <tr>

    <td align="left" valign="top">

    <div align="left" class="body">

      <p>

      <?php

      ?>

      <img src="<?php echo($image_news); ?>" width="<?php echo($ewidth); ?>" height="<?php echo($eheight); ?>" align="left" /><?php echo($body); ?></p>

      </div></td>

  </tr>

  <tr>

    <td align="left" valign="top"><div align="center"><img src="<?php echo($extra); ?>" width="<?php echo($iwidth); ?>" height="<?php echo($iheight); ?>" align="center" /></div></td>

  </tr>

  <tr>

    <td align="left" valign="top"><div align="center">

    <?php

	if($session->isAdmin()){

    $submit = $_GET['Submit'];

    $act = $_GET['act'];

    if(isset($submit) && (isset($act) && $act == "del")){

    $query = "DELETE FROM profiles WHERE ID = ".$ID;

    $result = mysql_query($query, @mysql_connect(DB_SERVER, DB_USER, DB_PASS)) or die(mysql_error());

    }

    ?>

      <br />

	  <form id="for1" name="form" method="post" action="<?php echo("user.php?view=$ID&act=del"); ?>">

        <input type="submit" name="Submit" value="Submit" />

      </form>

	 <?php

	 }

	 ?>

      </div></td>

  </tr>

</table>

<?php

}

}

include("footer.inc");

?>