0

Hey, guys. I have this code here, and for some reason, it won't update the data! At all! When you press 'submit', it just reloads the data that was already on the DB table. It's really confusing!!!

<?
	include_once ("../auth.php");
	include_once ("../authconfig.php");
	include_once ("../check.php");
	
	$connection = mysql_connect($dbhost, $dbusername, $dbpass);
	$SelectedDB = mysql_select_db($dbname);
	
	/*
	if (isset($_GET['username']))
	{
		$username = $_GET['username'];
	}
	elseif (isset($DetailsRow['username']))
	{
		$username = $DetailsRow['username'];
	}

	else
	{
		// Feel free to change the error message below. Just make sure you put a "\" before
		// any double quote.
		print "<font face=\"Arial, Helvetica, sans-serif\" size=\"5\" color=\"#FF0000\">";
		print "<b>Access Denied!</b>";
		print "</font><br>";
  		print "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"#000000\">";
		print "<b>You are not allowed to access this page.</b></font>";
		
		exit; // End program execution. This will disable continuation of processing the rest of the page.
	}
	*/
	
	$username = $USERNAME;
?>
<?
	if (isset($DetailsRow['Submit']))
	{
		//$username = $DetailsRow['username'];
		$username = $DetailsRow['username'];
		$email = $DetailsRow['email'];
		$password = $DetailsRow['password'];
		$fname = $DetailsRow['fname'];
		$lname = $DetailsRow['lname'];
		$mname = $DetailsRow['mname'];
		$dob = $DetailsRow['dob'];
		$address = $DetailsRow['address'];
		$city = $DetailsRow['city'];
		$state = $DetailsRow['state'];
		$zipcode = $DetailsRow['zipcode'];
		$license = $DetailsRow['license'];
		$carmake = $DetailsRow['carmake'];
		$carmodel = $DetailsRow['carmodel'];
		$engine = $DetailsRow['engine'];
		$class = $DetailsRow['class'];
		$doc = $DetailsRow['doc'];
		$docnum = $DetailsRow['docnum'];
		$primecon = $DetailsRow['primecon'];
		$primeconrel = $DetailsRow['primeconrel'];
		$primeconnum = $DetailsRow['primeconnum'];
		$seccon = $DetailsRow['seccon'];
		$secconrel = $DetailsRow['secconrel'];
		$secconnum = $DetailsRow['secconnum'];
		$status = $DetailsRow['status'];	// flag that says if user exists in the signup table or not
		
		// Error Checking to make sure that all required fields are filled out
		$action = 1;
		if ($fname == "")
		{
			$message = "First Name field cannot be left blank!";
			$action = 0;
		}
		elseif ($email == "")
		{
			$message = "E-mail field cannot be left blank!";
			$action = 0;
		}
		elseif ($lname == "")
		{
			$message = "Last Name field cannot be left blank!";
			$action = 0;
		}
		elseif ($dob == "")
		{
			$message = "Date of Birth field cannot be left blank!";
			$action = 0;
		}
		elseif ($address == "")
		{
			$message = "Address field cannot be left blank!";
			$action = 0;
		}
		elseif ($city == "")
		{
			$message = "City field cannot be left blank!";
			$action = 0;
		}
		elseif ($state == "")
		{
			$message = "State field cannot be left blank!";
			$action = 0;
		}
		elseif ($zipcode == "")
		{
			$message = "Zip Code field cannot be left blank!";
			$action = 0;
		}
		elseif ($license == "")
		{
			$message = "Driver's License field cannot be left blank!";
			$action = 0;
		}
		elseif ($carmake == "")
		{
			$message = "Make of Car field cannot be left blank!";
			$action = 0;
		}
		elseif ($carmodel == "")
		{
			$message = "Car Model field cannot be left blank!";
			$action = 0;
		}
		elseif ($engine == "")
		{
			$message = "Engine field cannot be left blank!";
			$action = 0;
		}
		elseif ($doc == "")
		{
			$message = "Primary Physician field cannot be left blank!";
			$action = 0;
		}
		elseif ($docnum == "")
		{
			$message = "Primary Physician's Number field cannot be left blank!";
			$action = 0;
		}
		elseif ($primecon == "")
		{
			$message = "Primary Contact field cannot be left blank!";
			$action = 0;
		}
		elseif ($primeconrel == "")
		{
			$message = "Primary Contact's Relationship field cannot be left blank!";
			$action = 0;
		}
		elseif ($primeconnum == "")
		{
			$message = "Primary Contact's Number field cannot be left blank!";
			$action = 0;
		}
		elseif ($seccon == "")
		{
			$message = "Secondary Contact field cannot be left blank!";
			$action = 0;
		}
		elseif ($secconrel == "")
		{
			$message = "Secondary Contact's Relationship field cannot be left blank!";
			$action = 0;
		}
		elseif ($secconnum == "")
		{
			$message = "Secondary Contact's Number field cannot be left blank!";
			$action = 0;
		}
		
		else
		{		
			// If user was added in control panel, we need to use INSERT to create a user record
			// in the signup table
			if ($status == 0 && $action != 0)
			{
				$qNewDetails = "INSERT INTO signup VALUES ('', '$username', '$email', '$fname', '$lname', '$mname', '$dob', '$address', '$city', '$state', '$zipcode', '$license', '$carmake', '$carmodel', '$engine', '$class', '$doc', '$docnum', '$primecon', '$primeconrel', '$primeconnum', '$seccon', '$secconrel', '$secconnum', '', '')";
			}
			elseif ($status == 1 && $action != 0)
			{
				$qNewDetails = "UPDATE signup SET fname='$fname', lname='$lname', mname='$mname', email='$email', dob='$dob', address='$address', city='$city', state='$state', zipcode='$zipcode', license='$license', carmake='$carmake', carmodel='$carmodel', engine='$engine', class='$class', doc='$doc', docnum='$docnum', primecon='$primecon', primeconrel='$primeconrel', primeconnum='$primeconnum', seccon='$seccon', secconrel='$secconrel', secconnum='$secconnum' WHERE username='$username'";
			}
			
			
			if (mysql_query($qNewDetails))
			{
				$message = "User details updated successfully!";
				$action = 1;
			}
			else
			{
				$message = "There was a problem udpating the user details.";
				$action = 0;
			}
		}
	}
	
	// Ger user details for data population below
	$qUserDetails = "SELECT * FROM signup where username='$username'";
	$UserDetails = mysql_query($qUserDetails);
	if (mysql_num_rows($UserDetails))
	{
		$DetailsRow = mysql_fetch_array($UserDetails);	
		$username = $DetailsRow['username'];
		$email = $DetailsRow['email'];
		$password = $DetailsRow['password'];
		$fname = $DetailsRow['fname'];
		$lname = $DetailsRow['lname'];
		$mname = $DetailsRow['mname'];
		$dob = $DetailsRow['dob'];
		$address = $DetailsRow['address'];
		$city = $DetailsRow['city'];
		$state = $DetailsRow['state'];
		$zipcode = $DetailsRow['zipcode'];
		$license = $DetailsRow['license'];
		$carmake = $DetailsRow['carmake'];
		$carmodel = $DetailsRow['carmodel'];
		$engine = $DetailsRow['engine'];
		$class = $DetailsRow['class'];
		$doc = $DetailsRow['doc'];
		$docnum = $DetailsRow['docnum'];
		$primecon = $DetailsRow['primecon'];
		$primeconrel = $DetailsRow['primeconrel'];
		$primeconnum = $DetailsRow['primeconnum'];
		$seccon = $DetailsRow['seccon'];
		$secconrel = $DetailsRow['secconrel'];
		$secconnum = $DetailsRow['secconnum'];
		$status = 1; // means user exists in the signup table
	}
	else
	{
		$username = '';
		$email = '';
		$password = '';
		$fname = '';
		$lname = '';
		$mname = '';
		$dob = '';
		$address = '';
		$city = '';
		$state = '';
		$zipcode = '';
		$license = '';
		$carmake = '';
		$carmodel = '';
		$engine = '';
		$class = '';
		$doc = '';
		$docnum = '';
		$primecon = '';
		$primecon = '';
		$primeconnum = '';
		$seccon = '';
		$seccon = '';
		$secconnum = '';
		$status = 0; // means user does not exist in the signup table
		$message = "";
	}
