Update won't work in php 5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
theoph
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA

Update won't work in php 5

Post by theoph »

The following script used to work perfectly, but now using php 5 is won't. The header () won't work as well.

Any suggestions?

Code: Select all

if($_GET['submit']) /* Handles the form. */
{
	foreach ($scell as $groups)
	{
		$array_data .= $groups."," ;
	}
	$array_data = substr($array_data,0,-1);
	$db = mysql_select_db($database_Home, $Home);
	$query = "UPDATE laos SET oikos_id='$famLabel', lname='$last', fname='$first', mname='$mname', label='$label', suffix='$suffix', directory='$directory', gender='$gender', race='$race', status='$status', pfamily='$position', member='$member', email='$email', web='$web', wphone='$wphone', mphone='$mphone', fax='$fax', pager='$pager', pcell='$pcell', scell='$array_data', birthday='$birthday', aniversary='$aniversary', notes='$notes' WHERE id='$id'";
	$result = mysql_query($query) or die ("Couldn't execute query.");
 	header("Location: update_success.php?recordID=$id");
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Some more context would be helpful, but I'll guess that this code was written with the assumption that register_globals was on, when they are not anymore.

Where are all the variables in the lines coming from?
theoph
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA

Post by theoph »

Here is the php scripting for the page I'm working on. It used to work find but on the new server it won't. All my other php pages work fine.

Code: Select all

<?php require_once('../../../Connections/Home.php'); ?>
<?php
if($_GET['submit']) /* Handles the form. */
{
	foreach ($scell as $groups)
	{
		$array_data .= $groups."," ;
	}
	$array_data = substr($array_data,0,-1);
	$db = mysql_select_db($database_Home, $Home);
	$query = "UPDATE laos SET oikos_id='$famLabel', lname='$last', fname='$first', mname='$mname', label='$label', suffix='$suffix', directory='$directory', gender='$gender', race='$race', status='$status', pfamily='$position', member='$member', email='$email', web='$web', wphone='$wphone', mphone='$mphone', fax='$fax', pager='$pager', pcell='$pcell', scell='$array_data', birthday='$birthday', aniversary='$aniversary', notes='$notes' WHERE id='$id'";
	$result = mysql_query($query) or die ("Couldn't execute query.");
 	header("Location: update_success.php?recordID=$id");
}
?>
<?php
/* rsLaos */ $colname_rsLaos = "1";
if (isset($_GET['recordID'])) {
  $colname_rsLaos = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_Home, $Home);
$query_rsLaos = sprintf("SELECT * FROM laos WHERE id = %s", $colname_rsLaos);
$rsLaos = mysql_query($query_rsLaos, $Home) or die(mysql_error());
$row_rsLaos = mysql_fetch_assoc($rsLaos);
$totalRows_rsLaos = mysql_num_rows($rsLaos);

/* rsOikosmenu */ mysql_select_db($database_Home, $Home);
$query_rsOikosmenu = "SELECT id, famLabel FROM oikos ORDER BY famLabel ASC";
$rsOikosmenu = mysql_query($query_rsOikosmenu, $Home) or die(mysql_error());
$row_rsOikosmenu = mysql_fetch_assoc($rsOikosmenu);
$totalRows_rsOikosmenu = mysql_num_rows($rsOikosmenu);

/* rsCellmenu */ mysql_select_db($database_Home, $Home);
$query_rsCellmenu = "SELECT name, cells.id FROM cells WHERE cells.active = 'Y' ORDER BY name ASC";
$rsCellmenu = mysql_query($query_rsCellmenu, $Home) or die(mysql_error());
$row_rsCellmenu = mysql_fetch_assoc($rsCellmenu);
$totalRows_rsCellmenu = mysql_num_rows($rsCellmenu);
?>
The Form

Code: Select all

<form action="<?php echo $editFormAction; ?>" method="POST" name="laosUpdate">
<table width="573" border="1" align="center" cellpadding="2">
<caption>Edit the information in the following table and then select the "Update" button to insert the changes.</caption>
  <tr>
    <th width="67" bgcolor="#C3D2F0"><div align="right">Family Label:</div></th>
    <td width="200" bgcolor="#FFFFFF"><select name="famLabel" id="famLabel">
      <?php
do {  
?>
      <option value="<?php echo $row_rsOikosmenu['id']?>"<?php if (!(strcmp($row_rsOikosmenu['id'], $row_rsLaos['oikos_id']))) {echo "SELECTED";} ?>><?php echo $row_rsOikosmenu['famLabel']?></option>
      <?php
} while ($row_rsOikosmenu = mysql_fetch_assoc($rsOikosmenu));
  $rows = mysql_num_rows($rsOikosmenu);
  if($rows > 0) {
      mysql_data_seek($rsOikosmenu, 0);
	  $row_rsOikosmenu = mysql_fetch_assoc($rsOikosmenu);
  }
?>
    </select></td>
    <th width="78" bgcolor="#C3D2F0"><div align="right">Work Phone:</div></th>
    <td bgcolor="#FFFFFF"><input name="wphone" type="text" id="wphone" value="<?php echo $row_rsLaos['wphone']; ?>" size="14" maxlength="14" /></td>
  </tr>
  <tr>
    <th bgcolor="#C3D2F0"><div align="right">Last Name:</div></th>
    <td bgcolor="#FFFFFF"><input name="last" type="text" id="last" value="<?php echo $row_rsLaos['lname']; ?>" /></td>
    <th bgcolor="#C3D2F0"><div align="right">Mobile Phone:</div></th>
    <td bgcolor="#FFFFFF"><input name="mphone" type="text" id="mphone2" value="<?php echo $row_rsLaos['mphone']; ?>" size="14" maxlength="14" /></td>
  </tr>
  <tr>
    <th bgcolor="#C3D2F0"><div align="right">First :</div></th>
    <td bgcolor="#FFFFFF"><input name="first" type="text" id="first" value="<?php echo $row_rsLaos['fname']; ?>" size="14" />
      Middle:
        <input name="mname" type="text" id="mname" value="<?php echo $row_rsLaos['mname']; ?>" size="2" maxlength="2" /></td>
    <th bgcolor="#C3D2F0"><div align="right">Fax:</div></th>
    <td bgcolor="#FFFFFF"><input name="fax" type="text" id="fax2" value="<?php echo $row_rsLaos['fax']; ?>" size="14" maxlength="14" /></td>
  </tr>
  <tr>
    <th bgcolor="#C3D2F0"><div align="right">Label:</div></th>
    <td bgcolor="#FFFFFF"><input name="label" type="text" id="label2" value="<?php echo $row_rsLaos['label']; ?>" size="30" maxlength="30" /></td>
    <th bgcolor="#C3D2F0"><div align="right">Pager:</div></th>
    <td bgcolor="#FFFFFF">      <input name="pager" type="text" id="pager2" value="<?php echo $row_rsLaos['pager']; ?>" size="14" maxlength="14" /></td>
  </tr>
  <tr>
    <th bgcolor="#C3D2F0"><div align="right">Suffix:</div></th>
    <td bgcolor="#FFFFFF"><input name="suffix" type="text" id="suffix" value="<?php echo $row_rsLaos['suffix']; ?>" size="4" maxlength="4" /></td>
    <th bgcolor="#C3D2F0"><div align="right">Status:</div></th>
    <td bgcolor="#FFFFFF"><select name="status" id="select5">
      <option value="ACT" <?php if (!(strcmp("ACT", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Active</option>
      <option value="ACP" <?php if (!(strcmp("ACP", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Active
      Prospect</option>
      <option value="INA" <?php if (!(strcmp("INA", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Inactive</option>
      <option value="INP" <?php if (!(strcmp("INP", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Inactive
      Prospect</option>
      <option value="OOF" <?php if (!(strcmp("OOF", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Out-of-Town</option>
      <option value="OOS" <?php if (!(strcmp("OOS", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Out-of-Town
      Student</option>
      <option value="SHT" <?php if (!(strcmp("SHT", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Shutin
      - Temporary</option>
      <option value="SHL" <?php if (!(strcmp("SHL", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Shutin
      - Long Term</option>
      <option value="UEV" <?php if (!(strcmp("UEV", $row_rsLaos['status']))) {echo "SELECTED";} ?>>Under
      Evalutation</option>
    </select></td>
  </tr>
  <tr>
    <th height="43" bgcolor="#C3D2F0">Directory:</th>
    <td bgcolor="#FFFFFF"><input <?php if (!(strcmp($row_rsLaos['directory'],"Y"))) {echo "checked";} ?> name="directory" type="checkbox" id="directory" value="Y" />
(Check for "Yes")</td>
    <th bgcolor="#C3D2F0"><div align="right">Gender:</div></th>
    <td valign="middle" bgcolor="#FFFFFF"><label>
      <input <?php if (!(strcmp($row_rsLaos['gender'],"M"))) {echo "CHECKED";} ?>  type="radio" name="gender" value="M" />
Male</label>
 &nbsp;      
 <label>
      <input <?php if (!(strcmp($row_rsLaos['gender'],"F"))) {echo "CHECKED";} ?>  type="radio" name="gender" value="F" />
Female</label></td>
    </tr>
  <tr>
    <th height="43" bgcolor="#C3D2F0"><div align="right">Member:</div></th>
    <td bgcolor="#FFFFFF"><input <?php if (!(strcmp($row_rsLaos['member'],"Y"))) {echo "checked";} ?> name="member" type="checkbox" id="member3" value="Y" />
      (Check for "Yes") </td>
    <th bgcolor="#C3D2F0"><div align="right">Race:</div></th>
    <td valign="middle" bgcolor="#FFFFFF"><select name="race" id="select2">
      <option value="A" <?php if (!(strcmp("A", $row_rsLaos['race']))) {echo "SELECTED";} ?>>Asian</option>
      <option value="B" <?php if (!(strcmp("B", $row_rsLaos['race']))) {echo "SELECTED";} ?>>Black</option>
      <option value="N" <?php if (!(strcmp("N", $row_rsLaos['race']))) {echo "SELECTED";} ?>>Native American</option>
      <option value="M" <?php if (!(strcmp("M", $row_rsLaos['race']))) {echo "SELECTED";} ?>>Mixed</option>
      <option value="W" <?php if (!(strcmp("W", $row_rsLaos['race']))) {echo "SELECTED";} ?>>White</option>
    </select></td>
  </tr>
  <tr>
    <th height="43" bgcolor="#C3D2F0"><div align="right">Birthday:</div></th>
    <td valign="middle" bgcolor="#FFFFFF"><input name="birthday" type="text" id="birthday" value="<?php echo $row_rsLaos['birthday']; ?>" size="10" maxlength="10" />      <img src="../../../images/dateBtn.gif" width="18" height="18" onclick="KW_doCalendar('birthday',0)" /><span class="recordtext">&nbsp;(YYYY-MM-DD)</span></td>
    <th bgcolor="#C3D2F0">Aniversary:</th>
    <td valign="middle" bgcolor="#FFFFFF"><input name="aniversary" type="text" id="aniversary" value="<?php echo $row_rsLaos['aniversary']; ?>" size="10" maxlength="10" />      <img src="../../../images/dateBtn.gif" width="18" height="18" onclick="KW_doCalendar('aniversary',0)" />&nbsp;<span class="recordtext">(YYYY-MM-DD)</span></td>
  </tr>
  <tr>
    <th rowspan="2" bgcolor="#C3D2F0"><div align="right">Position in Family:</div></th>
    <td rowspan="2" bgcolor="#FFFFFF"><label>
      <input <?php if (!(strcmp($row_rsLaos['pfamily'],"1"))) {echo "CHECKED";} ?>  type="radio" name="position" value="1" />
Head of Household</label>
      <br />
      <label>
      <input <?php if (!(strcmp($row_rsLaos['pfamily'],"2"))) {echo "CHECKED";} ?>  type="radio" name="position" value="2" />
Spouce</label>
      <br />
      <label>
      <input <?php if (!(strcmp($row_rsLaos['pfamily'],"3"))) {echo "CHECKED";} ?>  type="radio" name="position" value="3" />
Dependent Child</label>
      <br />
      <label>
      <input <?php if (!(strcmp($row_rsLaos['pfamily'],"4"))) {echo "CHECKED";} ?>  type="radio" name="position" value="4" />
Live In Adult</label>
      <br />
      <label>
      <input <?php if (!(strcmp($row_rsLaos['pfamily'],"5"))) {echo "CHECKED";} ?>  type="radio" name="position" value="5" />
Foster Child</label></td>
    <th height="43" bgcolor="#C3D2F0">Primary Cell Group:</th>
    <td valign="middle" bgcolor="#FFFFFF"><select name="pcell" id="select4">
      <option value="" <?php if (!(strcmp("", $row_rsLaos['pcell']))) {echo "SELECTED";} ?>>-None-</option>
      <?php
do {  
?>
      <option value="<?php echo $row_rsCellmenu['id']?>"<?php if (!(strcmp($row_rsCellmenu['id'], $row_rsLaos['pcell']))) {echo "SELECTED";} ?>><?php echo $row_rsCellmenu['name']?></option>
      <?php
} while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu));
  $rows = mysql_num_rows($rsCellmenu);
  if($rows > 0) {
      mysql_data_seek($rsCellmenu, 0);
	  $row_rsCellmenu = mysql_fetch_assoc($rsCellmenu);
  }
?>
    </select></td>
  </tr>
  <tr>
    <th height="111" bgcolor="#C3D2F0"><div align="right">Secondary
      Cell Group:</div></th>
This is a section that once gave me fits, multiple list menu.

Code: Select all

<td valign="top" bgcolor="#FFFFFF"><select name="scell[]" size="7" multiple="multiple" id="scell[]">
        <option value="" <?php if (!(strcmp("", $row_rsLaos['scell']))) {echo "SELECTED";} ?>>-None-</option>
        <?php 
			do {
				if(strpos($row_rsLaos['scell'],$row_rsCellmenu['id'])!==FALSE)
				{
					$check = 'SELECTED';
				}
				else
				{
					$check = '';
				}
				echo '<option value="'.$row_rsCellmenu['id'].'" '.$check.'>'.$row_rsCellmenu['name'].'</option>';
			}
			while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu));
		?>
        </select></td>
Rest of the form.

Code: Select all

</tr>
  <tr>
    <th bgcolor="#C3D2F0"><div align="right">Notes:</div></th>
    <td colspan="3" bgcolor="#FFFFFF"><textarea name="notes" cols="50" rows="5" id="textarea2"><?php echo $row_rsLaos['notes']; ?></textarea></td>
  </tr>
  <tr>
    <th bgcolor="#C3D2F0"><div align="right">Email:</div></th>
    <td colspan="3" bgcolor="#FFFFFF"><input name="email" type="text" id="email5" value="<?php echo $row_rsLaos['email']; ?>" size="48" maxlength="48" /> 
    <div align="right"></div></td>
    </tr>
  <tr>
    <th bgcolor="#C3D2F0"><div align="right">Web:</div></th>
    <td colspan="3" bgcolor="#FFFFFF"><input name="web" type="text" id="web4" value="<?php echo $row_rsLaos['web']; ?>" size="48" maxlength="48" />      
    <div align="right"></div></td>
    </tr>
  <tr>
    <td><div align="right"><font color="#FFFFFF"></font></div></td>
    <td colspan="3">
        <div align="center">
          <input name="submit" type="submit" id="submit" value="Update" />
        </div></td>
    </tr>
</table>
<input name="id" type="hidden" id="id" value="<?php echo $row_rsLaos['id']; ?>">
<input type="hidden" name="MM_update" value="laosUpdate">
</form>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yep, I'm pretty sure my first guess is the correct one. Your script was written with the assumption register_globals is on. It is not on in PHP 5.

To test my theory, echo out $query just after you set it in that originally posted snippet. If all the fields are blank then I was right. You will have to rewrite each variable to a $_POST['varname'] version.
theoph
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA

Post by theoph »

Thanks, I'll give it a try.

-Dave
Post Reply