Jump to content


Photo

$_GET problems...


  • Please log in to reply
3 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 27 August 2006 - 08:10 PM

I'm trying to make a page to update or delete a shirt from a database. I am passing the shirt_id in through a URL link and using GET. I used the exact same GET code on another page and it worked fine.  Can anyone see anything wrong with this... I am getting this error

Undefined index: shirt_id in E:\ProgramFiles\Apache\htdocs\ShirtSite\edit.php on line 15

Thanks in advance!!!!

<?php

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

$shirt_id = $_GET['shirt_id'];  //LINE 15

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

$query = "DELETE FROM shirts WHERE shirt_id='$shirt_id'";
$delete = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
    echo "Your shirt has been deleted!";

}



else if(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'";

  $result = 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 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 27 August 2006 - 08:13 PM

it's not an error, it's a warning.  You can simply reduce the error_reporting level to get rid of it.

http://ca.php.net/ma...r-reporting.php
Legend has it that reading the manual never killed anyone.
My site

#3 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 27 August 2006 - 08:30 PM

Will the code work if I change the error level...as of right now, the code doesn't do what it's supposed to do. it doesn't update the database when the submit button is pressed...I get the warning only...

can I change the code to get rid of the warning?

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 27 August 2006 - 09:17 PM

try to change
<form method='post' action='edit.php'>
to
<form method='post' action=''>
or
<form method='post' action='edit.php?shirt_id=$shirt_id'>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users