?>
<html>
<head>
<title>Sample User Login Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<p><font face="Helvetica, Verdana, Arial, sans-serif" size="5"><b>Sample User Login Results</b></font>
</p>
<form name="signup" method="POST" action="userdetail.php">
  <table width="75%" border="1" cellspacing="0" cellpadding="0" align="left">
<tr valign="middle"> 
      <td width="17%" bgcolor="#CCCCCC"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#990000">Username</font></b></td>
      <td width="83%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
        &nbsp;<input type="text" name="username" size="20" maxlength="20" value="<?php echo $username; ?>">
        </font></b></td>
  </tr>
    <tr valign="middle"> 
      <td width="17%" bgcolor="#CCCCCC"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#990000">Password</font></b></td>
      <td width="83%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
        &nbsp;<input type="password" name="password" size="20" maxlength="20" value="<?php echo stripslashes($password); ?>">
        </font></b></td>
  </tr>
   <tr valign="middle"> 
            <td width="27%" bgcolor="#33CCFF"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">&nbsp;</font></td>
            <td width="73%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000099">&nbsp;&nbsp;Leave
              the password field blank if you want to retain the old password. 
              </font></td>
          </tr>
      <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2" color="#000000">Email Address</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="email" size="45" maxlength="45" value="<?php echo $email; ?>">
        </font></b></td>
  </tr>
    <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF">&nbsp;</td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2"><strong>Personal Information:</strong></font></b></td>
  </tr>
    <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2" color="#000000">First Name</font></b></td>
      <td width="83%" bgcolor="#FFFFFF" bgcolor="#DDE4FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="fname" size="30" maxlength="30" value="<?php echo $fname; ?>">
        </font></b></td>
  </tr>
    <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2" color="#000000">Last Name</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="lname" size="20" maxlength="20" value="<?php echo $lname; ?>">
        </font></b></td>
  </tr>
      <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2" color="#000000">Middle Initial</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="mname" size="5" maxlength="1" value="<?php echo $mname; ?>">
        </font></b></td>
  </tr>
    <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Date of Birth <small>(MM/DD/YYYY format)</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="dob" size="15" maxlength="15" value="<?php echo $dob; ?>">
        </font></b></td>
  </tr>
      <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Address</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="address" size="30" maxlength="30" value="<?php echo $address; ?>">
        </font></b></td>
  </tr>
        <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">City</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="city" size="20" maxlength="15" value="<?php echo $city; ?>">
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">State</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="state" size="20" maxlength="15" value="<?php echo $state; ?>">
        </font></b></td>
  </tr>
    <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Zip Code</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="zipcode" size="15" maxlength="10" value="<?php echo $zipcode; ?>">
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Driver's License</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="license" size="25" maxlength="20" value="<?php echo $license; ?>">
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Make of Car:</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="carmake" size="15" maxlength="15" value="<?php echo $carmake; ?>">
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Model of Car:</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="carmodel" size="15" maxlength="15" value="<?php echo $carmodel; ?>">
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Engine Setup<BR><small>(Engine type, Mods, etc.)</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="engine" size="30" maxlength="30" value="<?php echo $engine; ?>">
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Class</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<select name="class"  value="<?php echo $class; ?>">
			<option value="a">Class A</option>
			<option value="b">Class B</option>
			</select>
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">&nbsp;</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;
        </font></b></td>
  </tr>
          <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2"></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<strong>Emergency Contact information:</strong>
        </font></b></td>
  </tr>
            <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">&nbsp;</font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;
        </font></b></td>
  </tr>
            <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Primary Physician:</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="doc" size="15" maxlength="15" value="<?php echo $doc; ?>">
        </font></b></td>
  </tr>
            <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Primary Physician's Number</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="docnum" size="15" maxlength="15" value="<?php echo $docnum; ?>">
        </font></b></td>
  </tr>
              <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Primary Contact:</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="primecon" size="15" maxlength="15" value="<?php echo $primecon; ?>">
        </font></b></td>
  </tr>
              <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Primary Contact's Relation:</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="primeconrel" size="15" maxlength="15" value="<?php echo $primeconrel; ?>">
        </font></b></td>
  </tr>
              <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Primary Contact's Number:</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="primeconnum" size="15" maxlength="15" value="<?php echo $primeconnum; ?>">
        </font></b></td>
  </tr>
                <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Secondary Contact:</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="seccon" size="15" maxlength="15" value="<?php echo $seccon; ?>">
        </font></b></td>
  </tr>
              <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Secondary Contact's Relation:</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="secconrel" size="15" maxlength="15" value="<?php echo $secconrel; ?>">
        </font></b></td>
  </tr>
              <tr valign="middle"> 
      <td width="17%" bgcolor="#DDE3FF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">Secondary Contact's Number:</small></font></b></td>
      <td width="83%" bgcolor="#FFFFFF"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2">
        &nbsp;<input type="text" name="secconnum" size="15" maxlength="15" value="<?php echo $secconnum; ?>">
        </font></b></td>
  </tr>
    <tr valign="middle"> 
      <td colspan="2" bgcolor="#FFFFCC">
        <div align="center"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2"></font></b><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2"> 
		  <!--<input type="hidden" name="username" value="<?php echo $username; ?>">-->			  
		  <input type="hidden" name="status" value="<?php echo $status; ?>">					  
		  <input type="submit" name="Submit" value="Save Changes">&nbsp;
          <input type="reset" name="Reset" value="Reset">
          </font></b></div>
      </td>
  </tr>
    <tr valign="middle">
      <td colspan="2" bgcolor="#FFFFCC">
	  <a href="index.php">
	  <font size="2" face="Helvetica, Verdana, Arial, sans-serif">&lt;&lt; Back</font></a></td>
    </tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<table width="75%" border="1" cellspacing="0" cellpadding="0" align="left" bordercolor="#000000">
  <tr>
    <td bgcolor="#990000"><b><font face="Helvetica, Verdana, Arial, sans-serif" size="2" color="#FFFFCC">Message:</font></b></td>
  </tr>
  <tr>
    <td><font face="Helvetica, Verdana, Arial, sans-serif" size="2" color="#0000FF">
      <?
		  	if (isset($message)) 
			{
			 	print $message;
		  	}
			else 
			{
				print "<BR>";
			}
		  ?>
    </font></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by hielo
0

On lines 37-64, you cannot have $DetailsRow because you have NOT queried the db. It looks like what you need is the data that was just POSTed. So change $DetailsRow to $_POST

Edited by hielo: n/a

0

I actually have changed it to that since then.
However, when I go to press 'submit', it refreshes the page and wipes all the fields clean... it doesn't save anything to the DB, but it also doesn't show any old or new information.

0

>> $username = $USERNAME; Where did you initialize $USERNAME? Most likely your query is not returning any results.

Edited by hielo: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.