?
Solved

Value for textfield is not showing from database

Posted on 2011-05-06
5
Medium Priority
?
304 Views
Last Modified: 2012-05-11
Hello, I am trying to make a form that onchange it redirects to itself passing a "txtbarcode" and "assetselect" hidden fields with it.  I will have if statements set up so I get different behavior based on which variables I have to work with.  The order so far seems correct but I have two textfields that aren't populating themselves with the data from the database.  However just above those boxes I reference values of other fields within the same query.  Also the value I am using in my if statements is true just above the two textfields.  So I am getting the right data in one of my fields but not in the other two.  Here is some  of my code, Thank you for helping in advanced.

<form method="POST" name="transferformDESK">
                    <h7>New User Information</h7>
                    <div id="CSSTable" class="assetborder" style="margin:5px; width:400px">
       	  				<div id="row">
                            <div id="left" style="padding-right:5px">
                                New User:             
                            </div>
                            <div id="right">
                              	<input type="hidden" name="assetselect" id="assetselect" value="<?php echo $_POST['assetselect']?>" />
								<input type="hidden" name="txtbarcode" id="txtbarcode" value="<?php echo $_POST['txtbarcode']?>" />
								
                              <select name="userid" id="userid" onchange="document.transferformDESK.submit()">
                                <?php
do {  
?>
                          <option value="<?php echo $row_rswholename['id']?>"><?php echo $row_rswholename['wholename']?></option>
                          <?php
} while ($row_rswholename = mysql_fetch_assoc($rswholename));
  $rows = mysql_num_rows($rswholename);
  if($rows > 0) {
      mysql_data_seek($rswholename, 0);
	  $row_rswholename = mysql_fetch_assoc($rswholename);
  }
?>
<?php
										if ($usercheck == "success")
										{?>
                  <option selected="selected" value="<?php echo $row_rsEmpInfo['id']?>"><?php echo $row_rsEmpInfo['LastName'] . ", " . $row_rsEmpInfo['FirstName'] ?></option>
                  					<?php }
										else
										{?>
                                        	<option selected="selected" value="NULL">Choose one...</option>
                  					<?php }?>
                  					
									<?php
                                      $rows = mysql_num_rows($rswholename);
									  if($rows > 0) {
										  mysql_data_seek($rswholename, 0);
										  $row_rswholename = mysql_fetch_assoc($rswholename);
									  }
									?>
                              </select>
                              
                            </div>
                   	  </div>
                        	<div id="row">
                           	  <div id="left" style="padding-right:5px">
                                New Location:            
               	          </div>
                            	<div id="right">
                                
                            	  <span id="sprytextfield2">
                            	  <input value="
								  <?php 
								  	if($usercheck == "success")
									{
										echo $row_rsEmpInfo['Location']; 
									}
									else
									{
										?>NULL<?php
                                     }?>"type="text" name="newlocal" id="newlocal" />
                           	  <span class="textfieldRequiredMsg"></span></span>
                              </div>
                        	</div>

Open in new window

0
Comment
Question by:andrewaiello
5 Comments
 
LVL 9

Expert Comment

by:Vampireofdarkness
ID: 35711205
Please post your SELECT query $rswholename.
You're using $row_rswholename[] on line 16 before declaring it on line 18.
Please post your $row_rsEmpInfo[] query (if it is the query, and not a variable defined from mysql_fetch_assoc).
0
 
LVL 4

Expert Comment

by:Kalyanum Deepak Kumar
ID: 35711305
Hi Andre,

Where are you getting the value for $usercheck?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35712021
A debugging note: In your PHP scripts, add error_reporting(E_ALL) to the top of all scripts so you can be sure that you are not relying on any undefined variables.
A design note: Please consider the way clients use forms.  Clients use the "submit" input control to submit the forms.  They do not expect to submit forms by changing the items in a select list.  If a client misfires a selection or checkbox or radio button, the client deserves an opportunity to correct this before the form is submitted.

Best, ~Ray
0
 
LVL 1

Accepted Solution

by:
andrewaiello earned 0 total points
ID: 35712962
@Ray Paseur: so just add the function "error_reporting(E_ALL)" in my header minus the quotes to enable that?

Overview: This is a group project for school and the "Group Leader" who knows nothing of database decided to disregard my database structure and "wing it".  So essentially none of the tables can be joined.  The purpose of the project is an asset tracking system for a company.  So we have 10 tables each for a different asset.  And, the way the "Group Leader" wants it to work is by dynamically changing the form as they use the select boxes.  None of us know ajax so I had to makeshift replicate it by upon selection it redirects back to the page while passing the 3 important variables I need (Type of asset, barcode, and employee id) via $_POST and just using a lot of if statements to decide what happens based on the information available.  So if "$_POST['userid'] then I set $usercheck = "success" at the top of my code and use that variable in my if statements to decide what to do.  I know it is much more complicated then it has to be but it is what happens in group projects.  With the current code I have posted the behavior was actually posting the correct rswholename in the <select name=userid></select> after redirect but not posting anything for location from the rsEmpInfo query.  
I know I said the behavior was that it stopped after the first space but I was mistaken(that was old behavior which I kind of fixed).  After I fixed that behavior it just stopped posting in the location text box all together.  I forgot last night my output had changed from stopping at the first space character (so please ignore me saying that, it was wrong information).  After sleeping on it I realized I should place some flags up to see which if statements it is hitting to help find the problem. But I can't do it at the moment but I will try to do it as soon as I get a chance.  However, If you guys do happen to see something I still welcome the help.

Here is the query for the $rsEmpInfo:
<?php
	if (isset($_POST['userid']))
	{	
		$usercheck = 'success';
		$userid_rsEmpInfo = "NULL";
		if (isset($_POST['userid'])) {
		  $userid_rsEmpInfo = $_POST['userid'];
		}
		mysql_select_db($database_authentication, $authentication);
		$query_rsEmpInfo = sprintf("SELECT * FROM employees WHERE employees.id = %s", GetSQLValueString($userid_rsEmpInfo, "text"));
		$rsEmpInfo = mysql_query($query_rsEmpInfo, $authentication) or die(mysql_error());
		$row_rsEmpInfo = mysql_fetch_assoc($rsEmpInfo);
		$totalRows_rsEmpInfo = mysql_num_rows($rsEmpInfo);
	}

Open in new window


Here is the query for the $rswholename
mysql_select_db($database_authentication, $authentication);
$query_rswholename = "SELECT employees.id, CONCAT(employees.LastName,', ', employees.FirstName) AS wholename FROM employees";
$rswholename = mysql_query($query_rswholename, $authentication) or die(mysql_error());
$row_rswholename = mysql_fetch_assoc($rswholename);
$totalRows_rswholename = mysql_num_rows($rswholename);

Open in new window


Thank you
0
 
LVL 1

Author Closing Comment

by:andrewaiello
ID: 35744779
Figured out why my if statements weren't executing.
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question