Jump to content

What is wrong with this select statement?!


lowe_22

Recommended Posts

I have a script to put members into a database
This part is supposed to select the auto_incremented field memberID from the database when the member name is a user defined Session - $_SESSION['master'].

For some reason, it is not inserting the masterID into the database! I dont know why!

Here is the code:

[code]$sql = "SELECT memberID FROM tblmembers WHERE memberName=".$_SESSION['master'];
if ($result = mysql_query($sql)) {
list($masterID)= mysql_fetch_row($result);
$_SESSION['masterID']=$masterID;
}

userindb($_SERVER['nickname']);
if ($indb==true) {
$error = "Error: That member is already in the database!";
}else{
//add info to DB without star color or initials
$sql = "INSERT INTO tblmembers (memberName, memberRank, memberMasterID, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $masterID . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')";[/code]
Link to comment
Share on other sites

Ok, ive changed my code. But it still doesnt work! I've no idea why not!

Here is the script in its entirity to see if it helps!!!

All the session variables are passed to this script from a user posted form in a previous script. This scrpt is supposed to check to see that the data they entered is correct (which works) then enters the necessary detaisl into the database, depending on whther certain fileds have been fillled out or not (sort of woks, minus the master ID thing...)

Its driving me insane...


[code]
<?php session_start();
include('../inc/inc.php');

checklogin();

if (isset($_POST['yes'])) {
$nickname=$_SESSION['nickname'];
userindb($nickname);
if ($indb==true) {
$error = "Error: That member is already in the database!";
}else{
$memberActive = "1";
$memberBanned = "0";

// No Master...
if ($_SESSION['master']=="No Master"){

//add info to DB without master...
$sql = "INSERT INTO tblmembers (memberName, memberRank, memberStarColor, memberInitials, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $_SESSION['starcolor'] . "', '" . $_SESSION['initials'] . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')";
if ($result = mysql_query($sql)) {
header('Location: add.php?action=added');
}

} elseif (($_SESSION['starcolor']=="-- No Color --") || ($_SESSION['initials']=="")){ // No star color or intials

// Get the ID of member's matser
$sql = "SELECT * FROM tblmembers WHERE memberName=".$_SESSION['master'];
if ($result = mysql_query($sql)) {
$row = mysql_fetch_array($result);
$masterID = $row['memberMasterID'];
$_SESSION['masterID'] = $row['memberMasterID'];
}
//add info to DB without star color or initials
$sql = "INSERT INTO tblmembers (memberName, memberRank, memberMasterID, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $masterID . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')";

if ($result = mysql_query($sql)) {
header('Location: add.php?action=added');
}
}else{

// convert to master to a member ID to get their star colours etc...
$sql = "SELECT memberID FROM tblmembers WHERE memberName = ".$_SESSION['master'];
if ($result = mysql_query($sql)) {
$row = mysql_fetch_array($result);
$masterID = $row['memberMasterID'];
$_SESSION['masterID'] = $row['memberMasterID'];
}

// insert info into database
$sql = "INSERT INTO tblmembers (memberName, memberRank, memberStarColor, memberInitials, memberMasterID, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $_SESSION['starcolor'] . "', '" . $_SESSION['initials'] . "', '" . $masterID . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')";
if ($result = mysql_query($sql)) {
header('Location: add.php?action=added');
}
}

}
}

if (isset($_POST['no'])) {
header('Location:add.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>LightSaber SithElite - Members Admin - Add</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css" media="screen">
/* <![CDATA[ */
@import url(../../style.css);
/* ]]> */
</style>
<!--[if IE 6]>
<style>
#navigation ul {padding-top:9px; margin:-1px -2.1px 0 -3px;}
#navigation ul li a {padding:1.2em 1.7em 1.42em 1.7em;}
.first {margin-left:-0.3em;}
</style>
<![endif]-->
</head>
<body>
<div id="wrapper">
  <div id="logo"></div>
  <div id="toplinks">
    <ul>
      <li><a href="../../index.php">Home</a></li>
      <li><a href="http://ehonu.com/lsforum">Forum</a></li>
      <li><a href="../../contact.php">Contact</a></li>
    </ul>
  </div>
  <div id="banner"> <img src="../../images/banner2.jpg" alt="Banner"/> </div>
  <div id="navContainer">
    <div id="navigation">
      <ul>
        <li><a href="../../index.php">home</a></li>
        <li><a href="../../../lsforum">forum</a></li>
        <li><a href="../../about.php">about</a></li>
        <li><a href="../../news.php">news</a></li>
        <li><a href="../../members.php">members</a></li>
        <li><a href="../../servers.php">servers</a></li>
        <li><a href="../../tournaments.php">tournaments</a></li>
        <li><a href="../../los.php">league of sith</a></li>
        <li><a href="../../downloads.php">downloads</a></li>
        <li><a href="../../allies.php">allies</a></li>
        <li class="last"><a href="../help.php">help</a></li>
      </ul>
    </div>
  </div>
  <div id="content">
    <div id="mainContent">
      <h1>site<span class=red>admin</span> - confirm</h1>
      <div id="news">
        <? if (isset($error)) {
  echo "<p class=err>".$error."</p>";
  }
  ?>
        <? if ($_GET['action']=="add") {
echo "<p class=ok>Thank you. Please confirm that the information you have chosen is correct.</p><br/>";
echo "Nickname: " . $_SESSION['nickname'] . "<br />";
echo "Email: ".$_SESSION['email']."<br />";

if (empty($_SESSION['realname'])){
echo    "Real Name: Not Specified.<br />";
}else{
echo "Real Name: ".$_SESSION['realname']."<br />";
}

echo "Master: ".$_SESSION['master']."<br />";
echo    "Rank: ".$_SESSION['rank']."<br />";

if (in_array($_SESSION['rank'], $highranks)){
echo "Star Color: ".$_SESSION['starcolor']."<br />";
}else{
echo "Star Color: Not Required<br />";
}

if (in_array($_SESSION['rank'], $highranks)){
echo "Initials: ".$_SESSION['initials']."<br />";
}else{
echo "Initials: Not Required<br />";
}

echo "<br><p>Is this information correct?</p><br /><br />";
echo "<form name=\"form2\" action=" . $_SERVER['PHP_SELF'] . " method=\"POST\" class=\"register-form\" id=\"form1\">";
echo "<input type=\"hidden\" value=\"\" /><span style=\"display:inline;\"><input type=\"submit\" name=\"yes\" class=\"btn\" value=\"Yes\">";
echo "<input type=\"submit\" name=\"no\" class=\"btn\" value=\"No\"></span>";
echo "</form>";
}
?>
        <br />
        <br />
        <? if (isset($error)){ echo "<p class=\"err\">This member is already in the database!</p><br />"; } ?>
        <p> <br />
          <br />
      </div>
    </div>
    <div id="sidebar">
      <div id="adminlinks">
        <ul>
          <li><a href="../../main.php">Home</a></li>
          <li><a href="add.php">Add Member</a></li>
          <li><a href="change.php">Promote / Demote Member</a></li>
          <li><a href="edit.php">Edit Member</a></li>
          <li><a href="delete.php">Delete Member</a></li>
          <li><a href="logout.php?logout=true">Logout</a></li>
        </ul>
      </div>
    </div>
  </div>
  <div id="footer">
    <p>copyright &copy; LightSaber SithElite 2006. design by b0ss.</p>
  </div>
</div>
</body>
</html>
[/code]
Link to comment
Share on other sites

I found the problem.

mySQL didnt like me trying to select from a Session variable on this line:

[code]
<?php
// Get the ID of member's matser
$sql = "SELECT * FROM tblmembers WHERE memberName=".$_SESSION['master'];
?>
[/code]

so ther value for masterId was not populating correctly... etc :D
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.