954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Trying to update entire column in database

Hi,

I'm new to PHP and was wondering if anyone could help me with my problem.

Basically I have an access database and have managed to create a few php scripts by looking at various tutorials and scripts on the net in php that insert, update, delete and view data from the database. The problem is that I need to be able to update, insert and delete more than one row at a time.

For example what I am trying to do at the moment is update an entire column.

I've been trying to use an array to hold the values of one of the database column variables and then just display them to see if I'm getting the right results, which I'm not. :sad:

Can anyone point me in the right direction and/or look at what I've done so far?

<form action="edit1.php" method="post" name="FormName">
<?php 

require_once('odbc.php');

//If cmd has not been initialized
if(!isset($cmd)) 
{
   // display all students
   $result = odbc_exec($odbc, "SELECT * FROM Students ORDER BY ID");
    
     echo "
     <table align=center border=0 cellpadding=5>
     <tr bgcolor=#3B6AA0>
     <th>ID</th>
     <th>FirstName</th>
     <th>LastName</th>
     <th>Present</th>
     </tr>";

   //run the while loop that grabs all the students     
      
   while($r = odbc_fetch_array($result)) 
   { 
      //grab the names and the ID of the students
      $FirstName=$r["FirstName"]; //take out the first name of student
      $LastName=$r["LastName"]; //take out the last name of student
      $Present=$r["Present"]; //take out the attendance code
      $ID=$r["ID"]; //take out the id
    
     echo "<tr>";
     echo "<td><font color=#bbbbbb>$ID</font></td>";
     echo "<td>$FirstName</td>";
     echo "<td>$LastName</td>";
     echo "<td>";
     echo "<INPUT TYPE='TEXT' NAME='Present[]' VALUE='$Present' SIZE=3>";
     echo "</td>";
    // echo "<td><a href='edit1.php?cmd=edit&id=$ID'>Edit</a></td>";
     echo "</tr>";
     }
     echo "</table>";

?>
<input type="submit" name="submit" value="submit">

<?php } ?>

<?php

if ($_POST["submit"])
{
 echo $_POST["Present"]; 
} 
 
?>

To actually update the database, I'd use something along the lines of:

<?php
   if ($_POST["submit"])
   {
      $id = $_POST["id"];
      $Present = $_POST["Present"];
      
      $sql = "UPDATE Students SET Present='$Present' WHERE ID=$id";
      $result = odbc_exec($odbc, $sql);
      echo "";
      echo "";
      echo "Thank you. Information updated.";
      echo "<a href='edit1.php'>refresh<a>";
    }
}
?>
ashweb
Newbie Poster
1 post since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

what exactly is the error you get ???

w_3rabi
Junior Poster
160 posts since Dec 2006
Reputation Points: 18
Solved Threads: 9
 
DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You