Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update User Details not working

    Hi Guys

    I was wondering if anyone could assisst, When I try and update the details for a user it just seems to refresh what is already there. Can anyone tell me wher eI am going wrong?

    Code:
    <div class="content">
    
    <div class="pdform">
    
    <?php
    //connect to db
    $connect = mysql_connect('localhost','fypsite_fypsite','pass');
    $connect = mysql_select_db('fypsite_db');
    
    //get data from db
    
    $fetchrecord1 = "SELECT TBL_CUSTOMER.*, users.email FROM TBL_CUSTOMER JOIN users ON TBL_CUSTOMER.CUS_USERNAME = users.userId WHERE CUS_USERNAME = " . $_SESSION['userId'] . "";
    
    $get_result1 = mysql_query($fetchrecord1);
    
    $record1 = mysql_fetch_array($get_result1);
    
    //echo $_SESSION['userId'];
    //echo $record1['CUS_FORNAME'];
    $forename = $_POST['forename'];
    ?>
    
    <?php
    if (isset($_POST['ud'])) {
    $update = mysql_query("UPDATE TBL_CUSTOMER SET CUS_FORNAME = '".$forename."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'"); 
    $fetchrecord1 = "SELECT * FROM TBL_CUSTOMER WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'";
    $get_result1 = mysql_query($fetchrecord1);
    $record1 = mysql_fetch_array($get_result1);
    
    $update = mysql_query("UPDATE TBL_CUSTOMER SET ETHNICITY_ID = '".$_POST['ethnicity'] ."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'");
    
    $update = mysql_query("UPDATE TBL_CUSTOMER SET HOME_LANG = '".$_POST['languages'] ."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'" );
    
    $update = mysql_query("UPDATE TBL_CUSTOMER SET RELIGION = '".$_POST['religion'] ."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'");
    
    }
    ?>
    
    <form action="" method="post">
    <table>
    	<tr>
    		<td><h3>Update Details</h3></td>
    	</tr>
    	<tr>
    		<td>First Name</td>
    		<td><input type="text" name="forename" value="<?php echo $record1['CUS_FORNAME']?>"/></td>
    		<td>Surname/Family Name</td>
    		<td><input type="text" name="surname" value="<?php echo $record1['CUS_SURNAME']?>" /></td>
    	</tr>
    	<tr>
    		<td>Date of Birth</td>
    		<td><input type="text" name="date_of_birth" value="<?php echo $record1['CUS_DATE_OF_BIRTH']?>" /></td>
    		<td>Gender</td>
    		<td>
    		<select name="gender">
            <option value=""><?php echo $record1['CUS_GENDER']?></option>
    		<option value="Male">Male</option>
    		<option value="Female">Female</option>
    		</select>
    		</td>
    	</tr>
    	
    	<tr>
    		<td>Ethnicity</td>
    		<td>
    		<select name="ethnicity">
    		<?php 
    		while($erow = mysql_fetch_array($get_result2)) {
    		?>
    		<option <?php if($erow['ETHNICITY_ID'] == $record1['ETHNICITY_ID']) echo ' selected = "selected"';?> value="<?php echo $erow['ETHNICITY_ID']?>"><?php echo $erow['DESCRIPTION']?></option>
    		<?php
    		}
    		?>
    		</select>
    		</td>
    		<td>What languages do you speak at home?</td>
    		<td>
    		<select name="languages">
            <option value="">Please choose a Language</option>
    		<option <?php if($record1['HOME_LANG'] == 'E') echo ' selected = "selected"';?>value="E">English</option>
    		<option <?php if($record1['HOME_LANG'] == 'G') echo ' selected = "selected"';?>value="G">German</option>
    		<option <?php if($record1['HOME_LANG'] == 'F') echo ' selected = "selected"';?>value="F">French</option>
    		<option <?php if($record1['HOME_LANG'] == 'S') echo ' selected = "selected"';?>value="S">Spanish</option>
    		</select>
    		</td>
    	</tr>
    	<tr>
    		<td>Prefer not to say</td>
    		<td><input type="checkbox" name="prefer" value="<?php echo $record1['PREFER']?>"></td>
    		<td>Religion (Optional)</td>
    		<td>
    		<select name="religion">
            <option value="">Please choose a Religion</option>
    		<option <?php if($record1['RELIGION'] == 'C') echo ' selected = "selected"';?>value="C">Christianity</option>
    		<option <?php if($record1['RELIGION'] == 'I') echo ' selected = "selected"';?>value="I">Islam</option>
    		<option <?php if($record1['RELIGION'] == 'H') echo ' selected = "selected"';?>value="H">Hinduism</option>
    		<option <?php if($record1['RELIGION'] == 'O') echo ' selected = "selected"';?>value="O">Other</option>
    		</select>
    		</td>
    	</tr>
    	
    	<tr>
    		<td>Home Address</td>
    	</tr>
    	<tr>
    		<td>House Number</td>
    		<td><input type="text" name="number" value="<?php echo $record1['CUS_HOME_ADDRESS_NUMBER']?>" /></td>
    	</tr>
    	<tr>
    		<td>Street Name</td>
    		<td><input type="text" name="street" value="<?php echo $record1['CUS_HOME_ADDRESS_STREET']?>" /></td>
            <td><label hidden="mil_street">House No/Street</label></td>
            <td><input type="hidden" name="mil_street" /></td>
    	</tr>
    	<tr>
    		<td>Town</td>
    		<td><input type="text" name="town" value="<?php echo $record1['CUS_HOME_ADDRESS_TOWN']?>"/></td>
            <td><label hidden="mil_town">Town</label></td>
            <td><input type="hidden" name="mil_town"></td>
    	</tr>
    	<tr>
    		<td>County</td>
    		<td><input type="text" name="county" value="<?php echo $record1['CUS_HOME_ADDRESS_COUNTY']?>"/></td>
            <td><label hidden="mil_county">County</label></td>
            <td><input type="hidden" name="mil_county"/></td>
    	</tr>
    	<tr>
    		<td>Postcode</td>
    		<td><input type="text" name="postcode" value="<?php echo $record1['CUS_HOME_ADDRESS_POSTCODE']?>" /></td>
            <td><label hidden="mil_postcode">Post Code</label></td>
            <td><input type="hidden" name="mil_postcode"/></td>
    	</tr>
    	<tr>
    		<td>Telephone</td>
    		<td><input type="text" name="telephone" value="<?php echo $record1['CUS_HOME_ADDRESS_TELEPHONE']?>"/></td>
            <td><label hidden="mil_telephone">Telephone</label></td>
            <td><input type="hidden" name="mil_telephone"/></td>
    	</tr>
    	<tr>
    		<td>Mobile</td>
    		<td><input type="text" name="mobile" /></td>
            <td><label hidden="mil_mobile">Mobile</label></td>
            <td><input type="hidden" name="mil_mobile"/></td>
            <br/>
    	</tr>
    		</tr>
    	<tr>
    		<td>Email Address</td>
    		<td><input type="email" name="email" value="<?php echo $record1['email']?>"/></td>
    		</tr>
        <tr>
            <td><input type="submit" value="Update Personal Details"></td>
    	</tr>
        </form>
    </table>
    </div>
    </div>
    Thanks

    Graham

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You have way too many queries here. Every update here can be replaced with a single update query.
    You only need one select too. Perform it after the update branch, and go from there.

    I don't see the input type for 'ud'. Without it, you'll never enter the branch. Although that said, that's not sufficient for verification and validation purposes, you need to check each input for validation prior to insertion. Don't use the mysql library either, its old, deprecated and what you have here isn't safe at all. Use a prepared statement with mysqli library or pdo.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not sure how to do that, I have been out of the loop for a while and am trying to pick apart a template for ages ago to get it to work. I have seperated out the PHP and moved the form to an html page to make it easier to read.

    Code:
    <?php
    //connect to db
    $connect = mysql_connect('localhost','fypsite_fypsite','Mutronics1977');
    $connect = mysql_select_db('fypsite_db');
    protect_page();
    
    $fetchrecord1 = "SELECT TBL_CUSTOMER.*, users.email FROM TBL_CUSTOMER JOIN users ON TBL_CUSTOMER.CUS_USERNAME = users.userId WHERE CUS_USERNAME = " . $_SESSION['userId'] . "";
    $fetchrecord2 = "SELECT * FROM TBL_ETHNICITY ORDER BY ETHNICITY_ID";
    
    $get_result1 = mysql_query($fetchrecord1);
    $get_result2 = mysql_query($fetchrecord2);
    
    $record1 = mysql_fetch_array($get_result1);
    
    ?>
    
    <?php
    if (isset($_POST['submit'])) {
    $update = mysql_query("UPDATE TBL_CUSTOMER SET CUS_FORNAME = '".$forename."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'"); 
    $update = mysql_query("UPDATE TBL_CUSTOMER SET ETHNICITY_ID = '".$_POST['ethnicity'] ."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'");
    $update = mysql_query("UPDATE TBL_CUSTOMER SET HOME_LANG = '".$_POST['languages'] ."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'" );
    $update = mysql_query("UPDATE TBL_CUSTOMER SET RELIGION = '".$_POST['religion'] ."' WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'");
    //$fetchrecord1 = "SELECT * FROM TBL_CUSTOMER WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'";
    //$get_result1 = mysql_query($fetchrecord1);
    //$record1 = mysql_fetch_array($get_result1);
    
    
    
    }
    include 'includes/content/update_details.html';
    ?>
    G
    Last edited by columbo1977; 03-14-2014 at 11:03 PM.

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got it working in the end by using the following :

    Code:
    <?php
    session_start();
    //connect to db
    $connect = mysql_connect('localhost','user','pass');
    $connect = mysql_select_db('db');
    protect_page();
    
    $fetchrecord1 = "SELECT TBL_CUSTOMER.*, users.email FROM TBL_CUSTOMER JOIN users ON TBL_CUSTOMER.CUS_USERNAME = users.userId WHERE CUS_USERNAME = " . $_SESSION['userId'] . "";
    $fetchrecord2 = "SELECT * FROM TBL_ETHNICITY ORDER BY ETHNICITY_ID";
    
    $get_result1 = mysql_query($fetchrecord1);
    $get_result2 = mysql_query($fetchrecord2);
    
    $record1 = mysql_fetch_array($get_result1);
    
    ?>
    
    <?php
    if (isset($_POST['submit'])) {
     
    $update = mysql_query("UPDATE TBL_CUSTOMER SET CUS_FORNAME = '".$_POST['forename'] ."' 
    ,CUS_SURNAME = '".$_POST['surname'] ."'
    ,CUS_GENDER = '".$_POST['gender'] ."'
    ,CUS_DATE_OF_BIRTH = '".$_POST['date_of_birth'] ."'
    ,CUS_HOME_ADDRESS_NUMBER = '".$_POST['number'] ."'
    ,CUS_HOME_ADDRESS_STREET = '".$_POST['street'] ."'
    ,CUS_HOME_ADDRESS_TOWN = '".$_POST['town'] ."'
    ,CUS_HOME_ADDRESS_CITY = '".$_POST['city'] ."'
    ,CUS_HOME_ADDRESS_COUNTY = '".$_POST['county'] ."'
    ,CUS_HOME_ADDRESS_POSTCODE = '".$_POST['postcode'] ."'
    ,CUS_HOME_ADDRESS_TELEPHONE = '".$_POST['telephone'] ."'
    ,CUS_HOME_EMAIL = '".$_POST['email'] ."'
    ,CUS_MOB_NUMBER = '".$_POST['mobile'] ."'
    ,ETHNICITY_ID = '".$_POST['ethnicity'] ."'
    ,HOME_LANG = '".$_POST['languages'] ."'
    ,RELIGION = '".$_POST['religion'] ."'
    
    WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'");
    
    }
    $fetchrecord1 = "SELECT * FROM TBL_CUSTOMER WHERE CUS_USERNAME = '" . $_SESSION['userId'] . "'";
    $get_result1 = mysql_query($fetchrecord1);
    $record1 = mysql_fetch_array($get_result1);
    
    include 'includes/content/update_details.html';
    ?>
    G


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •