Jump to content

Error after sending UPDATE command


vbcoach

Recommended Posts

Hello.  Have a simple site that takes softball player names and after successful logging in, give them to edit some basic information, like home and cell phone, comments, etc..  Everything appears correct, yet I am getting an undefined index MsSql error, yet when I do a variable dumb, the index appears.  Not sure what I am doing wrong.

 

<?php
require_once('access.php');

$conn = mssql_connect ("localhost", "bbpublic", "hdyet65e42") or die ('I cannot connect to the database because: ' . mssql_error());
mssql_select_db("********");
$vals = $_POST;

$sql = "UPDATE trinitySBteam SET homephone='$vals[homephone]',cellphone='$vals[cellphone]',email='$vals[email]',position1='$vals[position1]',position2='$vals[position2]',position3='$vals[position3]',comments='$vals[comments]' WHERE player_id = $vals[id]";
mssql_query($sql, $conn);

mssql_close($conn);
//Update Session Variables
$_SESSION['homephone'] = $vals['homephone'];
$_SESSION['cellphone'] = $vals['cellphone'];
$_SESSION['email'] = $vals['email'];
$_SESSION['position1'] = $vals['position1'];
$_SESSION['position2'] = $vals['position2'];
$_SESSION['position3'] = $vals['position3'];
$_SESSION['comments'] = $vals['comments'];

header("Location: viewplayer.php");
?>

 

Yet I get this error after running...

Notice: Undefined index: id in E:\Web Server\baltimorebeach_com\htdocs\trinitySB\updatePlayer.php on line 15

 

Warning: mssql_query(): message: Line 1: Incorrect syntax near '='. (severity 15) in E:\Web Server\baltimorebeach_com\htdocs\trinitySB\updatePlayer.php on line 16

 

Warning: mssql_query(): Query failed in E:\Web Server\baltimorebeach_com\htdocs\trinitySB\updatePlayer.php on line 16

 

Warning: Cannot modify header information - headers already sent by (output started at E:\Web Server\baltimorebeach_com\htdocs\trinitySB\updatePlayer.php:15) in E:\Web Server\baltimorebeach_com\htdocs\trinitySB\updatePlayer.php on line 28

Link to comment
Share on other sites

Here you go.

<?php
require_once('access.php');

$info = $_SESSION;

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Baltimore Beach Control Panel</title>
<link rel="stylesheet" href="../../cp/cpanel.css" type="text/css">
<script language="javascript">
</script>

<style type="text/css">
<!--
.style2 {	font-size: 18px;
font-weight: bold;
}
.style5 {font-size: 14; font-weight: bold; }
.style7 {font-size: 14px; }
-->
</style>
</head>

<body>


