Jump to content

Radio Button MYSQL Data Submission


unemployment

Recommended Posts

I'm in the process of making a network for investors and entrepreneurs. When they access their profile page, select edit and go to editprofile.php a problem arises with the data base submission. I have the data they have previously inputted being echoed back out to the user. This lets the user see what they have inputted so that they can make changes to their profile. Unfortunately, with my radio buttons, if no changes are made and the user hits submit, the radio buttons return a value of 'unchecked'. I need them to maintain the value previously submitted to the database if the radio button isn't 'checked'. I'm not sure exactly how to do this.

 

You can test it out yourself by going to http://network.jasonbiondo.com

 

Code is below:

 

?php

session_start();

require ('connect.php');

include ('header.php');

$savechanges = $_POST['savechanges'];

$firstname = strip_tags($_POST['firstname']);
$lastname = strip_tags($_POST['lastname']);
$username = strtolower(strip_tags($_POST['username']));
$email = strip_tags($_POST['email']);
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$entrepreneur = 'unchecked';
$investor = 'unchecked';
$date = date("Y-m-d");
$companyname = strip_tags($_POST['companyname']);
$companywebsite = strip_tags($_POST['companywebsite']);
$founder = strip_tags($_POST['founder']);
$phone = strip_tags($_POST['phone']);
$address = strip_tags($_POST['address']);
$city = strip_tags($_POST['city']);
$state = strip_tags($_POST['state']);
$zipcode = strip_tags($_POST['zipcode']);
$country = strip_tags($_POST['country']);
$development = strip_tags($_POST['development']);
$capitalamount = strip_tags($_POST['capitalamount']);
$companydo = strip_tags($_POST['companydo']);
$founderbuilt = strip_tags($_POST['founderbuilt']);
$whatsnew = strip_tags($_POST['whatsnew']);
$understand = strip_tags($_POST['understand']);
$competition = strip_tags($_POST['competition']);
$money = strip_tags($_POST['money']);
$demo = strip_tags($_POST['demo']);
$incorporation = strip_tags($_POST['incorporation']);
$companynameinv = strip_tags($_POST['companynameinv']);
$phoneinv = strip_tags($_POST['phoneinv']);
$addressinv = strip_tags($_POST['addressinv']);
$cityinv = strip_tags($_POST['cityinv']);
$stateinv = strip_tags($_POST['stateinv']);
$zipcodeinv = strip_tags($_POST['zipcodeinv']);
$countryinv = strip_tags($_POST['countryinv']);
$angel = strip_tags($_POST['angel']);
$vc = strip_tags($_POST['vc']);
$capital = strip_tags($_POST['capital']);

if ($savechanges)

