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.
Related
I badly need your help on this.
I can't seem to find what's wrong in my code.
The case is, I am trying to populate my textbox field based on my combobox value and it is connected in sql database. I have tried some codes on the web and then I found a code which seems accurate but I can't seem to display the result on my textbox.
here is my HTML Code:
<?php
echo"Concept Store:";
echo "<select width='100' id='strs' name='strs' >";
echo "<option></option>";
while($row=sqlsrv_fetch_array($stmt))
{
$x= $row['strnm'];
echo " <option> $x</option>" ;
}
echo "</select>";
?>
Address    : <input type="text" id="add" name="add" size="27" /><br><br>
here's the AJAX:
<script type="text/javascript">
$(document).ready(function(){
$('#strs').change(function(){
$.post("gadd.php",{strs:$(this.val() )},function(result){
$("#add").val(result);
});
});
});
</script>
and here's my 'gadd.php'
<?php
session_start();
include ('sqlconn.php');
$gadd=$_post['strs'];
//$t1= mysql_real_escape_string($t1);
$sql="Select distinct dadd1 from ostore where strnm='".$gadd."' ";
$stmt = sqlsrv_query($conn,$sql);
//echo "<option></option>";
while ($row = sqlsrv_fetch_array($stmt))
{
// $type2=$row['dadd1'];
echo $row['dadd1'];
//echo '<option value ="'.$type2.'">'.$type2.'</option>';
}
?>
if you could help me, that would be really really awesome thank you!
Check it. Global variables should be in upper case.
$gadd = $_POST['strs'];
First, make sure you use the proper format for global variables $gadd = $_POST['strs'];
Second, check your query if it is working, try this
$sql=("Select distinct dadd1 from ostore where strnm = '$gadd'");
Most problably it's because you're missing the value in the option.
Use this:
echo " <option value='$x'> $x</option>" ;
instead of this:
echo " <option> $x</option>" ;
If still don't work, like was said before check if the query is working.
You can do that in chrome by the option "Inspect element" and the go to the "Network" tab. You can see what is sent through ajax and the return data.
I have researched many places to find an answer to this question, but they never quite answer my real question: What is the best/approved way to move to a new page within the same website? I have read that it is bad to use window.location because search engines will think you are hiding something. But, when I don't want to open a new window (window.open), then I don't know how else to do it. I use href anchors in links and form actions, where appropriate. But when I have menus or buttons with onclick, then I need something else.
Here's an snippet of my code:
my javascript: (with one option commented)
function gotoCat() {
var catcdF = document.catSelect.catcd.value;
<?php
echo "window.location.href='http://www.mysite.org".$pgmdir."services/busMenu.php?catF='+catcdF; ";
/*
echo "window.open('http://www.mysite.org".$pgmdir."services/busMenu.php?catF='+catcdF,'','resizable=1,scrollbars=1,toolbar=1,top=50,left=300,width=950,height=800,location=0'); ";
*/
?>
}
My dynamic SELECT list in a form (within PHP):
echo " <select name='catcd' id='catcd' size='8' onclick=gotoCat() > \n";
// display list of categories
if ($numcats == 0) { // print message text only
echo "<option value='0' >".$catMsg."</option> \n";
}
else {
for ($i=1; $i<=$numcats; $i++) {
$catcd_db = $catAry[$i][1];
$catName_db = $catAry[$i][2];
echo "<option value='".$catcd_db."'> ".$catName_db." </option> \n";
}
}
echo "</select>";
So, as you can see, I just want a method to allow the user a choice and then automatically go to the correct web page once selected. This is not always in a select list. Often it's when they want to exit or get an error:
if (mysqli_connect_errno()) {
echo "<br/> <p style='text-align:center;'> <button type='button'
class='buttonStyle' style='padding: 4px 20px;' value='Exit' ";
echo "onClick=\"window.location.href='http://www.mysite.org/services/catSelbus.php?rc=1&func=Rev'\" > ";
echo "Exit </button></p> ";
}
I cannot use "go back" because they need to go to a prior page, not the form they came from.
So, unless my navigation methods are really off-the-mark, I guess I need to know the acceptable method for using javascript onClick to move to the next page in the same website. Is window.location okay, or should I use something else?
Any opinions or suggestions are welcome!
To navigate to another page using Javascript, use:
window.location.href = "url";
That's how it's done and there's nothing wrong about it.
For the sake of argument, you could create a hidden link and simulate a click on it, but as I said, there's really no need.
You can use php header('location') instead:
<form action="submit.php">
<input type="hidden" value="test" name="hidden1" />
<input type="submit" Value="Exit" ... />
submit.php
<?php
if (isset($_POST['hidden1'])
{
header('Location: http://www.mysite.org/services/catSelbus.php?rc=1&func=Rev');
exit;
}
?>
More info about header('Location ...');:
http://php.net/manual/en/function.header.php
Instead of a hidden, you use your select's value and get it via the $_POST variable.
I can't think of an easy way to explain what I'm trying to accomplish..
Inserting data into MySQL using php is simple, yet I need to be able to give users the option to add more text inputs in one form...
Just for example purpose...
Users can create a shopping list, the page loads with 15 inputs for 15 items they wish to insert into their shopping list...
At the bottom, they can have the option to add another item, and when clicked, it will show an additional text input..
I've looked for examples but off the top of my head I can't think of any...
if(isset($_POST['createList']){
$item=addslashes(strip_tags($_POST['item']));
}
mysqli_query("INSERT INTO shoppingLists (id,itemName) VALUES (``,`$item`)");
How do insert multiple items with a simple POST?
I was hoping it's possible to use JQuery to add additional input fields.. but how is something like this accomplished on the PHP side?
I do hope I've explained this well enough haha.
You can use an array for your input name attribute
<input type="text" name="item[]" />
And you can browse it by looping through your variable $_POST['item'], that now contains an array with an entry for each field in your form.
I use jQuery .clone() for this.
html:
<div id=="ShoppingList">
<input class="item" name="item[]" />
<input type="button" onclick="addAnotherItem()" />
</div>
js:
function addAnotherItem(){
$("#ShoppingList input.item:first").clone().val("").appendTo("#ShoppingList");
}
I use .val("") so that whatever value the first input has isn't copied to the new one.
Sample Code For This inserting multiple images
if(isset($_POST['addSpace'])){
$spaceTitle = mysql_real_escape_string($_POST['title']);
$spaceBody = mysql_real_escape_string($_POST['text']);
if($_FILES['SliderImage']['tmp_name'] != "" ){
if (($_FILES["SliderImage"]["type"] == "image/jpeg")
&& ($_FILES["SliderImage"]["size"] < 2000000))
{
if ($_FILES["SliderImage"]["error"] > 0)
{
echo "<div class='error_box'><p>Error :: " . $_FILES["SliderImage"]["error"] . ".</p></div>'";
}else{
$path = "../images/prisma-img/demo/services/";
$path2 = "images/prisma-img/demo/services/";
$num = mt_rand();
if (file_exists($path . $num.".jpg" ))
{
echo "<div class='error_box'>"."(".$num .")".
" already exists. "."</div>";
}else{
if(move_uploaded_file($_FILES["SliderImage"]["tmp_name"],$path . $num.".jpg" )){
$mysqlPath = $path2. $num.".jpg" ;
$result = $db->insert("pages","pageTitle, pageImage, pageBody, pageSlug ", "'$spaceTitle','$mysqlPath','$spaceBody','services'");
if($db->affected_rows()){
$id=mysql_insert_id();
echo '<div class="valid_box"><p>Success :: Services successfully Added.</p></div>';
echo "<meta http-equiv='refresh' content='1; url= add-services-slide.php?id=".$id."' />";
}
}
}
}
}else{
echo '<div class="error_box"><p>Error :: Only JPEG file allowed.</p></div>';
}
}
}
?>
Hope that this will help u.
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.