Php creating new user everytime

Hey guys I hope i am posting in the right forum. I am building my first site for college and and have the majority of the groundwork completed. I am using dreamweaver so it is generating the PHP for me(Dont really understand php enough to write myself). I will post the code and a screenshot to give a better idea of what i am asking.

Basically my problem is when I select an item from the drop down tables and logged in it does not write to my user id. For example If i select Chelsea for the Premier League instead of writing to the premier league field on my user table it creates a whole new user id. I think the problem must be when i am creating a session(I have no experience in creating sessions so am probably doing it wrong!)

If anyone can point me in the right direction that would be great. I will post my code if required, the page is 500 lines or that so i dont want to overwhelm the post!

laika1986,

It is really tough to help you when knowing that you won’t understand the PHP help we provide. Also, we have no idea what Dreamweaver created for you so it is not even a good idea for any of us to theorize what might be happening.

If you are to build a system that requires HTML (CSS + JavaScript), PHP and Database you really need to have an understand what is happening. You might consider getting a low cost e-file of something like PHP & MYSQL NOVICE TO NINJA, 5TH EDITION which has no assumptions a reader has prior knowledge, and walks you through the basics until you may have enough understanding to know what you are doing.

Steve

Thanks for your reply. I have somewhat figured out my problem and am in the process of changing code at the moment. I will post my code tomorrow and hopefully that will help. I will try to explain the logic. First i have a user table that i want to populate from drop down bars. At the moment once i submit a record it rights to the first row everytime instead of the user that is logged in. I am struggling with the php to write to the currently logged in user. I hope i have made it a little clearer and I will post my code once i have it improved. Thanks again

<?php

session_start();

?>


