New problem now updting a member!

Discussion in 'PHP' started by lounar, Nov 11, 2007.

  1. #1
    well here is the code...the problem is that when i push the save button i get an error if u want further information let me know!
    <?php
    
    session_start();
    
    
    
    include ('inc/validation.php');
    
    include ('inc/header.php');
    
    
    
    if ($_POST['verifySubmit'] == "yes"){
    
    
    
    
    
               include ('inc/db_open.php');
    
    
    
    			$id = $_POST['id'];
    
    			$username = $_REQUEST['username'];
    
    	$password = $_POST['password'];
    
    	$name = $_POST['name'];
    	
    	$access = $_POST['Status'];
    
    
    
    			// Insert the user to the Database.
    
    			$request = "UPDATE members, user SET 
    
    				user.username='$username', user.pass=PASSWORD('$password'), members.name='$name',
    
    			 members.status='$access',
    
    				
    
    				WHERE user.memID='$id' AND members.memID='$id'";
    
    			$result = mysql_query($request) or die ('Query failed'.mysql_error());
    
    			
    
    			if($result == 1){
    
    			?>
    
    				<script type="text/javascript">
    
    				window.location="viewmember.php?id=<?php echo $id; ?> ";
    
    				</script>
    
    			<?php
    
    			}	   
    
          }
    
    	  		else {
    
                echo "<font color=red>$error_msg</font>";
    
          }
    
    
    
    
    
    include ('inc/db_open.php');
    
    $id = $_GET['id'];
    
    $sql = "SELECT * FROM members, user WHERE members.memID='$id' AND user.memID='$id'";
    
    $result = mysql_query($sql)or die('Query failed'.mysql_error());
    
    $row=mysql_fetch_array($result); 
    
    ?>
    
    
    
    
    
    
    <script type="text/javascript" language="javascript">
    
    
    
    function pcheck(str) {
    
    
    
    
    
    		if (str.length > 15) {
    
            	alert('Please Enter A Smaller Password');
    
            	return false;
    
        	}
    
    		
    
        	if (str.length < 5) {
    
            	alert('Please Enter A Longer Password');
    
            	return false;
    
        	}
    
    		
    
    		var pass_string = document.newmember.password.value;
    
    		
    
    		var valid = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
    
    
       		for (var i=0; i < document.newmember.password.value.length; i++) {
    
            	if (valid.indexOf(pass_string.charAt(i)) < 0) {
    
                alert('Your password contains invalid characters');
    
                return false;
    
            }
    
        }
    
    
    
    		var hasNumber = 0;
    
    		var hasString = 0;
    
    	
    
    		var num_valid="123456789";
    
    		var alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
    
    
    	
    
        	for (var i=0; i<document.newmember.password.value.length; i++) {
    
            	if (num_valid.indexOf(pass_string.charAt(i)) >= 0) {
    
                	hasNumber += 1 ;
    
            	}
    
    			if (alph_valid.indexOf(pass_string.charAt(i)) >= 0){
    
    			hasString = hasString + 1;
    
    			}
    
    
    
    		}
    
    		 
    
    		if (hasNumber > 0 && hasString == 0){
    
    			alert('Your password contains only numbers. Please enter an alphanumeric value like -alpha1-');
    
                return false;
    
    		}
    
    		if (hasNumber == 0 && hasString > 0){
    
    			alert('Your password contains only characters. Please enter an alphanumeric value like -alpha1-');
    
                return false;
    
    		}
    
    
    
    	return true
    
     }
    
    
    
    function ValidatePass(){
    
    
    
    	if (pcheck(document.newmember.password.value)==false){
    
    		document.newmember.password.value=""
    
    		document.newmember.password.focus()
    
    		return false
    
    	}
    
    	return true
    
     }
    
    
    
    </script>
    
    
    
    <script type="text/javascript" language="javascript">
    
    	function validate(){
    
    	
    
    		var error_msg = 0;
    
    	
    
    		if(document.getElementById('username').value == ""){
    
    			document.getElementById('h1').style.visibility='visible';
    
    			error_msg = 1;
    
    			}
    
    		else
    
    		{
    
    			if (document.getElementById('username').value.length < 3)
    
      			{
    
        		alert("Please enter at least 3 characters in the \"Username\" field.");
    
        		document.newmember.username.focus();
    
    			error_msg= 1;
    
    			}
    
    			else if (document.getElementById('username').value.length > 20)
    
    			{
    
    			alert("Please enter a \"Username\" with less than 20 characters.");
    
    			document.newmember.username.focus();
    
    			error_msg= 1;
    
    			}
    
    			else
    
    			{
    
    			document.getElementById('h1').style.display='none';
    
    			}
    
    		}
    
    		
    
    		if(document.getElementById('name').value == ""){
    
    			document.getElementById('h2').style.visibility='visible';
    
    			error_msg= 1;
    
    			}
    
    		else
    
    		{
    
    			if (document.getElementById('name').value.length < 4)
    
      			{
    
        		alert("The value entered in the \"Name\" field, appears to be too small.");
    
        		document.newmember.name.focus();
    
    			error_msg= 1;
    
    			}
    
    			else if (document.getElementById('name').value.length > 50)
    
    			{
    
    			alert("The value entered in the \"Name\" field, appears to be too big.");
    
    			document.newmember.name.focus();
    
    			error_msg= 1;
    
    			}
    
    			else
    
    			{
    
    			document.getElementById('h2').style.display='none';
    
    			}
    
    		}
    
    			
    
    		if(document.getElementById('password').value == ""){
    
    			document.getElementById('h3').style.visibility='visible';
    
    			error_msg= 1;
    
    			}
    
    		else
    
    			if(ValidatePass()==false)
    
    			{
    
    			document.getElementById('h3').style.display ='block';
    
    			error_msg= 1;
    
    			}
    
    			else
    
    			document.getElementById('h3').style.visibility='hidden';
    
    			
    
    		
    			
    
    		if(document.getElementById('radio1').checked == false && document.getElementById('radio2').checked == false  && document.getElementById('radio3').checked == false  && document.getElementById('radio4').checked == false){
    
    			document.getElementById('h6').style.visibility='visible';
    			error_msg= 1;
    
    			}
    
    		else
    
    			document.getElementById('h6').style.visibility='hidden';
    
    			
    
    		
    			
    
    		if(error_msg == 0){
    
    			document.newmember.submit();
    
    		}
    
    	}
    
          
    
    </script>
    
    
    
    <table border="3" width="1047" align="center" bgcolor="#FFFFFF">
    
      <tr>
    
        <td width="1%" align="center" valign="top"  >
    
    <?php
    
    		if(isset($_SESSION['login'])){
    
    			include "sidemenu.php";
    
    
    		}
    
    		else{
    
    			include "login.php";
    
    		}
    		?>
    		</td>
        <td align="center" valign="top">
    	<center> 
    
    		<FIELDSET>
    
    			<LEGEND>Welcome To Our Site</LEGEND>
    
    			
    
    			<table width="100%" border="0" align="center" >
    
    			  <tr class="tableHeader">
    
    				<td align="center"><strong>General Info</strong></td>
    
    			  </tr>
    			  
    			 		  
    			  <tr class="temp_content">
    			 
    					<td align="center">
    								
    						<!--
    						  
    						  The following image will have to be replaced so that the content desired
    						  can be placed in the following row of the table. Please mention at
    						  this page the instructions for the user in order to be able to 
    						  navigate the page. Mention the fact that the user has to register
    						  in order to view all the features provided by the page.
    						  
    						 -->
    			  						
    						Here you can Delete/Edit Members!
    					
    					</td>
    			
    			  </tr>
    				
    			</table>
    </FIELDSET><center></br>
    	<FIELDSET>
    
    			<LEGEND>Edit Member: <strong><?php echo $row['username']; ?></strong></LEGEND>
    
    			
    
    			<form name="newmember" id="newmember" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
    
    			
    
    				<table width="70%" align="center" cellspacing="2" cellpadding="4">
    
    				  <tr>
    
    					<td class="eventLeftSide">Username:</td>
    
    					<td class="eventRightSide"><input type="text" name="username" id="username" value="<?php echo $row['username']; ?>" /></td>
    
    					<td id='h1' style="visibility:hidden"><font color="#FF0000">Required</font></td>
    
    				  </tr>
    
    				  <tr>
    
    					<td class="eventLeftSide">Name:</td>
    
    					<td class="eventRightSide"><input type="text" name="name" id="name" value="<?php echo $row['name']; ?>" /></td>
    
    					<td id='h2' style="visibility:hidden"><font color="#FF0000">Required</font></td>
    
    				  </tr>
    
    				  <tr>
    
    					<td class="eventLeftSide">Password:</td>
    
    					<td class="eventRightSide"><input type="password" name="password" id="password" value="<?php echo $row["PASSWORD('pass');"]; ?>" /></td>
    
    					<td id='h3' style="visibility:hidden"><font color="#FF0000">Required</font></td>
    
    				  </tr>
    
    				  
    
    				  <tr>
    
    					<td class="eventLeftSide">Status:</td>
    
    					<td class="eventRightSide">
    
    						<input type="radio" id="radio1" name="access" value="1" <?php if($row['status']==1){?>checked='checked'<?php }?>/>Receprtionist <br />
    
    						<input type="radio" id="radio1" name="access" value="2" <?php if($row['status']==2){?>checked='checked'<?php }?>/>Accountant <br />
    						<input type="radio" id="radio1" name="access" value="3" <?php if($row['status']==3){?>checked='checked'<?php }?>/>Manager <br />
    
    						<input type="radio" id="radio2" name="access" value="4" <?php if($row['status']==4){?>checked='checked'<?php }?>/>Administrator
    
    					</td>
    
    					<td id='h6' style="visibility:hidden"><font color="#FF0000">Required</font></td>
    
    				  </tr>
    
    				
    
    				  <tr>
    
    				  <td colspan="2" class="eventHeadingText">
    
    				<input type="hidden" name="id" value="<?php echo $row['memID']; ?>">
    
    				<input type="hidden" name="verifySubmit" value="yes">
    
    				<input type="button" name="submitButton" value='Save' onClick="validate()"/>
    
    				<input type="button" value="Back" class="submit" onClick="window.location='viewmember.php?id=<?php echo $id; ?>'">
    
    				</td>
    
    			   </tr>
    
    			  </table>
    
    			</form>
    
    		</FIELDSET>
    </body>
    
    </html>
    
    
    PHP:

    Query failedYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user.memID='15' AND members.memID='15'' at line 9


    thats the msg i get!
     
    lounar, Nov 11, 2007 IP
  2. lounar

    lounar Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ok there was an extra comma there i found it but now the problem is that it takes no status!


    i try to edit a member but the status isn't updated or even stay the same!it turns to null!!!!
     
    lounar, Nov 11, 2007 IP
  3. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need to do an echo of $request - preferably before result.
    That would display what is the final query that gets executed. If the query has invalid id / mismatch of names etc, obviously nothing would get updated.
    If query appears to be OK, then go to phpmyadmin and run the same query, and note the result. That should give you some guidance.
    HTH
     
    pubdomainshost.com, Nov 11, 2007 IP
  4. lounar

    lounar Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    would help to do the echo cause i am a little newbie in php...
    plz refer to the code i have post ;)
     
    lounar, Nov 11, 2007 IP
  5. yyyk9

    yyyk9 Peon

    Messages:
    670
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi, what script is this? I think I have seen it before, and had problems myself.
     
    yyyk9, Nov 11, 2007 IP
  6. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #6
    OK, what you need to do is to write just after your query in the file you have mentioned as shown below.
    
    // Insert the user to the Database.
    
     $request = "UPDATE members, user SET user.username='$username', user.pass=PASSWORD('$password'), members.name='$name',  members.status='$access'  WHERE user.memID='$id' AND members.memID='$id'";
    
    echo "<BR>This is the request ".$request."<BR>" ; 
    
    Code (markup):
    This would display the final query that should get executed and give us information on what could be wrong.

    Cheers
    GS
     
    pubdomainshost.com, Nov 12, 2007 IP