Jump to content

Recommended Posts

I need to create a web based interface to update fields in a database. What i want it to do is have 2 combo boxes the first which will contain both the last name (last_name is the field name in db) a comma then the first name (first_name is the field name in db). In the other combo box will be either a yes or a no (which will read from the db from the field client). The trick about this part is that the database has a 0 or 1, 0=false 1=true...obviously. What i would like is for the yes/no field to auto update if the choice in the other combo box changes to it's current value in the database. I want the user to be able to change the yes/no field then click a  'Go' button to post the change to the database in the row of the persons name as displayed in the other database.

 

I know that's kinda confusing, but it seems like a simple concept to me i just have no clue how to do it

Link to comment
https://forums.phpfreaks.com/topic/87157-interface-to-update-database/
Share on other sites

Is there more than one thing you want there?  It's a little unclear.

 

1.  If the database changes, then the form should be updated

2.  If the user edits the form, then the change should be posted to the database after clicking the Go button.

 

Is that right, or is it just #2?

Ok, this is what i have...I have the two combo boxes and they are reading from the db but i can only get the last result of the loop to display in the boxes...

<?php
$session = mysql_connect("localhost", "xxx", "xxx");
mysql_select_db("xxx");
$query = "select * from users";

$result = mysql_query($query);
if ( !$result )
{
echo ( "<P>Error doing a select: " . mysql_error() . "</P>" );
}
else
{
// succesful read - how many records ?
print (" Number of rows read " . mysql_num_rows($result)."</br>");

$rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr

// loop over rows, counts the total number and prints them
for ($i=0; $i<$rr; $i++) {
$nextresult = mysql_fetch_array($result);
$username = $nextresult['username'];
$client = $nextresult['client'];
print ($username."<br>");
print ($client."<br>");
}
}
// close the connection
mysql_close($session);

?>
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="">
<select name="name" id="name">
<option><?php print($username); ?></option>
<option selected "$user_input"></option>
</select>

<select name="client" id="client">
<option><?php print($client); ?></option>
<option selected "$user_input"></option>
</select>
<input name="change" type="button" value="Change"></form> 
</body>
</html>

I'm having trouble with this while loop, i can get it to loop the proper number of times but in the combo box it just displays the last result a number of times

 

<?php
$session = mysql_connect("localhost", "xxx", "xxx");
mysql_select_db("xxx");
$query = "select * from users";

$result = mysql_query($query);
if ( !$result )
{
echo ( "<P>Error doing a select: " . mysql_error() . "</P>" );
}
else
{
// succesful read - how many records ?
print (" Number of rows read " . mysql_num_rows($result)."</br>");

$rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr

// loop over rows, counts the total number and prints them
for ($i=0; $i<$rr; $i++) {
$nextresult = mysql_fetch_array($result);
$username = $nextresult['username'];
$client = $nextresult['client'];
print ($username."<br>");
print ($client."<br>");
}
}
// close the connection
mysql_close($session);
?>
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="">
<select name="name" id="name">
<?php
$j=0;
while($j<$rr){
echo "<option>{$nextresult['username']}</option>";
$j++;
}?>
</select>

<select name="client" id="client">
<option><?php print($client); ?></option>
<option selected "$user_input"></option>
</select>
<input name="change" type="button" value="Change"></form> 
</body>
</html>

ok I've found a way to get the proper readouts in the both the name and client combo boxes but i've looked around and can't find anthing on auto updating. I want the user to select a persons name from the name box and the client box to be auto updated to it's proper value

any ideas?

 

current code:

<?php
$session = mysql_connect("localhost", "xxxx", "xxxx");
mysql_select_db("xxxx");
$query = "select * from users";

$result = mysql_query($query);
if ( !$result )
{
echo ( "<P>Error doing a select: " . mysql_error() . "</P>" );
}
else
{
// succesful read - how many records ?
print (" Number of rows read " . mysql_num_rows($result)."</br>");

$rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr

// loop over rows, counts the total number and prints them
$user = array(); // define array students
for ($i=0; $i<$rr; $i++) {
    $nextresult = mysql_fetch_array($result);
$fname = $nextresult['first_name'];
$lname = $nextresult['last_name'];
$journal = $nextresult['client'];
$username="$lname, $fname";
$user[$i] = $username;
$client[$i]=$journal;
} 
}
mysql_close($session);
sort($user);
?>
<html>
<head>
</head>
<body>
<form name="form" method="post" action="">
<select name="name" id="name">
<?php
foreach ( $user as $user_name ) {
echo "<option>{$user_name}</option>";
}
?>
</select>
<select name="client" id="client">
<option>
<?php
foreach ( $client as $yesno ) {
if($yesno==1){ echo "<option>Yes</option>";}
if($yesno==0){ echo "<option>No</option>";}
}
?>
</option>
<option selected "$user_input"></option>
</select>
<input name="change" type="button" value="Change"></form> 
</body>
</html>

Anyone? I'm really stuck. I need a way for either another combo box or radio buttons to be automatically updated when the main combo box is updated (containing names) to their appropriate values in the db.

Okay I get the updating the database part, but what in the world is ^ that supposed to say? ???

 

Automatically update to what? Can you lay out 2 examples please? One where the radio buttons automatically update and one where it's not.

Ok i am looking to have one of the following setups:

1.jpg

 

2.jpg

 

The values in the combo box on the left and the yes/no in either object on the left are stored in the database they are being read from.

What i want to happen is if a user were to change the combo box on the left the object on the right would update to reflect it's value in the database. I hope that helps...

Well, PHP can be involved.  Revraz is saying it can't be done with pure php.

 

What you can do is have javascript call a php script to do the update, without loading a new page.  That kind of idea is called Ajax.  Ajax is too complex to explain here, so if you're serious about providing that kind of functionality, I would do some tutorials.  It won't take long before you can do what you're trying to do (trigger a database update based on an action such as button click or change of a combo box value.

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.