<?php require_once('../Connections/Server.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form9")) {
  $updateSQL = sprintf("UPDATE tbluser SET premierleague=%s WHERE userid=%s",
                       GetSQLValueString($_POST['premierleague'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tbluser SET premierleague=%s WHERE userid=%s",
                       GetSQLValueString($_POST['premierleague'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE tbluser SET championship=%s WHERE userid=%s",
                       GetSQLValueString($_POST['championship'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form3")) {
  $updateSQL = sprintf("UPDATE tbluser SET laliga=%s WHERE userid=%s",
                       GetSQLValueString($_POST['laliga'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form4")) {
  $updateSQL = sprintf("UPDATE tbluser SET seriea=%s WHERE userid=%s",
                       GetSQLValueString($_POST['seriea'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form5")) {
  $updateSQL = sprintf("UPDATE tbluser SET championsleague=%s WHERE userid=%s",
                       GetSQLValueString($_POST['championsleague'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form6")) {
  $updateSQL = sprintf("UPDATE tbluser SET eredivisie=%s WHERE userid=%s",
                       GetSQLValueString($_POST['eredivisie'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form7")) {
  $updateSQL = sprintf("UPDATE tbluser SET ligueone=%s WHERE userid=%s",
                       GetSQLValueString($_POST['ligueone'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form8")) {
  $updateSQL = sprintf("UPDATE tbluser SET bundesliga=%s WHERE userid=%s",
                       GetSQLValueString($_POST['bundesliga'], "text"),
                       GetSQLValueString($_POST['userid'], "int"));

  mysql_select_db($database_Server, $Server);
  $Result1 = mysql_query($updateSQL, $Server) or die(mysql_error());
}

mysql_select_db($database_Server, $Server);
$query_rstpremierleague = "SELECT * FROM tblpremierleague ORDER BY premierleaguename ASC";
$rstpremierleague = mysql_query($query_rstpremierleague, $Server) or die(mysql_error());
$row_rstpremierleague = mysql_fetch_assoc($rstpremierleague);
$totalRows_rstpremierleague = mysql_num_rows($rstpremierleague);

mysql_select_db($database_Server, $Server);
$query_rstchampionship = "SELECT * FROM tblchampionship ORDER BY championshipname ASC";
$rstchampionship = mysql_query($query_rstchampionship, $Server) or die(mysql_error());
$row_rstchampionship = mysql_fetch_assoc($rstchampionship);
$totalRows_rstchampionship = mysql_num_rows($rstchampionship);

mysql_select_db($database_Server, $Server);
$query_rstbundesliga = "SELECT * FROM tblbundesliga ORDER BY bundesligaName ASC";
$rstbundesliga = mysql_query($query_rstbundesliga, $Server) or die(mysql_error());
$row_rstbundesliga = mysql_fetch_assoc($rstbundesliga);
$totalRows_rstbundesliga = mysql_num_rows($rstbundesliga);

mysql_select_db($database_Server, $Server);
$query_rstligueone = "SELECT * FROM tblligueone ORDER BY ligueonename ASC";
$rstligueone = mysql_query($query_rstligueone, $Server) or die(mysql_error());
$row_rstligueone = mysql_fetch_assoc($rstligueone);
$totalRows_rstligueone = mysql_num_rows($rstligueone);

mysql_select_db($database_Server, $Server);
$query_rstseriea = "SELECT * FROM tblseriea ORDER BY serieAname ASC";
$rstseriea = mysql_query($query_rstseriea, $Server) or die(mysql_error());
$row_rstseriea = mysql_fetch_assoc($rstseriea);
$totalRows_rstseriea = mysql_num_rows($rstseriea);

mysql_select_db($database_Server, $Server);
$query_rsteredivisie = "SELECT * FROM tbleredivise ORDER BY eredivisename ASC";
$rsteredivisie = mysql_query($query_rsteredivisie, $Server) or die(mysql_error());
$row_rsteredivisie = mysql_fetch_assoc($rsteredivisie);
$totalRows_rsteredivisie = mysql_num_rows($rsteredivisie);

mysql_select_db($database_Server, $Server);
$query_rstlaliga = "SELECT * FROM tbllaliga ORDER BY laliganame ASC";
$rstlaliga = mysql_query($query_rstlaliga, $Server) or die(mysql_error());
$row_rstlaliga = mysql_fetch_assoc($rstlaliga);
$totalRows_rstlaliga = mysql_num_rows($rstlaliga);

mysql_select_db($database_Server, $Server);
$query_rstchampionsleague = "SELECT * FROM tblchampionsleague ORDER BY championsleagueName ASC";
$rstchampionsleague = mysql_query($query_rstchampionsleague, $Server) or die(mysql_error());
$row_rstchampionsleague = mysql_fetch_assoc($rstchampionsleague);
$totalRows_rstchampionsleague = mysql_num_rows($rstchampionsleague);

mysql_select_db($database_Server, $Server);
$query_rsttest = "SELECT * FROM tblpremierleague ORDER BY premierleaguename ASC";
$rsttest = mysql_query($query_rsttest, $Server) or die(mysql_error());
$row_rsttest = mysql_fetch_assoc($rsttest);
$totalRows_rsttest = mysql_num_rows($rsttest);

mysql_select_db($database_Server, $Server);
$query_rstmybet = "SELECT userid, premierleague, championship, seriea, laliga, ligueone, championsleague, eredivisie, bundesliga FROM tbluser";
$rstmybet = mysql_query($query_rstmybet, $Server) or die(mysql_error());
$row_rstmybet = mysql_fetch_assoc($rstmybet);
$totalRows_rstmybet = mysql_num_rows($rstmybet);
?>
<?php require_once('../Connections/Server.php'); ?>

<?php require_once('../Connections/Server.php'); ?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Big Fat Bet of the Year</title>
<link rel="shortcut icon" href="images/football.jpg" />
<link rel="stylesheet" text="text/css" href="betcss.css"/>

</head>

	
<body>
	

<img style="padding-left:95px;" src="../images/logo.png" align="center" width="1041" height="175" alt="My Big Fat Bet of the Year">
	
	  <div id="header" align="center"> <span class="events h1">
	<h2 ><a href="home.php" >Home</a></h2>
		
    <h2><a href="events.php">Events</a></h2>
		
	<h2><a href="leaderboard.php">Leaderboard</a></h2>
	
	<h2><a href="register.php">Register</a></h2>
		
	<h2><a href="mybet.php">MyBet</a></h2>
		
        </span></div>

    <div align="right">

      <?php
	
	if ($_SESSION['MM_UserGroup']==1)	{
		
		echo "<a href=profile.php>Admin</a>";
		echo"I";
		echo "<a href=logout.php>Logout</a>";
	
		
		}
	elseif($_SESSION['MM_UserGroup']==2){
		
		echo "<a href=profile.php>Profile</a>";
		echo "I";
		echo "<a href=logout.php>Logout</a>";
	}
	else {
		
		echo "<a href=login.php>Login</a>I<a href=register.php>Register</a>";
	}
	?>
    </div>

	
	<div id="sidebar" align="left">

    <h2 ><a href="home.php" >Home</a></h2>
	
    <h2><a href="events.php">Events</a></h2>
		
	<h2><a href="leaderboard.php">Leaderboard</a></h2>
	
	<h2><a href="register.php">Register</a></h2>
		
<h2><a href="mybet.php">MyBet</a></h2></div>


	<br />

    <span class="events h1">
    <h1><u><strong>MyBet</strong></u></h1>
    </span>
    <div id="main">

<table width="500" align="center" >
        <tr>
   <th width="125" scope="col"><img src="../images/premierleague.gif" width="125" height="100" alt="Premier League" </th>
   <th width="125" scope="col"><img src="../images/championship.jpg" width="125" height="100" alt="Championship" </th>
   <th width="125" scope="col"><img src="../images/laliga.jpg" width="125" height="100" alt="La Liga" </th>
   <th width="125" scope="col"><img src="../images/seriea.jpg" width="125" height="100" alt="Serie A" </th>
      </tr>
        <tr>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="premierleague">
                    <?php
do {
?>
                    <option value="<?php echo $row_rstpremierleague['premierleagueid']?>" <?php if (!(strcmp($row_rstpremierleague['premierleagueid'], htmlentities($row_rstmybet['premierleague'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rstpremierleague['premierleaguename']?></option>
                    <?php
} while ($row_rstpremierleague = mysql_fetch_assoc($rstpremierleague));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form1" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="championship">
                    <?php
do {
?>
                    <option value="<?php echo $row_rstchampionship['championshipid']?>" <?php if (!(strcmp($row_rstchampionship['championshipid'], htmlentities($row_rstmybet['championship'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rstchampionship['championshipname']?></option>
                    <?php
} while ($row_rstchampionship = mysql_fetch_assoc($rstchampionship));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form2" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form3" id="form3">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="laliga">
                    <?php
do {
?>
                    <option value="<?php echo $row_rstlaliga['laligaid']?>" <?php if (!(strcmp($row_rstlaliga['laligaid'], htmlentities($row_rstmybet['laliga'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rstlaliga['laliganame']?></option>
                    <?php
} while ($row_rstlaliga = mysql_fetch_assoc($rstlaliga));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form3" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form4" id="form4">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="seriea">
                    <?php
do {
?>
                    <option value="<?php echo $row_rstseriea['serieaid']?>" <?php if (!(strcmp($row_rstseriea['serieaid'], htmlentities($row_rstmybet['seriea'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rstseriea['serieAname']?></option>
                    <?php
} while ($row_rstseriea = mysql_fetch_assoc($rstseriea));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form4" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
        </tr>
</table>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <table width="500" align="center">
        <tr>
          <th width="125" scope="col"><img src="../images/CL.jpg" width="125" height="100" alt="Champions League" /></th>
          <th width="125" scope="col"><img src="../images/eredivisie.jpg" width="125" height="100" alt="Eredivisie" /></th>
          <th width="125" scope="col"><img src="../images/ligue1.jpg" width="125" height="100" alt="Ligue One" /></th>
          <th width="125" scope="col"><img src="../images/Bundesliga.jpg" width="125" height="100" alt="Bundesliga" /></th>
        </tr>
        <tr>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form5" id="form5">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="championsleague">
                    <?php
do {
?>
                    <option value="<?php echo $row_rstchampionsleague['championsleagueid']?>" <?php if (!(strcmp($row_rstchampionsleague['championsleagueid'], htmlentities($row_rstmybet['championsleague'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rstchampionsleague['championsleagueName']?></option>
                    <?php
} while ($row_rstchampionsleague = mysql_fetch_assoc($rstchampionsleague));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form5" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form6" id="form6">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="eredivisie">
                    <?php
do {
?>
                    <option value="<?php echo $row_rsteredivisie['erediviseid']?>" <?php if (!(strcmp($row_rsteredivisie['erediviseid'], htmlentities($row_rstmybet['eredivisie'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rsteredivisie['eredivisename']?></option>
                    <?php
} while ($row_rsteredivisie = mysql_fetch_assoc($rsteredivisie));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form6" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form7" id="form7">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="ligueone">
                    <?php
do {
?>
                    <option value="<?php echo $row_rstligueone['ligueoneid']?>" <?php if (!(strcmp($row_rstligueone['ligueoneid'], htmlentities($row_rstmybet['ligueone'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rstligueone['ligueonename']?></option>
                    <?php
} while ($row_rstligueone = mysql_fetch_assoc($rstligueone));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form7" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
          <td>&nbsp;
            <form action="<?php echo $editFormAction; ?>" method="post" name="form8" id="form8">
              <table align="center">
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"></td>
                  <td><select name="bundesliga">
                    <?php
do {
?>
                    <option value="<?php echo $row_rstbundesliga['bundesligaID']?>" <?php if (!(strcmp($row_rstbundesliga['bundesligaID'], htmlentities($row_rstmybet['bundesliga'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_rstbundesliga['bundesligaName']?></option>
                    <?php
} while ($row_rstbundesliga = mysql_fetch_assoc($rstbundesliga));
?>
                  </select></td>
                </tr>
                <tr> </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Update record" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_update" value="form8" />
              <input type="hidden" name="userid" value="<?php echo $row_rstmybet['userid']; ?>" />
            </form>
          <p>&nbsp;</p></td>
        </tr>
      </table>
<div id="header" align="center"> <span class="events h1">
	<h2 ><a href="home.php" >Home</a></h2>
		
    <h2><a href="events.php">Events</a></h2>
		
	<h2><a href="leaderboard.php">Leaderboard</a></h2>
	
	<h2><a href="register.php">Register</a></h2>
		
	<h2><a href="mybet.php">MyBet</a></h2>
		
        </span></div>



</body>


</html>
<?php
mysql_free_result($rstpremierleague);

mysql_free_result($rstchampionship);

mysql_free_result($rstbundesliga);

mysql_free_result($rstligueone);

mysql_free_result($rstseriea);

mysql_free_result($rsteredivisie);

mysql_free_result($rstlaliga);

mysql_free_result($rstchampionsleague);

mysql_free_result($rsttest);

mysql_free_result($rstmybet);
?>