{

$queryreg = mysql_query("UPDATE users SET

   `firstname` = '$firstname',
   `lastname` = '$lastname',
   `email` = '$email',
   `entrepreneur` = '$entrepreneur',
   `investor` = '$investor',
   `companyname` = '$companyname',
   `companywebsite` = '$companywebsite',
   `founder` = '$founder',
   `phone` = '$phone',
   `address` = '$address',
   `city` = '$city',
   `state` = '$state',
   `zipcode` = '$zipcode',
   `country` = '$country',
   `development` = '$development',
   `capitalamount` = '$capitalamount',
   `companydo` ='$companydo',
   `founderbuilt` = '$founderbuilt',
   `whatsnew` = '$whatsnew',
   `understand` = '$understand',
   `competition` = '$competition',
   `money` = '$money',
   `demo` = '$demo',
   `incorporation` = '$incorporation',
   `companynameinv` = '$companynameinv',
   `phoneinv` = '$phoneinv',
   `addressinv` = '$addressinv',
   `cityinv` = '$cityinv',
   `stateinv` = '$stateinv',
   `zipcodeinv` = '$zipcodeinv',
   `countryinv` = '$countryinv',
   `angel` = '$angel',
   `vc` = '$vc',
   `capital` = '$capital'
   
   WHERE username=  '" . $_SESSION['username'] . "'
   
   ");
   
   $selected_radio_selector = $_POST['selector'];
    $selected_radio_invtype = $_POST['invtype'];
      
   if ($selected_radio_selector == 'entrepreneur')
      {
         $entrepreneur = 'checked';
         
      }
      else if ($selected_radio_selector == 'investor')
      {
         $investor = 'checked';
         
         if ($selected_radio_invtype == 'angel')
         {
            $angel = 'checked';
            $vc = 'unchecked';
         
         }
         else if ($selected_radio_invtype == 'vc')
         {
            $vc = 'checked';
            $angel = 'unchecked';
         }
         else
         {
         die("Please select what type of investor you are!");
         }
      }
   
}

$q = mysql_query("SELECT `firstname`, `lastname`, `firstname`, `lastname`, `email`, `entrepreneur`, `investor`, `companyname`, `companywebsite`, `founder`, `phone`, `address`, `city`, `state`, `zipcode`, `country`, `development`, `capitalamount`, `companydo`, `founderbuilt`, `whatsnew`, `understand`, `competition`, `money`, `demo`, `incorporation`, `companynameinv`, `phoneinv`, `addressinv`, `cityinv`, `stateinv`, `zipcodeinv`, `countryinv`, `angel`, `vc`, `capital` FROM `users` WHERE username=  '" . $_SESSION['username'] . "'");

$r = mysql_fetch_assoc($q);

?>

<script type="text/javascript" src="../assets/js/editprofile.js"></script>

<form action='editprofile.php' method="POST" id="form">

   <fieldset>

      <p id="required"> * Required Fields</p>

      <p class="fieldSpacing">

         <label for="firstname" class="leftcolalign">First Name *</label>

         <input id="firstname" class="rightcolalign" name="firstname" value='<?php echo $r['firstname']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="lastname" class="leftcolalign">Last Name *</label>

         <input id="lastname" class="rightcolalign" name="lastname" value='<?php echo $r['lastname'];?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="username" class="leftcolalign">User Name *</label>

         <?php echo $_SESSION['username']; ?>

      </p>

      <p class="fieldSpacing">

         <label for="email" class="leftcolalign">Email *</label>

         <input id="email" class="rightcolalign" name="email" value='<?php echo $r['email']; ?>''/>

      </p>

      <p class="fieldSpacing">

         <label for="selector" class="leftcolalign">What am I? *</label>

         <input id="entButton" class="radioalign" type="radio" name="selector" value="entrepreneur"<?php echo $r['entrepreneur']; ?>/>

         <label for="entrepreneur" id="entrepreneur">Entrepreneur</label>

         <input id="invButton" class="radioalign" type="radio" name="selector" value="investor"<?php echo $r['investor']; ?>/>

         <label for="investor" id="investor">Investor</label>

      </p>

   </fieldset>

   <fieldset id="entForm">

      <p class="fieldSpacing">

         <label for="companyname" class="leftcolalign">Company Name: *</label>

         <input id="companyname" class="rightcolalign" name="companyname" value='<?php echo $r['companyname']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="companywebsite" class="leftcolalign">Company Website:</label>

         <input id="companywebsite" class="rightcolalign" name="companywebsite" value='<?php echo $r['companywebsite']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="founder" class="leftcolalign">Founder(s): *</label>

         <input id="founder" class="rightcolalign" name="founder" value='<?php echo $r['founder']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="phone" class="leftcolalign">Phone Number(s): *</label>

         <input id="phone" class="rightcolalign" name="phone" value='<?php echo $r['phone']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="address" class="leftcolalign">Address: *</label>

         <input id="address" class="rightcolalign" name="address" value='<?php echo $r['address']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="city" class="leftcolalign">City: *</label>

         <input id="city" class="rightcolalign" name="city" value='<?php echo $r['city']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="state" class="leftcolalign">State:</label>

         <input id="state" class="rightcolalign" name="state" value='<?php echo $r['state']; ?>'/>

      </p>

      <p class="fieldSpacing">

         <label for="zipcode" class="leftcolalign">Zip Code:</label>

         <input id="zipcode" class="rightcolalign" name="zipcode" value='<?php echo $r['zipcode']; ?>'/>

      </p>




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.