Hello I created a menu from a table. I added to the table employee the user none to make it the default value in the option menu. The problem is that I dont know how to add the none user as the default value in the option menu. Here is what I have:
$query = "SELECT UserName FROM employee where Classification_ClassificationID = '2'";
$result = queryMysql($query);
if (!queryMysql($query)) {
"Query fail: $query<br />" .
mysql_error() . "<br /><br />";
}
else
{
<select name = "UserName", "Name" size = "1">'; // or name="toinsert[]"
while ($row = mysql_fetch_array($result)) {
'<option value="' . htmlspecialchars($row['UserName']) . '" >'
. htmlspecialchars($row['UserName'])
. '</option>';
echo <option selected="selected">Non User</option> before the while loop. Also read comments #Cybernate .
<select>
<?php
if (!queryMysql($query)) {
"Query fail: $query<br />" . mysql_error() . "<br /><br />";
}
else
{
while ($row = mysql_fetch_array($result)) {
$selected = '';
if($row['Username']=='none') $selected = ' selected="selected"';
echo '<option value="'.htmlspecialchars($row['UserName']).'"'.$selected.'>'.htmlspecialchars($row['UserName']).'</option>';
}
}
?>
</select>
Related
I'm displayed a dropdown list of initials that come from a table. I insert "--" at the start before getting the initials from the table.
It goes:
AB
CD
EF
I want it to select the default. $init is the defaulkt
The code below works for '--' but not for the initials.
On the While, if I remove the if statement and just leave the 'else'
echo "<option value='" . $row['id'] . "'>" . $row['init'] . " ";
it is OK.
The first half of the if statement should be the same but with 'selected added.
I don't understand why it is not working.
All I get is "--", not the initials, or any other following input.
Thanks for your help.
<?php
echo $init;
// Drop down list initials
$conn=createconnection();
$sql = "SELECT * FROM employees WHERE lef='0' AND man='1' ORDER BY init";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Updated by and date<br>";
echo "<select name='select_initial' id='select_initial'>";
if ($init==="--"){
echo "<option value='" . '0' . "'selected>" .'--' . " </option>";
} else {
echo "<option value='" . '0' . "'>" . '--' . " </option>";
}
// output data of each row
while($row = $result->fetch_assoc()) {
if ($init===$row('init')) {
echo "<option value='" . $row['id'] . "'selected>" . $row['init'] . " </option>";
} else {
echo "<option value='" . $row['id'] . "'>" . $row['init'] . " </option>";
}
}
echo "</select>";
//echo "<br><br>";
}
$conn->close();
?>
I found if I used square brackets round the $row function it worked:
if ($init===$row['init']) {
My dropdown list displays user names that I get from the database. I want to implement a displayInfo function so that when someone selects a user, it will automatically display his/her info below.
How can I display a user's info when someone selects their name?
This is my dropdown code:
<?php
//connect
$conn = mysqli_connect("localhost","user","123abc");
mysqli_select_db($conn, "users");
//query
$sql= mysqli_query($conn, "SELECT person_id,first_name FROM users");
echo "<select name='dropdown' onchange='displayInfo' id='dropdown'>";
while ($row = mysqli_fetch_array($sql))
{
//display friends' first names on dropdown
if($row['person_id'] == $row['first_name']) {
echo "<option value='" . $row['person_id'] . "' selected>" . $row['list_name'] . "</option>";
} else {
echo "<option value='" . $row['person_id'] . "'>" . $row['first_name'] . "</option>";
}
}
echo "</select>";
Best way to call a Javascript function on option select like this
<?php
//connect
$conn = mysqli_connect("localhost","user","123abc");
mysqli_select_db($conn, "users");
//query
$sql= mysqli_query($conn, "SELECT person_id,first_name FROM users");
echo "<select name='dropdown' onchange='displayInfo' id='dropdown'>";
while ($row = mysqli_fetch_array($sql))
{
//display friends' first names on dropdown
if($row['person_id'] == $row['first_name']) {
**echo "<option onchange='myFunction(this);' value='" . $row['person_id'] . "' selected>" . $row['list_name'] . "</option>";**
} else {
echo "<option onchange='myFunction(this);' value='" . $row['person_id'] . "'>" . $row['first_name'] . "</option>";
}
}
echo "</select>";
<script>
function myFunction(control){
$(control).val() //to access value or any other functionality
}
</script>
To reduce the risk of sql injection I decided only to use preset drop down menus for users to query the database. I have a set of five drop downs that work well together with a single submit button and it opens the page it should but I'm not getting any data. I think I've tried everything that I can find and I suspect it is the select line that is wrong but I've tried dozens of variations without success. It seems that every tutorial shows something different and none of the ones I've found have helped.
The drop down I'm using is this:
<form action="test_result3.php" method="post">
<?php
mysql_connect('localhost', 'user', 'password');
mysql_select_db('database');
$sql = "SELECT DISTINCT Country FROM engravers Where Country <>'' AND Country IS NOT NULL ORDER by Country";
$result = mysql_query($sql);
echo "<select name\\='Country'>";
echo "<option value='$_POST'>Country</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Country'] . "'>" . $row['Country'] . "</option>";
}
echo "</select>";
$sql = "SELECT DISTINCT Year FROM engravers Where Year <>'' AND Year IS NOT NULL ORDER by Year";
$result = mysql_query($sql);
echo "<select name\\='Year'>";
echo "<option value='$_POST'>Year</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Year'] . "'>" . $row['Year'] . "</option>";
}
echo "</select>";
$sql = "SELECT DISTINCT Engraver1Surname FROM engravers Where Engraver1Surname <> '' AND Engraver1Surname IS NOT NULL ORDER by Engraver1Surname";
$result = mysql_query($sql);
echo "<select name\\='Engraver1Surname'>";
echo "<option value='$_POST'>Engraver</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Engraver1Surname'] . "'>" . $row['Engraver1Surname'] . "</option>";
}
echo "</select>";
$sql = "SELECT DISTINCT Designer1Surname FROM engravers Where Designer1Surname <>'' AND Designer1Surname IS NOT NULL ORDER by Designer1Surname";
$result = mysql_query($sql);
echo "<select name\\='Designer1Surname'>";
echo "<option value='$_POST'>Designer</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Designer1Surname'] . "'>" . $row['Designer1Surname'] . "</option>";
}
echo "</select>";
$sql = "SELECT DISTINCT Printer FROM engravers Where Printer <>'' AND Printer IS NOT NULL ORDER by Printer";
$result = mysql_query($sql);
echo "<select name\\='Printer'>";
echo "<option value='$_POST'>Printer</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Printer'] . "'>" . $row['Printer'] . "</option>";
}
echo "</select>";
?>
<input type="submit" />
</form>
This takes me to the php page test_results3 but it is blank.
<?php
mysql_connect('localhost', 'user', 'password') or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$query=("SELECT * FROM engravers WHERE $Country = $_POST['Country']", $Year = $_POST['Year'], $Engraver1Surname = $_POST['Engraver1Surname'], $Designer1Surname = $_POST['Designer1Surname]', $Printer = $_POST['Printer']);
while($result = mysql_fetch_array( $query ));
$num=mysql_numrows($result);
$i=0;
while ($i,$num){
$i++;
}
{
echo $result['Country'];
echo " ";
echo $result['Year'];
echo " Engraver: ";
echo $result['Engraver1Surname'];
echo " Designer: ";
echo $result['Designer1Surname'];
echo " Printer: ";
echo $result['Printer'];
echo " ";
$img_url = "http://www.engravedstamps.net/images/";
{
echo '<img src="'.$img_url.$result['Images'].'" />';
}
echo "<br>";
echo "<br>";
}
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
echo "<b>Searched For:</b> " .$find;
}
mysql_close();
?>
I seem to be getting more confused and frustrated by the hour with this. So far I've spent six weeks trying to write a three page search and display website and I don't feel like I'm any closer than when I started. Any help at all would be greatly appreciated.
update.php
$q = mysql_query("SELECT id FROM performer WHERE username='$user' LIMIT 1") or die("Error : " . mysql_error());
$r = mysql_fetch_assoc($q);
$id = $r['id'];
$query = mysql_query("SELECT baned_c, baned_c2, baned_c3 FROM performer_s WHERE id='$id' LIMIT 1");
$result = mysql_fetch_assoc($query);
if($result['baned_c'] == NULL) { $res1 = "NONE"; } else { $res1 = $result['baned_c']; }
<?php
echo "<form method=post action=insert.php>";
echo "<select name=country>";
echo "<option value=>NONE</option>";
$country = mysql_query("SELECT DISTINCT country_name FROM country_list ORDER BY country_name ASC");
while($next = mysql_fetch_assoc($country))
{
if($next['country_name'] == $res1)
{
echo "<option selected value=" . $next['country_name'] . ">" . $next['country_name'] . "</option>";
}
else
{
echo "<option value=" . $next['country_name'] . ">" . $next['country_name'] . "</option>";
}
}
echo "</select>";
echo "<br /><input type=submit value=Update List />";
echo "</form>";
mysql_close();
insert.php
$country1 = $_POST['country'];
$user = $_SESSION['MM_Username'];
$query = mysql_query("SELECT id FROM performer WHERE username='$user' LIMIT 1") or die("Error : " . mysql_error());
$row = mysql_fetch_assoc($query) or die("Error : " . mysql_error());
$id = $row['id'];
if(isset($country1)) { mysql_query("UPDATE performer_s SET baned_c='$country1' WHERE id='$id'") or die("Error : " . mysql_error()); }
hello 2 all, new here and its nice too meet you.
hope you can help me out
Up here are my 2 pages update.php and insert.php
my problem :
if $country1 = $_POST['country']; is a one word country all is good but if its a two word country $_POST only gives me the first word
$country1 = $_POST['country'];
if its AMERICA its OK
if its REPUBLIC OF KOREA NOT OK i only get REPUBLIC
what can i do ?
Try changing:
echo "<option value=" . $next['country_name'] . ">" . $next['country_name'] . "</option>";
for:
echo "<option value=\"" . $next['country_name'] . "\">" . $next['country_name'] . "</option>";
You are, basically, generating this HTML right now:
<option value=REPUBLIC OF KOREA>REPUBLIC OF KOREA</option>
and you should be generating this HTML:
<option value="REPUBLIC OF KOREA">REPUBLIC OF KOREA</option>
By the way, do the same thing (add the "s) to the other echo (the selected one).
<?php
require_once("../../db_connect/db_connect.php");
$decoded = json_decode($_GET['json']);
$ias = $decoded->{'ias'};
$ian = $decoded->{'ian'};
$select = "select iacode,ianame from isdsmot_ia_creation";
$res = mysql_query($select);
while ($row = mysql_fetch_array($res)) {
$ias = $row['iacode'];
$ian = $row['ianame'];
$ia=$ias."|".$ian;
echo "<OPTION value = \"" . $row[0] . "|" . $row[1] . "\">" . $ia . "</OPTION>";
}
$result=$ia;
if ($result) {
echo "Successful" . mysql_error();
} else {
echo "Unsuccess" . mysql_error();
}
?>
Will this help you : add around your
<?php
require_once("../../db_connect/db_connect.php");
$decoded = json_decode($_GET['json']);
$ias = $decoded->{'ias'};
$ian = $decoded->{'ian'};
$select = "select iacode,ianame from isdsmot_ia_creation";
$res = mysql_query($select);
echo '<select name="myDropDown">';
while ($row = mysql_fetch_array($res)) {
$ias = $row['iacode'];
$ian = $row['ianame'];
$ia=$ias."|".$ian;
echo "<OPTION value = \"" . $row[0] . "|" . $row[1] . "\">" . $ia . "</OPTION>";
}
echo '</select>';
$result=$ia;
if ($result) {
echo "Successful" . mysql_error();
} else {
echo "Unsuccess" . mysql_error();
}
?>