• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

using tab - unable to store data on other tabs to db??

what i have done is use tabs so that you can pick what area of the profile you want to edit.

that ist page shown below where the tab code is on wors perfect and updates anything done!

the code provided in the next part is hobbies.php

it wont add it to the db or validate any errors... i think its because i use <?php "$_SERVER[PHP_SELF]" ?> and it wont use the hobbies.php ... can nay1 help..if more info is needed just ask!
<link rel="stylesheet" type="text/css" href="http://www.runningprofiles.com/css/login.css">
<link rel="stylesheet" type="text/css" href="include/profiletab/ajaxtabs/ajaxtabs.css">
<script type="text/javascript" src="include/profiletab/ajaxtabs/ajaxtabs.js"></script>
<script language = "Javascript">
/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
 
maxL=1000;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}
 
function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
	}
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}
</script>
 
 
<?php 
require_once '../settings.php';
checkLogin('1 2');
include "../info.php"; // sets username/id ect
include "../getuser.php"; // records user view on page
$getuser = mysql_fetch_assoc(mysql_query("SELECT * from users where Username='$username'"));
$getuserprofile = mysql_fetch_assoc(mysql_query("SELECT * from profile where ID='" .
            $getuser['ID'] . "'"));
			$your_date = $getuserprofile['dob'];
$splitDate = explode("-", $your_date);
 
?>		
           <br /> Edit <?php echo $username;?>'s profile 
       
 <table width="100%" cellspacing="0" cellpadding="0">
   <tr>
     <td width="10%">&nbsp;</td>
     <td width="42%" valign="middle"> <br />       
       <br />     <br />     <br />  
<ul id="countrytabs" class="shadetabs">
      <li><a href="#" rel="#default" class="selected">User Details</a></li>
      <li><a href="include/profiletab/hobbies.php" rel="countrycontainer">About me</a></li>
      <li><a href="include/profiletab/goal.php" rel="countrycontainer">Goals</a></li>
      <li><a href="include/profiletab/idols.php" rel="countrycontainer">Idols</a></li>
      <li><a href="include/profiletab/thanks.php" rel="countrycontainer">Thanks to..</a></li>
</ul>
    
      <div id="countrydivcontainer" style="border:1px solid gray; width:800px; margin-bottom: 1em; padding: 10px">
      
       <?  
       if(isset($_POST['submitted']))
{
 
 
	   
	  foreach($_POST as $field => $value) {
   if (($field != 'submit') && ((!$value) || (trim($value) == ''))) {
      $err .= "$field cannot be empty. <br>";
      $warnings[$field] ="required";
   }
}   
 
if (!$_POST["First Name"] || !preg_match("/^[a-zA-Z ]+$/", $_POST["First Name"])) {
   $warnings["First Name"] = " <label for=\"uname\" class=\"error\"><em>*</em>First name can only contain letters</label>";
   }
if (!$_POST["Last Name"] || !preg_match("/^[a-zA-Z ]+$/", $_POST["Last Name"])) {
   $warnings["Last Name"] = " <label for=\"uname\" class=\"error\"><em>*</em>Last name can only contain letters</label>";
   }
   
if (!$_POST["about_me"] || !preg_match("/^[a-zA-Z ]+$/", $_POST["about_me"])) {
   $warnings["about_me"] = " <label for=\"uname\" class=\"error\"><em>*</em>please only user words</label>";
   }
 
           $count  = count($warnings);
           }
