Hello,

I'm trying to do a very basic page that allows me to edit a single column in a MSSQL database. For whatever reason I can't figure it out and am hoping that you can help.

Here is my front page (sorry about the silly names)

$ninja_conn = odbc_connect('XXXXX','XXXX','XXXX', SQL_CUR_USE_ODBC);
?>
<head>
	<title>In/Out</title>
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
	<div id="upper_left"></div>
	<div id="upper_right"></div>
	<div id="lower_left"></div>
	<div id="lower_right"></div>	
	<div id="page_wrap">
	  <h1>Time Clock Status</h1>
	  <br /><br />
     <?php 
     $sql_ninja_stats = "SELECT * from dbo.TCNinja";
     $ninja_get=odbc_exec($ninja_conn, $sql_ninja_stats);
     echo'<table border="1">
      <th><b><u>Name</b></u></th>
      <th>&nbsp;</th>
      <th><b><u>Status</b></u></th>
      <th>&nbsp;</th>
      <th><b><u>Update</b></u></th>';
         
     while($rows=odbc_fetch_array($ninja_get)){
     echo "
<tr>
  <td>".$rows['EmpName']."</td>
  <td>&nbsp; &nbsp; &nbsp; </td>
  <td><select name='Status'>
      <option value=".$rows['Status']." selected='selected'>". $rows['Status']."</option>
      <option vlaue='1'>1</option>
      <option vlaue='0'>0</option>
    </select></td>
  <td>&nbsp; &nbsp; &nbsp; </td>
  <td><a href='tcninja_update.php?ID=".$rows['ID']."'>submit</a></td>
  </tr>
";
}
    echo'</table>';
      ?>

</form></div></body></html>

That pulls the data fine, but when I try to submit I'm getting undefined indexes.
Here is the back end page:

$ninja_conn = odbc_connect('XXXX','XXXXX','XXXX', SQL_CUR_USE_ODBC);

$status=$_POST['Status'];
$id=$_POST['ID'];

$query="UPDATE dbo.TCNinja SET Status='$status' WHERE ID='$id'";

/// Perform the update ///
$result=odbc_exec($ninja_conn, $query);
  
/// if successfully updated. ///
if($result){
header("Location:http://phi/who/tcninjas.php");

}
else {
echo "Error";
}
/// close connection ///
odbc_close($ninja_conn);
?>

Any suggestions?

Recommended Answers

All 2 Replies

Where is the form? And why you wrote this:

<td><a href='tcninja_update.php?ID=".$rows['ID']."'>submit</a></td>

This will generate a GET, to read ID you need to write $_GET, but you won't get Status, to get that you need to add it to the link &Status=value To submit a form like yours you need the proper tag, so you need to write:

<form method="post" action="tcninja_update.php"> <!-- this goes at the top of the form -->
<!-- select goes here... -->

<!-- before </form> add this: -->
<input type="hidden" name="ID" value="<?php echo $rows['ID']; ?>" />
<input type="submit" name="submit" value="send" />

Thanks for the info. It got me going in the correct direction!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.