Jump to content

pls i need help with this php/mysql code


mrheart5000

Recommended Posts

hello dear code gurus... i have this code which make use of php/mysql and javascript. the output is a select list/menu which has 3 textfield ( firstname, lastname and phone number). the select menu is retrieving email addresses from the mysql dbase which is the primary key and on selecting a particular email from the list, the preceeding textfields will be populated with the corresponding firstname, lastname and phone number of the person, on selecting another, the details will change to the corresponding person selected. now this code is working fine as intended. the problem now is i want the the whole thing to be in 5 rows so that each row is details belonging to a different person so it can be sent to database in bulk(at once)... if i try to iterate the code, i will have 5 rows quite ok but on selecting email from any other row apart from the first one, instead of the firstname, lastname and phone apearing on that row, it only update the first row... can someone pls help me run the code and fix it to desire for me pls..... any help will be appreciated... here is the code...

 

 


<?php 

$vbCrLf = chr(13).chr(10);
// open connection to MySQL server
$connection = mysql_connect('localhost', 'root', 'ishima')
or die ('Unable to connect!');

//select database
mysql_select_db('test') or die ('Unable to select database!');

//create and execute query
$query = 'SELECT * FROM user';
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());

//create selection list
$DropDownList .= "<select name='Company' id='DropDownListId' onchange='javascript:SelectChanged();'> ".$vbCrLf;
$DropDownList .= "<option value=''></option> ".$vbCrLf;

while($row = mysql_fetch_row($result))
{
	$heading = $row[0];
	$DropDownList .= "<option value='$heading'>$heading</option> ".$vbCrLf;
	$FirstArrayPhp .= 'FirstArray["'.$heading.'"]="'.$row[2].'";'.$vbCrLf;
	$EmailArrayPhp .= 'EmailArray["'.$heading.'"]="'.$row[3].'";'.$vbCrLf;
	$DetailsArrayPhp .= 'DetailsArray["'.$heading.'"]="'.$row[5].'";'.$vbCrLf;
}
$DropDownList .= "</select> ".$vbCrLf;
      ?>


<html>
<head>
<title>DropDown</title>
<script language="Javascript" type="text/javascript">
var FirstArray = new Array();
<?php echo $FirstArrayPhp; ?>
var EmailArray = new Array();
<?php echo $EmailArrayPhp; ?>
var DetailsArray = new Array();
<?php echo $DetailsArrayPhp; ?>
function SelectChanged()
{
	var Company = document.getElementById('DropDownListId').value;
	document.getElementById('first').value = FirstArray[Company];
	document.getElementById('email').value = EmailArray[Company];
	document.getElementById('company').value = DetailsArray[Company];
}
</script>
</head>

<body>
<form name="events" method="post"  action="<?= $_SERVER['PHP_SELF']?>">
<table width="835" align="center">
  <tr>
    <td width="215" align="left"> </td>
    <td width="157" height="24" align="left"> </td>
    <td width="144" align="left"> </td>
    <td width="144"> </td>
    <td width="261"> </td>
    </tr>
  <tr>
    <td align="left" valign="top"> </td>
    <td align="left" valign="top"> </td>
    <td align="left" valign="top"><p>First Name:</p></td>
    <td align="left">Last Name:</td>
    <td align="left">Phone Number:</td>
    </tr>
  <tr>
    <td align="right" valign="top">Select:</td>
    <td align="left" valign="top"><?php echo $DropDownList; ?></td>
    <td align="left" valign="top"><p>
      <input type="text" name="first" id="first" class="heading" value="<?php echo $row['pass']; ?>">
    </p></td>
    <td align="left">
      <input type="text" name="email" id="email" class="date"value="<?php echo $row['fname']; ?>">    </td>
    <td align="left"><input name="company" id="company" class="details"value="<?php echo $row['lname']; ?>"></td>
    </tr>
  <tr>
    <td align="left" valign="top"> </td>
    <td align="left" valign="top"> </td>
    <td align="left" valign="top"><p>
  
      <input name="submit" type="submit" class="submitForm" value="Submit">
    </p></td>
    <td> </td>
    <td> </td>
    </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    </tr>
</table>
</form>
</body>
</html>


 

i have also attached here the pictorial output of the code in its first instanace...

 

[attachment deleted by admin]

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.