Jump to content


Photo

New problem...


  • Please log in to reply
2 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 27 August 2006 - 09:12 PM

I just posted a few minutes ago about a GET problem...It turns out that is wasn't a problem, just a warning...It is actually working fine...but my code is still not working...
the following snippet is supposed to update or delete a row in a MySQL database....

when I press either submit or delete I get the correct response, that is, is says "your shirt has been deleted", but nothing actually happens in the database...
any ideas....

Thanks!!!


<?php

include 'library/config.php';
include 'library/opendb.php';
error_reporting(0);


$shirt_id = $_GET['shirt_id'];

if(isset($_POST['delete'])) {

$query = "DELETE from shirts WHERE shirt_id='$shirt_id'";
mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

    echo "Your shirt has been deleted!";

}



elseif(isset($_POST['submit'])) {

  $name=$_POST['name'];
  $comment=$_POST['comment'];
  $link=$_POST['link'];
  $site=$_POST['site'];
  $image=$_POST['image'];
  $active=$_POST['active'];
  $commission=$_POST['commission'];

  $query="UPDATE shirts SET name='$name', comment='$comment', link='$link', site ='$site',
  image ='$image', active ='$active', commission ='$commission' WHERE shirt_id ='$shirt_id'";

  mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
    echo "Your shirt has been updated!";


} else

{


$data = mysql_query("SELECT * FROM shirts WHERE shirt_id ='$shirt_id'") or die(mysql_error());
$info = mysql_fetch_array( $data );

echo "<a href='admin.php'><img src='images/logo.gif' border='0'></a><br>
<form method='post' action='edit.php'>
<TABLE>
<TR>
  <TD>Name:</TD>
  <TD><INPUT TYPE='TEXT' NAME='name'  size=50 value='".$info['name']."'></TD>
</TR>
<TR>
  <TD>Comment</TD>
  <TD><textarea rows='5' cols='50' name='comment'>".$info['comment']."</textarea>
</TD>
</TR>
<TR>
  <TD>Link</TD>
  <TD><INPUT TYPE='TEXT' NAME='link'  size=50 value='".$info['link']."'></TD>
</TR>
<TR>
  <TD>Site</TD>
  <TD><INPUT TYPE='TEXT' NAME='site'  size=50 value='".$info['site']."'></TD>
</TR>
<TR>
  <TD>Image</TD>
  <TD><INPUT TYPE='TEXT' NAME='image'  size=50 value='".$info['image']."'></TD>
</TR>
<TR>
  <TD>Active</TD>";

if($info['image'] == 'true') {


echo

  "<TD><input type='radio' name='active' value='true' CHECKED> Active
<br>
<input type='radio' name='active' value='false'> Inactive
  </TD>";

  }


  else {

  echo "<TD><input type='radio' name='active' value='true' > Active
<br>
<input type='radio' name='active' value='false' CHECKED> Inactive
  </TD>";

  }

echo

"</TR>
<TR>
  <TD>Commission</TD>
  <TD><INPUT TYPE='TEXT' NAME='commission' size=50 value='".$info['commission']."'></TD>
</TR>
<TR>
  <TD></TD>

  <TD><INPUT TYPE='submit' name='submit' value='Edit this Tee'>
      <INPUT TYPE='submit' name='delete' value=' Delete this Tee'></TD>
</TR>

</TABLE>
</form>";


}
?>

</body>
</html>



#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 27 August 2006 - 09:30 PM

Try:
<?php

include 'library/config.php';
include 'library/opendb.php';

@$shirt_id = $_GET['shirt_id'];

if(isset($_POST['delete'])) {

$query = "DELETE from shirts WHERE shirt_id='$shirt_id'";
mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

    echo "Your shirt has been deleted!";

}
?>

And see if you get an error.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 27 August 2006 - 11:20 PM

Perhaps I am missing the boat (I think it sailed 50 plus years ago), but nowhere in your example have you set a value to shirt_id.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users