Jump to content

drop down list from SQL then Post


mattichu

Recommended Posts

Here is the code ive tried but it doesnt post anything :(

 

<?php

 

$username="*****";

$password="*****";

$database="checkmyw_database";

mysql_connect('localhost',$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT $staffno FROM rotastaff WHERE wkbeg='$wkbeg'";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

 

$staffname=mysql_result($result,$a,"staff1");

 

 

 

$username="******";

$password="******";

$database="checkmyw_database";

mysql_connect('localhost',$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

$query2="SELECT id FROM rotastaff WHERE wkbeg='$wkbeg'";

$result2=mysql_query($query2);

$num2=mysql_numrows($result2);

mysql_close();

 

$id=mysql_result($result2,$a,"id");

 

 

 

?>

 

<div style="position:absolute; top:370px; left:400px;">

<font color="white" size="3">

<table width="300px">

<td>

Select New Name:

</td>

</table>

</font>

</div>

 

<div style="position:absolute; top:430px; left:400px;">

<font color="white" size="3">

<table width="300px">

<td>

<a href="/new/usernotlisted.php">User Not Listed?</a>

</td>

</table>

</font>

</div>

 

 

 

 

<?php

 

mysql_connect("localhost","******","*****");

mysql_select_db("checkmyw_database") or die("Unable to select database");

$result = mysql_query("select DISTINCT username from members");

 

?>

 

<form action="/new/newrotastaffprocess.php" method="post">

<div style="position:absolute; top:400px; left:400px;">

<?

echo '<select name="user"><OPTION>';

echo "Select a User</OPTION>";

echo "Create New..</OPTION>";

while ($row = mysql_fetch_array($result)){

$username = $row["username"];

echo "<OPTION value=\"$username\">$username</OPTION>";

 

}

echo '</SELECT>';

?>

</div>

 

 

<div style="position:absolute; top:397px; left:550px;">

<input type="hidden" size="20" value="<?php echo $result;?>" name="username">

<input type="hidden" size="20" value="<?php echo $wkbeg;?>" name="wkbeg">

<input type="hidden" size="20" value="<?php echo $staffno;?>" name="staffno">

<input type="submit" size="5" value="Change">

</div>

</form>

 

 

</body>

</html>

Link to comment
Share on other sites

Hi

 

This line

<input type="hidden" size="20" value="<?php echo $result;?>" name="username">

, will not post anything as $result is a mysql data result.

 

What code do you have in /new/newrotastaffprocess.php?  How do you know it's not posting anything?

Link to comment
Share on other sites


// Form fetching
if(isset($_POST['option'])){
  $selected_option = $_POST['option']; // Your selected option successfully posted. Now do anything with it.
}

// Options listout with onselect - post option

<?php

mysql_connect("localhost","******","*****");
mysql_select_db("checkmyw_database") or die("Unable to select database"); 
$result = mysql_query("SELECT DISTINCT user_id username FROM members");  // USER ID MUST BE FETCHED AND SELECTED

?>

<form action="/new/newrotastaffprocess.php" method="post">
<div style="position:absolute; top:400px; left:400px;">
<?php
echo '<select name=\'user\' onchange=\'this.form.submit()\'><option selected>Select a User</option>'; // onchange=\'this.form.submit()\' is what submits the form.
echo 'Create New...</option>';
while ($row = mysql_fetch_array($result)){
     $username = $row["username"];
     echo "<OPTION value=\"$_POST['user_id']\">{$_POST['username']}</OPTION>";
}
echo '</select>';
?>
</div>
</form> // YOU DIDN'T CLOSE THIS

 

One more thing, I suggest you start using mysqli function for database. And more of these ''. "" check for variables, '' check only for text so it's faster.

Link to comment
Share on other sites


CORRECTION (unable to modify, don't know why)
I missed a character. :S
$result = mysql_query("SELECT DISTINCT user_id, username FROM members");  // USER ID MUST BE FETCHED AND SELECTED

 

One more thing, I suggest you start using mysqli function for database. And more of these ''. "" check for variables, '' check only for text so it's faster.

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.