Hey Everyone!

I'm new to PHP and mySQL, and I'm stumped on one bit of functionality. I'm hoping that someone here will be able to help me.

I'd like to have a visitor (who's logged in already) be able to change the status of a particular record. This record is in a repeat region, and I have a small graphic that the user would click on, and that particular record status would change.

I have no clue how to do this, and I've tried a number of different code variations to no avail... I'm stumped!

Here's a sample of my code... (I've edited out non-php related material) -- notice the image that I would like to have "clickable" is deletebutton.gif and I want this tied to a record update. (using the image, not a separate submit button). I want to update the status of msg_status to DELETE, not actually delete the record from the table. (I have provisioning for that later).

<?php
session_start();
?>
<?php require_once('../Connections/newconnection.php'); ?>
<?php
$colname_rsUserDetails = "1";
if (isset($HTTP_SESSION_VARS['teleflow'])) {
  $colname_rsUserDetails = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['teleflow'] : addslashes($HTTP_SESSION_VARS['teleflow']);
}
mysql_select_db($database_newconnection, $newconnection);
$query_rsUserDetails = sprintf("SELECT * FROM message WHERE (u_code = '%s' and  msg_status <> 'DELETE') ORDER BY msg_id DESC", $colname_rsUserDetails);
$rsUserDetails = mysql_query($query_rsUserDetails, $newconnection) or die(mysql_error());
$row_rsUserDetails = mysql_fetch_assoc($rsUserDetails);
$totalRows_rsUserDetails = mysql_num_rows($rsUserDetails);


$colname_rsUser = "1";
if (isset($HTTP_SESSION_VARS['teleflow'])) {
  $colname_rsUser = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['teleflow'] : addslashes($HTTP_SESSION_VARS['teleflow']);
}
mysql_select_db($database_newconnection, $newconnection);
$query_rsUser = sprintf("SELECT u_first FROM `user` WHERE u_code = '%s'", $colname_rsUser);
$rsUser = mysql_query($query_rsUser, $newconnection) or die(mysql_error());
$row_rsUser = mysql_fetch_assoc($rsUser);
$totalRows_rsUser = mysql_num_rows($rsUser);

$colname_rsNewMsg = "1";
if (isset($HTTP_SESSION_VARS['teleflow'])) {
  $colname_rsNewMsg = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['teleflow'] : addslashes($HTTP_SESSION_VARS['teleflow']);
}
mysql_select_db($database_newconnection, $newconnection);
$query_rsNewMsg = sprintf("SELECT msg_status FROM message WHERE (u_code = '%s' and  msg_status = 'New')", $colname_rsNewMsg);
$rsNewMsg = mysql_query($query_rsNewMsg, $newconnection) or die(mysql_error());
$row_rsNewMsg = mysql_fetch_assoc($rsNewMsg);
$totalRows_rsNewMsg = mysql_num_rows($rsNewMsg);
?>
<html>
<HEAD>

</head>
<body>
              <table width="600" border="0">
                <tr>
                  <td><font color="#003399" size="2" face="Verdana, Arial, Helvetica, sans-serif">Welcome, 
                    <strong><?php echo ucfirst($row_rsUser['u_first']); ?></strong>. <br>
                    You have a total of <strong><?php echo $totalRows_rsUserDetails ?></strong> messages available, <strong><?php echo $totalRows_rsNewMsg ?></strong> messages are marked new.</font></td>
                </tr>
              </table>
              <br>
              <table width="600" border="0" cellpadding="1" cellspacing="1">
                <tr bgcolor="#003399"> 
                  <td width="75"><div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Action</font></strong></font></div></td>
                  <td width="100"><div align="right"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Status</font></strong></font></div></td>
                  <td width="150"><div align="right"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Msg 
                      From</font></strong></font></div></td>
                  <td width="100"><div align="right"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Date</font></strong></font></div></td>
                  <td width="100"><div align="right"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Time</font></strong></font></div></td>
                  <td width="75"><div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Delete</font></strong></font></div></td>
                </tr>
                <?php do { ?>
                <tr bgcolor="<?php if ($BRB_rowcounter++%2==0){?>#E2E2E2<?php }else{ ?>#F2F2F2<?php }?>" valign="middle"> 
                  <td width="75"><div align="center"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><a href="http://mywebsite.com/<?php echo $row_rsUserDetails['temp_msg_loc'];?>"><img src="images/playbutton.gif" alt="play voice mail message" border="0"></a></font></div></td>
                  <td width="100"><div align="right"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><?php echo $row_rsUserDetails['msg_status']; ?></font></div></td>
                  <td width="150"><div align="right"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><?php echo $row_rsUserDetails['msg_ani']; ?></font></div></td>
                  <td width="100"><div align="right"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><?php echo $row_rsUserDetails['creat_date']; ?></font></div></td>
                  <td width="100"><div align="right"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><?php echo $row_rsUserDetails['creat_time']; ?></font></div></td>
                  <td width="75"><div align="center"><img src="images/deletebutton.gif" alt="delete voice mail message" width="17" height="17" border="0"></font></div></td>
                </tr>
                <?php } while ($row_rsUserDetails = mysql_fetch_assoc($rsUserDetails)); ?>
              </table>
<p align="center">&nbsp;</p>
              <p align="right"><a href="logout.php"><img src="images/logout.gif" alt="log out of message center" width="59" height="21" border="0"> 
                </a></strong></font></p>
            </div>
            </td>
        </tr>
      </table>
</body>
</html>
<?php
mysql_free_result($rsUserDetails);

mysql_free_result($rsUser);

mysql_free_result($rsNewMsg);
?>

Can anyone help me with this functionality? I'm sure it's easy, but I'm still learning. Thanks very much in advance!!

...Tanya

    first of all you should always close your mysql connection as soon as possible.
    mysql_close();

    and to update an item in your database is simple.
    mysql_query("UPDATE Table_Name SET Field_name='New_Value' WHERE some_field=''");

    regards
    ryza

      Thank you for your help!! I know the code is wrong, but this is something like what I'm trying to make work:

      <form action="POST">
      <?PHP ("UPDATE message SET msg_status = 'DELETE' WHERE u_code = '%s'") ?>
      <input name="formupdate" type="image" src="images/deletebutton.gif">
      </form>
      

      Can someone help me refine this bit of code so that it actually works to update that particular record in the recordset?

      Thanks again!!
      ...Tanya

        • [deleted]

        Nope, you should NOT close your database connection as soon as possible, you should close it when you have no more use for it, and that is usually not untill the script ends.

        Never ever close and re-open a connection in the same script.

          thanks for the info.... 🙂

          Do you have any comment on my crappy code?

          Thanks in advance!

          Tanya

            Write a Reply...