2 Replies - 250 Views - Last Post: 15 March 2014 - 08:41 AM Rate Topic: -----

#1 columbo1977  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 14-March 14

Update details issue

Posted 14 March 2014 - 03:16 PM

Hi there

Hope someone can help, I have realized I am very rusty with PHP and Mysql but am trying to get this code working. I am able to get the information up but I cannot make any changes to the data. Not sure what to change as I said I am very rusty.

Code for the PHP Page
<?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 = '".$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';
?>


HTML form Code
<!DOCTYPE HTML>
<HTML>
   <HEAD>
      <TITLE>Update Details</TITLE>
   </HEAD>
<BODY>
<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="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="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="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="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="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="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>
    </BODY>
</HTML>



Is This A Good Question/Topic? 0
  • +

Replies To: Update details issue

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3824
  • View blog
  • Posts: 13,556
  • Joined: 12-December 12

Re: Update details issue

Posted 14 March 2014 - 03:20 PM

	if (isset($_POST['submit'])) {

Your submit button doesn't have the name "submit" so none of that section of code will execute.

(30 second spot ;))

This post has been edited by andrewsw: 14 March 2014 - 03:21 PM

Was This Post Helpful? 0
  • +
  • -

#3 columbo1977  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 14-March 14

Re: Update details issue

Posted 15 March 2014 - 08:41 AM

I got it working using hte following code :P

<?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';
?>





Cheers

Graham
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1