if($count === 0)
{
   
if(array_key_exists('submit', $_POST))
{
 
 
 
$club = mysql_real_escape_string($_POST['club']);
$first_name = mysql_real_escape_string($_POST['First Name']);
$last_name =  mysql_real_escape_string($_POST['Last Name']);
$gender =  mysql_real_escape_string($_POST['gender']);
$year =  mysql_real_escape_string( $_POST['year']);
$month =  mysql_real_escape_string( $_POST['month']);
$day =  mysql_real_escape_string( $_POST['day']);
$dob = $day.'-'.$month.'-'.$year; 
$update = "UPDATE profile SET dob='$dob', club= '$club', first_name = '$first_name', gender = '$gender', last_name = '$last_name' WHERE ID='$id' ";
 
 
$result = mysql_query($update);
 
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $er  = 'Invalid query: ' . mysql_error() . "\n";
    $er .= 'Whole query: ' . $query;
    die($er);
       }}
  echo '			<p class="error">' . $message . '</p>' . "\n";
}
 
 
 
            if ($err){?>
      <div class="errors">
		<p align="center"><em>Oops... the following errors were encountered:</em></p>
 
		<div align="center"><?php echo $err; ?>	      </div>
		<p align="center">&nbsp;</p>
		<p align="center">Data has <strong>not</strong> been saved.</p>
      </div>
      <p>
       <?php } ?>
      <fieldset>
		<legend>User Details</legend>	 
      <form  action='<?php "$_SERVER[PHP_SELF]" ?>' method="post" name="submit">
        <label>
        
          
          <div align="center">
            <table width="91%" align="left" cellpadding="0" cellspacing="0">
              <tr>
                <td width="28%"><div align="right">First Name:</div></td>
                <td >&nbsp;</td>
                <td width="70%"><input name="First Name" id="first name" <? if (count($warnings) > 0){ if ($warnings['First Name']) echo "class=\"inputerror\""; }?> value="<?php echo $getuserprofile['first_name'] ?>"  />
                <?php if (count($warnings) > 0){ echo $warnings["First Name"];} ?> </td>
              </tr>
              <tr>
                <td height="30"><div align="right">Last Name: </div></td>
                <td><label></label></td>
                <td><input  type="text" name="Last Name" id="Last Name" <? if (count($warnings) > 0){ if ($warnings['Last Name']) echo "class=\"inputerror\"";} ?> value="<?php echo $getuserprofile['last_name'] ?>" />
                  <?php if (count($warnings) > 0){ echo $warnings["Last Name"];} ?>                </td>
              </tr>
              <tr>
                <td height="30"><div align="right">Birthday :</div></td>
                <td>&nbsp;</td>
                <td valign="middle"><?php  
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December');
$weekday = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
$days = range (1, 31);
$years = range (1910, 2015);
 
//**********************************************
 
echo "Day: <select name='day'>";
foreach ($days as $value) {
   echo '<option ';
   if($splitDate[0] == $value)
      echo 'selected="selected"';
   echo ' value="'.$value.'">'.$value.'</option>\n';
} echo '</select>';
 
echo "Month: <select name='month'>";
foreach ($months as $value) {
 
   echo '<option ';
   if($splitDate[1]==$value) 
      echo "selected='selected'";
   echo 'value="'.$value.'">'.$value.'</option>\n';
} echo '</select>';
 
echo "Year: <select name='year'>";
foreach ($years as $value) {
   echo '<option ';
   if($splitDate[2]==$value)
      echo 'selected="selected"';
   echo " value='".$value."'>".$value."</option>\n";
} 
 ?>                </td>
              </tr>
              <tr>
                <td height="30"><div align="right">Gender : </div></td>
                <td>&nbsp;</td>
                <td><?php $true=$getuserprofile['gender'];?>
                  <select name='gender' id='gender'>
                    <option value='Male' <?php if ($true=='Male') {echo "selected";} ?>>Male</option>
                    <option value='Female'<?php if ($true=='Female') {echo "selected";} ?>>Female</option>
                </select></td>
              </tr>
              <tr>
                <td height="30"><div align="right">Club :</div></td>
                <td>&nbsp;</td>
                <td>
                  <?php $lines = file('runningclubs.txt');
echo '<select class="inputedit" id="club" name="club">';
foreach($lines as $line) {
if($getuserprofile['club'] == trim($line)){
echo '<option value="'.$line.'" selected="selected">'.$line.'</option>';
}else{
echo '<option value="'.$line.'">'.$line.'</option>';
}
}
echo "</select>";
?>
                    
                  <input type="hidden" name="submitted" value="1" />
                <input type="hidden" name="id" value="<?php echo $id ?>" /></td>
              </tr>
              <tr>
                <td colspan="3"><div align="center">
                    <p>&nbsp;                    </p>
                    <p>
                      <input name="submit"  type="submit"  value="Submit" />
                        </p>
                </div></td>
              </tr>
            </table>
          </div>
      </form>      
      </fieldset>  
      
      </div>
      </td>
     <td width="10%">&nbsp;</td>
   </tr>
 </table>
 <script type="text/javascript">