<p><img src="images/trinity1.jpg" width="336" height="87"></p>
<table width="788"  border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td width="58%" height="340"><form name="updtplyr" action="updatePlayer.php" method="post">
      <table width="98%"  border="0" cellpadding="2" cellspacing="0" class="grey2px">
        <tr>
          <td colspan="3" class="dk_greyTxt"><h3 class="style2">Player's Information</h3></td>
        </tr>
        <tr>
          <td width="30%" class="dk_greyTxt"><span class="style5">Name</span></td>
          <td width="3%"> </td>
          <td width="67%"><?php echo $info['playername']; ?> </td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">Home Phone</span></td>
          <td> </td>
          <td><input type="text" name="homephone" id="homephone" value="<?php echo $info['homephone'] ?>">
              <br></td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">Cell Phone</span></td>
          <td> </td>
          <td><input type="text" name="cellphone" id="cellphone" value="<?php echo $info['cellphone'] ?>"></td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">E-mail</span></td>
          <td> </td>
          <td><input type="text" name="email" id="email" value="<?php echo $info['email'] ?>"></td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">Jersey</span></td>
          <td> </td>
          <td><?php echo $info['jersey'] ?></td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">Position 1</span></td>
          <td> </td>
          <td><input type="text" name="position1" id="position1" value="<?php echo $info['position1'] ?>"></td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">Position 2</span></td>
          <td> </td>
          <td><input type="text" name="position2" id="position2" value="<?php echo $info['position2'] ?>"></td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">Position 3</span></td>
          <td> </td>
          <td><input type="text" name="position3" id="position3" value="<?php echo $info['position3'] ?>"></td>
        </tr>
        <tr>
          <td class="dk_greyTxt"><span class="style5">Comments</span></td>
          <td rowspan="2" valign="top"> </td>
          <td rowspan="2" valign="top"><textarea name="comments" id="comments" cols="45" rows="2"><?php echo $info['comments'] ?></textarea>          </td>
        </tr>
        <tr>
          <td class="dk_greyTxt"> </td>
        </tr>
        <tr>
          <td class="dk_greyTxt"> </td>
          <td> </td>
          <td><input type="submit" name="updateplayerinfo" id="updateplayerinfo" value="Update Player Information">          </td>
        </tr>
      </table>
      <br>
    </form>
        </td>
    <td width="42%" align="center" valign="top"><form name="uAv" action="updateAvailability.php" method="post" >
      <table width="310" border="0">
        <tr>
          <td colspan="10" bgcolor="#D1E39B"><div align="center" class="style2">Schedule Availability</div></td>
        </tr>
        <tr>
          <td width="59" class="menu"><div align="center" class="style7">5/1</div></td>
          <td width="58" class="menu"><div align="center" class="style7">5/8</div></td>
          <td width="58" class="menu"><div align="center" class="style7">5/15</div></td>
          <td width="58" class="menu"><div align="center" class="style7">5/22</div></td>
          <td width="55" class="menu"><div align="center" class="style7">5/29</div></td>
        </tr>
        <tr>
          <td><div align="center">
            <select name="week6" id="week2">
              >
                <option value="" <?php if($info['week1'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week1'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week1'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
            <select name="week6" >
                <option value="" <?php if($info['week2'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week2'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week2'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
            <select name="week6" id="week6">
                <option value="" <?php if($info['week3'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week3'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week3'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
            <select name="week6" id="week7">
                <option value="" <?php if($info['week4'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week4'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week4'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
            <select name="week6" id="week8">
                <option value="" <?php if($info['week5'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week5'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week5'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
        </tr>
      </table>
      <p>
      <table width="310" border="0">
        <tr>
          <td colspan="10" bgcolor="#D1E39B"><div align="center" class="style2">Schedule Availability</div></td>
        <tr>
          <td width="59" class="menu"><div align="center" class="style7">6/5</div></td>
          <td width="58" class="menu"><div align="center" class="style7">6/12</div></td>
          <td width="58" class="menu"><div align="center" class="style7">6/19</div></td>
          <td width="58" class="menu"><div align="center" class="style7">6/26</div></td>
          <td width="55" class="menu"><div align="center" class="style7">7/10</div></td>
        </tr>
        <tr>
          <td><div align="center">
              <select name="week6" id="week9">
                <option value="" <?php if($info['week6'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week6'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week6'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
              <select name="week7" id="week10">
                <option value="" <?php if($info['week7'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week7'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week7'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
              <select name="week8" id="week11">
                <option value="" <?php if($info['week8'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week8'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week8'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
              <select name="week9" id="week12">
                <option value="" <?php if($info['week9'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week9'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week9'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
          <td><div align="center">
              <select name="week10" id="week13">
                <option value="" <?php if($info['week10'] == NULL) echo 'selected'; ?>>?</option>
                <option value="Yes" <?php if($info['week10'] == 'Yes') echo 'selected'; ?>>Yes</option>
                <option value="No" <?php if($info['week10'] == 'No') echo 'selected'; ?>>No</option>
              </select>
          </div></td>
        </tr>
      </table>
      <p>
        <input type="submit" name="update" id="update" value="Update Availability">
        <br>
      </p>
      </form>
      </form></td>
  </tr>
</table>
<p> </p>
<p> </p>

</body>
</html>

============  This is the form that calls the update to be set in Sql database===============
============= Now below is the ACCESS form that is used, and defines the variables ==========
<?php 
/*
This document will be used to manage the Trinity SB team sessions when they login
This should be placed at the top of each page in the /trinitySB directory
*/

session_start();

if(!isset($_SESSION['id']) && !isset($_POST['unique']))
{
  //build login page again
  ?>
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Baltimore Beach Control Panel</title>
<link rel="stylesheet" href="../cp/cpanel.css" type="text/css">
</head>

<body>

<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3"><img src="../cp/images/BBV_CP_top.jpg" width="800" height="200"></td>
  </tr>
  <tr>
    <td> </td>
    <td><br>
      <br>
      <br>
  <form name="bbv_login_form" action="login.php" autocomplete = "false" method="post">
      <table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="4"><img src="../cp/images/login_top.jpg" width="350" height="25"></td>
        </tr>
      <tr>
        <td width="5" rowspan="7" class="tableltBg"></td>
        <td colspan="2" align="center"><strong><em>Sorry: You must first login to use this feature </em></strong></td>
        <td width="5" rowspan="7" class="tableRtBg"></td>
      </tr>
      
  <tr>
    <td align="right" class="dk_greyTxt"> </td>
    <td> </td>
    </tr>
  <tr>
        <td width="100" align="right" class="dk_greyTxt"><strong>username: </strong></td>
        <td width="240"> 
          <input name="unique" type="text" id="unique"></td>
        </tr>
      <tr>
        <td width="100"> </td>
        <td width="240"> </td>
      </tr>
      <tr>
        <td width="100" align="right" class="dk_greyTxt"><strong>password: </strong></td>
        <td width="240"> 
          <input name="pword" type="password" id="pword"></td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td width="100"> </td>
        <td width="240"><input name="Submit" type="submit" class="button" value="Login"></td>
      </tr>

      <tr>
        <td colspan="4" class="tableFoot"></td>
        </tr>
    </table>
  </form>    </td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="3"> </td>
  </tr>
</table>
</body>
</html>

  <?php
  exit;
}

if(isset($_POST['pword']))
{
$conn = mssql_connect ("localhost", "bbpublic", "********") or die ('I cannot connect to the database because: ' . mssql_error());

$un  = $_POST['unique'];
$pw = $_POST['pword'];
mssql_select_db("baltimorebeach");

$sql = "SELECT t.*, username, password FROM trinitySBteam as t WHERE username='$un' AND password='$pw'";
$res = mssql_query($sql,$conn);

if(mssql_rows_affected($conn) !== 1)
{
   //Login unsuccessful build nessecery page
   ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Trinity Softball 2010 Control Panel</title>
<link rel="stylesheet" href="../cp/cpanel.css" type="text/css">
</head>

<body>

<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3"><img src="../cp/images/BBV_CP_top.jpg" width="800" height="200"></td>
  </tr>
  <tr>
    <td> </td>
    <td><br>
      <br>
      <br>
  <form name="bbv_login_form" action="" autocomplete = "false" method="post">
      <table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="4"><img src="../cp/images/login_top.jpg" width="350" height="25"></td>
        </tr>
      <tr>
        <td width="5" rowspan="7" class="tableltBg"></td>
        <td colspan="2" align="center"><strong><em>Error: username/password combination not found </em></strong></td>
        <td width="5" rowspan="7" class="tableRtBg"></td>
      </tr>
      
  <tr>
    <td align="right" class="dk_greyTxt"> </td>
    <td> </td>
    </tr>
  <tr>
        <td width="100" align="right" class="dk_greyTxt"><strong>username: </strong></td>
        <td width="240"> 
          <input name="unique" type="text" id="unique"></td>
        </tr>
      <tr>
        <td width="100"> </td>
        <td width="240"> </td>
      </tr>
      <tr>
        <td width="100" align="right" class="dk_greyTxt"><strong>password: </strong></td>
        <td width="240"> 
          <input name="pword" type="password" id="pword"></td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td width="100"> </td>
        <td width="240"><input name="Submit" type="submit" class="button" value="Login"></td>
      </tr>

      <tr>
        <td colspan="4" class="tableFoot"></td>
        </tr>
    </table>
</body>
</html>
   <?php
   mssql_close($conn);
   exit;
}

$SBteam = mssql_fetch_assoc($res);
$_SESSION['id'] = $SBteam['player_id'];
$_SESSION['playername'] = $SBteam['playername'];
$_SESSION['homephone'] = $SBteam['homephone'];
$_SESSION['cellphone'] = $SBteam['cellphone'];
$_SESSION['email'] = $SBteam['email'];
$_SESSION['jersey'] = $SBteam['jersey'];
$_SESSION['position1'] = $SBteam['position1'];
$_SESSION['position2'] = $SBteam['position2'];
$_SESSION['position3'] = $SBteam['position3'];
$_SESSION['week1'] = $SBteam['week1'];
$_SESSION['week2'] = $SBteam['week2'];
$_SESSION['week3'] = $SBteam['week3'];
$_SESSION['week4'] = $SBteam['week4'];
$_SESSION['week5'] = $SBteam['week5'];
$_SESSION['week6'] = $SBteam['week6'];
$_SESSION['week7'] = $SBteam['week7'];
$_SESSION['week8'] = $SBteam['week8'];
$_SESSION['week9'] = $SBteam['week9'];
$_SESSION['week10'] = $SBteam['week10'];
$_SESSION['week11'] = $SBteam['week11'];
$_SESSION['week12'] = $SBteam['week12'];
$_SESSION['comments'] = $SBteam['comments'];
mssql_close($conn);
}
?>

There is one other page that simply allows the player to view his current information.  Does this help?

Link to comment
Share on other sites

Sure there is.  In the included code: access.php

 

Here's the flow: 

*Index page allows player to enter his userid and password.

*Access.php processes that information, sets $_Post variables to pass to

*viewplayer.php which allows player to view his current information.

*editplayer.php allows a player to change certain fields.

*updateplayer.php processes those changes, then updates the variables.

 

It's at this point where the "id" is not being found.  If I do a  $vars = get_defined_vars();

print_r($vars);  it does show an "[id] = 1" which is what the player_id is supposed to be.

 

I am confused.

Link to comment
Share on other sites

<?php
require_once('access.php');

$conn = mssql_connect ("localhost", "bbpublic", "hdyet65e42") or die ('I cannot connect to the database because: ' . mssql_error());
mssql_select_db("********");
$vals = $_POST;
$id = $_SESSION['id'];
$sql = "UPDATE trinitySBteam SET homephone='$vals[homephone]',cellphone='$vals[cellphone]',email='$vals[email]',position1='$vals[position1]',position2='$vals[position2]',position3='$vals[position3]',comments='$vals[comments]' WHERE player_id = $id";
mssql_query($sql, $conn);

mssql_close($conn);
//Update Session Variables
$_SESSION['homephone'] = $vals['homephone'];
$_SESSION['cellphone'] = $vals['cellphone'];
$_SESSION['email'] = $vals['email'];
$_SESSION['position1'] = $vals['position1'];
$_SESSION['position2'] = $vals['position2'];
$_SESSION['position3'] = $vals['position3'];
$_SESSION['comments'] = $vals['comments'];

header("Location: viewplayer.php");
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.