I'm stuck with, what I think, should be something basic. But i can't, for the love of anything, get it to work.
:
echo "<tr><td>Aktiv</td><td>";
echo "<select class=left size=1 name=active>";
echo "<option value=1>aktiv</option>";
echo '<option value=0 selected>inaktiv</option>';
echo "</select>";
echo "</td></tr>";
:
I just want to create a dropdown and preselect the "inaktiv" option.
The funny part is, when using it on my Work-PC, this will still preselect "aktiv".
When i throw this in any kind of other thing, even the most basic online "compiler", it will do just fine.
Are there mybe any kind of kompatibility issues with this on like older versions of Firefox or something like that?
Related
In this code, I'm trying to take a user that wants to change event statuses from a dropdown. The dropdown consists of three options:
"Contacted"
"Verified"
"Completed"
I want a user to click "Submit status" and take them to change.php, as specified in the action attribute. Change.php should have 2 get parameters: the id of the database column of the event they want to alter, and the new status they want to change it to. For example it should look like this: http://localhost/schedule/change.php?id=60?status=verified
But this is what I'm getting right now:
http://localhost/schedule/change.php?status=verified&submitStatus=Change+status
And also, the dropdown is showing an error: Notice: Undefined index: status in line 1
// Assume this is line 1
echo "<form method='get' action='change.php?id=".urlencode($e['id'])."?url=".urlencode($_GET['status'])."'><select name='status' id='status'>'";
if ($e['status'] == "contacted") {
echo "<option value='contacted' selected>Contacted</option>";
echo "<option value='verified'>Verified Appointment</option>";
echo "<option value='completed'>Job Completed</option>";
$counter++;
} else if ($e['status'] == "verified") {
echo "<option value='verified' selected>Verified Appointment</option>";
echo "<option value='contacted'>Contacted</option>";
echo "<option value='completed'>Job Completed</option>";
$counter++;
} else if ($e['status'] == "completed") {
echo "<option value='completed' selected>Job Completed</option>";
echo "<option value='contacted'>Contacted</option>";
echo "<option value='verified' selected>Verified Appointment</option>";
$counter++;
} else {
echo "No event status found!";
}
if ($counter == 1) {
echo "<input type='submit' name='submitStatus' value='Change status'></form></select>
</td>";
echo "</tr>";
}
I know the real issue lies in the first echo line, where I start the form tag, and I know the issue is in the action parameter, but I just don't know what to do! Please help me out here...
The error is that you are using ? to separate parameters instead of using & or &&. So your code should be:
echo "<form method='get' action='change.php?id=".urlencode($e['id'])."&url=".urlencode($_GET['status'])."'><select name='status' id='status'>'";
Also, as said by Phil, try using POST if you don't want to change the data values from url. For example, if you change, id from url, change.php will make changes on the basis of id parameter from url. It seems to me like you should use POST as change to me means quite secure thing and not the thing to be done via GET.
Obviously, it does not mean you should not use GET. These methods are equally important, but not as secure in the sense that data can be changed from url so easily. GET can be used in search process, for example where you don't have to change to the database, you just have to retrive.
I might have gone off topic, but I think that was quite important for you to know which method you should be using. Thank you!!!
I coded adding comments function to RSS articles
In the twists and turns, it is in php coding to show and enter comments. However, the input box does not appear.
Here is the php code:
$url = "./comments/" . $q.".txt";
//댓글 파일에서 컨텐츠 문자열 가져오기
$txtcomment = file_get_contents($url,true);
//댓글 나열
echo "<ol>";
if ($q !== "" ) {
$comm = $txtcomment;
$arr = [];
$arr = explode("--",$comm);
for ($i=4;$i<count($arr);$i++) {
echo "<li>".$arr[$i]."</li>";
}
} else {
echo "해당기사가 없습니다.";
}
echo "</ol>";
//중첩검색&결과내 검색 폼 만들기
echo "<br><form class=\"category B\" >
Comment: <input type=\"text\" name=\"comment1\" id=\"comment1\" onkeyup=\"inputComment()\" >
</form>";
Why?
Thank for your concern.
Since I use RSS, I presume that php does not properly pass the attributes of the input tag in between. I started to change the old coding.
In other words, I decided that the Show Comments and the input comments were different from the beginning.
getrss.php code as below at first.
echo " <option id=".$i." onclick=\"showComment".$i."(this.value)\" value=".$item_link4."> Show Comments </option>";
but, I added the input code as like
echo " <option id=".$i." onclick=\"showComment".$i."(this.value)\" value=".$item_link4."> Show Comments </option>";
echo "댓글: <input type='text' name='inputComment' size='200' id='input".$i."' onclick='inputComment".$i."(this.value)' >
<input type='text' name='txtfile' id='txt".$i."' value=".$item_link4." hidden>
<div id='comment".$i."'><b>information will be listed here.</b></div>";
And, I make input box as a below picture.
In the end, I am trying to solve the problem in a roundabout way.
But, I still wonder why ajax's ajax is not working!!
After I input my comment, at once I see that.
further coding makes a below picture.
Thanks a lot for your sharing.
it is only displaying the first select box and the last one ..
here is the code.
function select_nom_of_guests($guest_type){
$i=0;
echo $guest_type;
echo "<select name=\"adults_num\" id= \"a\">";
while ($i<=5){
echo "<option value= $i>$i</option>" ;
$i++;
}
}
echo "<p>";
select_nom_of_guests("מספר מבוגרים");
select_nom_of_guests("מספר ילדים");
select_nom_of_guests("מספר תינוקות");
echo "</p>";
Close your <select> tags and it should work better ;-)
Note that a for loop would be more appropriate in your case.
Note that you don't end the <select> tag. I'm not sure how browsers would respond to that, but it definitely wouldn't help.
One helpful tool in these scenarios is the View Source tool that all major browsers have: instead of being confused about what's appearing on the screen, look at the HTML that the browser received to see why it might be showing what it's showing. If this is the issue, the source code would have revealed it lickity-split :)
You didn't close the select tag. You probably also want to make the name and id attributes different for each select.
function select_nom_of_guests($guest_type){
$i=0;
echo $guest_type;
echo "<select name=\"adults_num".$guest_type."\" id= \"select_".$guestType."\">";
while ($i<=5){
echo "<option value= $i>$i</option>" ;
$i++;
}
echo "</select>";
}
Thank you so much for being so helpful. Owe you all a thank you. I will be asking more questions in the future. Someone has solved the problem by giving me this code:
echo "" . strval($row['style']) . "" . "";
and it worked beautifully!!!!!!!!! You rock!
I am sorry, I don't know how to post follow up questions, so I keep posting each question as a new question. I've never joined any forum before, so don't know how to follow a thread :( Sorry
I previously asked a question, but didn't post my code, so many kind people (thank you so much) who respanded couldn't help me out.
So I'll post my partial code below.
";
echo "Select an item";
echo "";
}
while($row = mysql_fetch_array($result))
{
echo "$row[style] $row[color]";
}
mysql_close($con);
echo "";
echo "";
echo "Enter your 4 digit postcode";
echo "";
echo "";
echo "Enter quantity";
echo "";
echo "";
echo "";
echo "";
?>
Then to process form, I use $_POST['item'] to find out which item was selected, I get the first word, the rest of the words are missing.
For example, if the dropdown box was populated with the follwoing:
Dressmaker mannequin size 12
Mannequin torso PH-9 in skin color
...
if item selected was "Dressmaker manenquin size 12", $_POST['item'] gives me Dressmaker, the rests are missing.
I spent whole last night and today searching, but have made no progress, please help :(
This still applies from my previous post:
//====== Begin previous post
Hopefully, your MYSQL database has a primary key? If it does, set the value of each <option> to the primary key of the item.
For example:
SQL
id desc
1 "dressmaker thing with mannequin"
2 "dressmaker thing no mannequin"
Form PHP
echo "<option value='".$query['id']."'>".$query['desc']."</option>";
When the form is submitted, re-query the database for the desired description. You'll be doing this re-query anyway to retrieve prices and such, yes?
The reason this is happening is that spaces are discouraged in HTML attributes. You shouldn't have an attribute like value='this attribute is spaced'.
//====== End previous post
Basically, change this line:
while($row = mysql_fetch_array($result))
{
echo "<option value=$row[style]>$row[style] $row[color]</option><br />";
}
to
while($row = mysql_fetch_array($result))
{
echo "<option value='".$row['id']."'>$row['style'] $row['color']</option><br />";
}
and add this in process_form.php to get the description:
$desc = mysql_query("SELECT style FROM products WHERE id='".$_POST['item']."';");
You can also use this to get all other related info from the DB right when you need it.
// Another edit
#Cambraca - right on - I forgot to sanitize the quote.
#Ottoman - Your solution is a temporary fix. I strongly recommend applying an id/primary key system if it's not in place. An ounce of prevention is worth a pound of cure.
That is because in php you get what is in the "value" attribute of the dropdown's options.
You need to do something like this:
Replace
echo "<option value=$row[style]>$row[style] $row[color]</option><br />";
with
echo "<option value=\"$row[style] $row[color]\">$row[style] $row[color]</option><br />";
The problem is your lack of quotes in the option "echo" statement.
Try something like this
while($row = mysql_fetch_array($result))
{
printf('<option value="%s">%s %s</option>',
htmlspecialchars($row['style']),
htmlspecialchars($row['style']),
htmlspecialchars($row['color']));
}
Note also, the <br> element does not belong in the <select>
Edit: Added htmlspecialchars to properly escape any HTML entities that might exist in retrieved strings
If it gives you only the first word, then you forgot to enclose the option value="with quotes". Otherwise show us the constructed HTML source.
here is my problem. I have an xml file that acts like a small database. My php code goes through the xml file and retrieves the info creating a form. For example, the xml file holds info about a menu, the user chooses salad, then the code will print out all types of salads and the user then chooses his favourite salad. The actual problem is that there are different portions; small and large and different prices for each!
I am not able to keep track of the selected item... X(
Any help??
Thanks in advance
here is my code:
<?php
foreach ($xml-> CATEGORY as $category)
{
if($_GET['category']==$category["id"])
{
echo "<h3>".$category ["id"]."</h3>";
echo "<br />";
echo "<form method=\"post\" action=\"add.php\">";
foreach ($category -> FOOD as $food) {
echo "<li>";
echo "<b>".$food["name"]."</b>";
echo "<hr>";
echo "</li>";
echo "<select name=\"variations[]\">";
foreach($food -> PRICE as $price)
{
echo "<option value=\"$price\">";
echo "<ul>";
echo $price["size"]. " ";
echo $price;
echo "</ul>";
echo "</option>";
}
echo "</select>";
echo "<input type=\"submit\" value=\"Buy this\">";
}
echo "<br />";
echo "<br />";
}
echo "</form>";
}
?>
the cart looks something like this
<?php
echo "<br>";
$values = $_POST['variations'];
foreach($values as $value)
{
echo $value;
echo "<br>";
}
?>
the code above only shows prices about small items. Large items are somehow ignored!! This code is not actually what I meant to do but it's an start. It should say:
You have chosen a large portion of greek salad for £10.50.
So, I should be able to pass three variables that I don't know how: $price[size], food and $price...
Thanks for your time
if i understand you correctly, you are just recieving the selected size (price) but not the actual meal?
well two possible solutions:
version one:
create a second form field that holds the selected meal.
i think its elegant and logical if you have checkboxes for the meals and then radio buttons or lists for the size... so you can check/uncheck meals but if its check you need to select a size...
you can also just let the user select the price and dynamlically select the the meal field too with javascript but i wouldnt suggest that, if you want this kind of user experience, i'd opt for vesion two
version two:
include the meal in the value of the input field that for the price. maby seperated by a comma or as a json encoded string.
then when you retrieve the post variable you can split/decode...
if you give me a working example which i can just paste into a file and hit it (including the xml object) i can quickly do that for you...