var countries=new ddajaxtabs("countrytabs", "countrydivcontainer")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init()
  </script>

Open in new window

0
runnerjp
Asked:
runnerjp
  • 2
1 Solution
 
runnerjpAuthor Commented:
like i said this is hobbies.php where i cant use validation or the db
<?php error_reporting(E_ALL);
session_start();
require_once '../../../settings.php';
include "../../../info.php"; // sets username/id ect
 
$getuser = mysql_fetch_assoc(mysql_query("SELECT * from users where Username='$username'"));
$getuserprofile = mysql_fetch_assoc(mysql_query("SELECT * from profile where ID='" .
				$getuser['ID'] . "'"));
 
?>
 
<html>
<head>
    <title></title>
   </head>
 
<body>
  <?  
       if(isset($_POST['submitted']))
{
 
 
	   
	  foreach($_POST as $field => $value) {
   if (($field != 'submit') && ((!$value) || (trim($value) == ''))) {
      $err .= "$field cannot be empty. <br>";
      $warnings[$field] ="required";
   }
}   
 
if (!$_POST["about_me"] || !preg_match("/^[a-zA-Z ]+$/", $_POST["about_me"])) {
   $warnings["about_me"] = " <label for=\"uname\" class=\"error\"><em>*</em>please only user words</label>";
   }
 
 
           $count  = count($warnings);
           }
if($count === 0)
{
   
if(array_key_exists('submit', $_POST))
{
 
 
 
$about_me = mysql_real_escape_string($_POST['Description']);
$update = "UPDATE profile SET  about_me = '$about_me' WHERE ID='$id' ";
 
 
$result = mysql_query($update);
 
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $er  = 'Invalid query: ' . mysql_error() . "\n";
    $er .= 'Whole query: ' . $query;
    die($er);
       }}
  echo '			<p class="error">' . $message . '</p>' . "\n";
}
 
 
 
            if ($err){?>
      <div class="errors">
		<p align="center"><em>Oops... the following errors were encountered:</em></p>
 
		<div align="center"><?php echo $err; ?>	      </div>
		<p align="center">&nbsp;</p>
		<p align="center">Data has <strong>not</strong> been saved.</p>
      </div>
      <p>
       <?php } ?>
    <fieldset>
        <legend>About me</legend> 
 
        <div class="c1">
          <p>&nbsp;</p>
 
                <form  action='<?php "$_SERVER[PHP_SELF]" ?>' method="post" name="submit">
              <p><em><strong>Tell everybody a little bit about yourself...</strong></em></p>
              <p>
                <textarea <? if (count($warnings) > 0){ if ($warnings['about_me']) echo "class=\"inputerror\""; }?> onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="Description" rows="7" wrap="physical" cols="60">
<?php echo $getuserprofile['about_me']; ?><?php if (count($warnings) > 0){ echo $warnings["about_me"];} ?>
              </textarea>
                <br />
                <br />
                You have <b><span id="myCounter">1000</span></b> characters remaining</p>
              <input name="submit"  type="submit"  value="Submit" />
 
                      </form>
    </div>
    </fieldset>
</body>
</html>

Open in new window

0
 
b0lsc0ttIT ManagerCommented:
This isn't really clear so I have hesitated to dive in.  Your question is good and I am glad you posted code but just the page layout and way all of the code works.  Since no one else has responded yet let me see if some questions will help get me going on this.
Do you have this online and can you provide a link?
Do the tabs actually change the URL and reload the page?  What exactly do you mean by them and how they work?
When you are on the page (or maybe just "tab") with the problem (hobbies.php you said) what is the action in the form tag?  Look at the browser source to see this so you won't see the PHP script but what the server sends to the browser.  What do you need there for the form that is on that hobbies page?
I hope this will provide the info I need.  The questions and what I have said might even let you know what I am missing, misunderstand, or need and so please don't just provide a quick, brief response to each.  If you are right that the action when the Hobbies "tab" is used is the problem then that would seem to make the fix obvious to you but that is where my lack of understanding on the tabs is hurting me.
Let me know if you have a question about any of this.
bol
0
 
runnerjpAuthor Commented:
ok i have set up some links so you can see it in action http://www.runningprofiles.com/test.php

if you want to run the hobbies page on it own then go to http://www.runningprofiles.com/members/include/ajaxtab/hobbies.php
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now