My web host recently updated their version of PHP and some of my code is no longer working. I created a band website that stores news items in a MySQL database. I created an update page (news.php) where the band can log in and add, update, or delete news. I have the following section of code in news.php which displayes news items from the table into a drop down list and calls a javascript function to pop up the news item in another window:

<form name="updateNews" method="post" onSubmit="updateWindow(this.updateNews.value)" >
  <tr>
    <td width="17%"><div align="right"><strong>Select news to Update:</strong></div></td>
    <td width="1%">&nbsp;</td>
    <td width="82%"><div align="left">
    <select name="updateNews" class="select">
    <?php
      do 
      {  
    ?>
    <option value="<?php echo $row_NewsUpdate['seq_id']?>"><?php echo $row_NewsUpdate['news_date']?></option>
    <?php
      } 
      while ($row_NewsUpdate = mysql_fetch_assoc($NewsUpdate));
      $rows = mysql_num_rows($NewsUpdate);
      if($rows > 0) 
      {
        mysql_data_seek($NewsUpdate, 0);
        $row_NewsUpdate = mysql_fetch_assoc($NewsUpdate);
      }
    ?>
        </select>
        </div>
        </td>
  </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input name="update" type="submit" class="buttons" id="update" value="Get News to Update" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
</form>

I have the following code to select from the database (I put xxxxx in place of real names):

mysql_select_db($database_xxxxxx, $xxxxxx);
$query_NewsUpdate = "select seq_id,news_date,news_content from news order by news_date DESC";
$NewsUpdate = mysql_query($query_NewsUpdate, $xxxxxx) or die(mysql_error());
$row_NewsUpdate = mysql_fetch_assoc($NewsUpdate);
$totalRows_NewsUpdate = mysql_num_rows($NewsUpdate);

$query_NewsDelete = "select seq_id,news_date,news_content from news order by news_date DESC";
$NewsDelete = mysql_query($query_NewsDelete, $xxxxxx) or die(mysql_error());
$row_NewsDelete = mysql_fetch_assoc($NewsDelete);
$totalRows_NewsDelete = mysql_num_rows($NewsDelete);
?>

Here is the Javascript function I'm using:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript">
<!--
function updateWindow(seq_id)
{  
  newsUpdateWindow = window.open("updateNews.php?seq_id="+seq_id,"newsUpdate_window","height=500,width=600,scrollbars");
}
function deleteWindow(seq_id)
{  
  newsDeleteWindow = window.open("deleteNews.php?seq_id="+seq_id,"newsDelete_window","height=500,width=600,scrollbars");
}

//-->
</script> 

A couple of things I checked:

  1. news.php is receiving the seq_id and is populating the drop down list with the correct values.
  2. I put print statements in update.php to see if it was receiving the seq_id from news.php and it is not.

This code worked great until php was updated on the server. I'm not sure why seq_id is no longer being passed to update.php.

Any thoughts on what may be happening? I really appreciate any help.

Member Avatar for rajarajan2017

Try to use directly the echo statement with your javascript code

<?php echo $seq_id;?>

from php version ?? to php version ??
the php.net website has a long list of details on the upgrade from one version of php to the next, lilkely you can go there and find details on what syntax is changed
often an variable that was able to be accessed as $variable has been changed so that it is accessed as $_server['variable'] $_get['variable'] or some other simple change
without knowing the two versions of php incvolved we are all shooting in the dark

when submitting code wrap it in [code=language] code [/code] tags where 'language' is php|html|css|perl|javascript|sql (any language) and the code will be presented appropriately highlighted,
often people who know the solution, wont bother if they have to wade through plain text

I put print statements in update.php to see if it was receiving the seq_id from news.php and it is not.

most likely this is the "register global" problem. You should edit your code as Almostbob recommend, using $_POST[] etc.

Sorry about not wrapping the code in tags - I will make sure to do that in the future. This was my first post.

PHP was upgraded from php4 to php5. The select queries (which populate the option_value) are working fine. I believe the root is either the variable I'm trying to pass from option_value to the Javascript pop_up window function isn't being received or the javascript function isn't passing the variable successfully to the next php page to bring up the specific record. I'm not sure how to test if the Javascript function is receiving the variable being passed from the option_value.

Obviously, I don't have much experience in this area. It's been about 5 years since I wrote the original code and haven't really worked with PHP or Javascript since.

Any direction you can give is appreciated. Thanks!

from php version ?? to php version ??
the php.net website has a long list of details on the upgrade from one version of php to the next, lilkely you can go there and find details on what syntax is changed
often an variable that was able to be accessed as $variable has been changed so that it is accessed as $_server['variable'] $_get['variable'] or some other simple change
without knowing the two versions of php incvolved we are all shooting in the dark

when submitting code wrap it in [code=language] code [/code] tags where 'language' is php|html|css|perl|javascript|sql (any language) and the code will be presented appropriately highlighted,
often people who know the solution, wont bother if they have to wade through plain text

If anyone thought there was anything other than newness as the source,
ya wouldn' believe how **expletive deleted** some of the replies would be,

maybe this

<?php
do
{
?>
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.