I have a simple input form with input fields that are 3 characters wide. To gain focus to these fields however, I must click the very, very LEFT of the field, about 1 pixel or cursor width wide. The form works fine in Firefox and Safari, where you can click anywhere in the text input field to gain focus.
The form:
<form name=game_edit method=post action="?includepage=game_results.php&gameID=<?=$gameID?>" onsubmit="return validate_form();">
<table border="0" id=gameResults>
<tr><th colspan="4">RESULTS FOR: <?=$gamedate?> HOSTED BY <?=$hostName?></th></tr>
<tr>
<td colspan="2">PLAYERS: <input type=text name=playercount value="<?=$playercount?>" size="3"></td>
<td colspan="2">Championship money colleted: $<?=$champamount?></td>
</tr>
<tr><th>PLAYER</th><th>Place</th><th>Champ Discount</th><th>Didn't play</th></tr>
<? Player_list($gameID); ?>
<tr><td colspan="2"><input type="text" name="manualAdd" size="17" /></td><td colspan="2">Add a username who didn't RSVP</td></tr>
<input type=hidden name=gameID value="<?=$gameID?>">
<tr>
<td colspan="2"><input type=submit name='saveGameResults' value='SAVE CHANGES' style='width:100px;font-size:11px;'></td>
<td colspan="2" align="right"><input type=submit name='saveGameResults' value='LOCK GAME' style='width:100px;font-size:11px;'></td>
</tr>
</table>
The function that writes the fields:
function player_list($gameID)
//////////////////////////////////////////////
// Creates player list for specified //
// game. Provides input for game results. //
//////////////////////////////////////////////
{
//*****Get list of players for gameID*****
$sql = "SELECT rsvpid,rsvp.playerid,concat(fname,' ',lname) as playerName,place,points,freeChamp FROM rsvp LEFT JOIN players ON rsvp.playerid=players.id WHERE rsvp.gameID=$gameID ORDER BY place,lname";
$playerlist = mysql_query($sql);
if ($listrow = mysql_fetch_array($playerlist))
{
#--Get number of players who signed up on the website. This may differ from the actual player count --#
#--entered by the host. A player may have played but not be signed up on the website. --#
echo "<input type=hidden name='recordedPlayerCount' value='".mysql_num_rows($playerlist)."'>";
$i = 0; // index for form rows
do
{
foreach($listrow as $key=>$value) $$key = $value;
($freeChamp) ? $freeChampChecked = "checked" : $freeChampChecked = ""; //check the freechamp box if appropriate.
if ($place==100) $place="";
?>
<tr>
<td><?=$playerName?>:</td>
<td style="text-align:center"><input type=text size="2" name="place<?=$i?>" value="<?=$place?>"></td>
<td style="text-align:center"><input type=checkbox name="freeChamp<?=$i?>" value='true' <?=$freeChampChecked?>></td>
<td style="text-align:center"><input type=checkbox name="noShow<?=$i?>" value='true'></td>
<input type=hidden name="rsvpid<?=$i?>" value="<?=$rsvpid?>">
</tr>
<?
$i++; //increment index for next row
}while ($listrow = mysql_fetch_array($playerlist));
}else
echo "<tr><td colspan='4'>NO RECORDS FOUND FOR THIS GAME!</td></tr>";
}
?>
The offending form field is the "place" field...it is clickable only on the very left of the form field instead of the entire form field, in IE only. (IE 7, that I know of).
Help?
I am willing to bet that the culprit is setting the size of the input element to 2. Give this a shot and let me know if it works any better:
<td style="text-align:center"><input type=text size="3" maxlength="2" name="place<?=$i?>" value="<?=$place?>"></td>
There are other things that I notice in your code:
<tr><th>PLAYER</th><th>Place</th><th>Champ
Discount</th><th>Didn't play</th></tr>
<? Player_list($gameID); ?>
You call the function "Player_list()", but your function is named "player_list()".
foreach($listrow as $key=>$value) $$key = $value;
is the same as:
extract($listrow);
Thanks for the tips, Michael. Found the issue. I have a css-driven horizontal dropdown menu (http://www.udm4.com/) in a header div that drops down over the content div's. Above that, I have a javascript-driven login panel that can drop down over the header div. In playing around with the z-indexes so that everything played nice, I set the content div that holds the form to a z-index of -1. Even after taking out everything except that one div and that one form, IE doesn't like negative z-indexes. I don't know if negative z-indexes constitute valid CSS and IE is just being a tard again, or if other browsers are just too lenient.
Related
I'm developing a simple PHP page, this is a small part of my code that doesn't work properly.
I want to use DB and print some products and for each product, I want to show a "buy" button.
If I press this button, a hidden input must be set with the product id(which later has to be sent to another page).
But, if I use var_dump to control(if my data was correct), I can see that the ID is wrong (I see that its always shown in the last)
<form id="products_list" method="post" action="step2.php">
<table>
<tr>
<td align="center">Immagine</td>
<td align="center">Nome prodotto</td>
<td align="center">Descrizione prodotto</td>
<td align="center">Prezzo unitario</td>
<td align="center">Taglie disponibili</td>
<td align="center">Colori disponibili</td>
<td align="center">Nickname disponibili</td>
</tr>
<?php
$product = mysqli_query($mysqli, "SELECT * FROM products");
while ($row = mysqli_fetch_array($product)) {
$id = $row[id_products];
print("
<tr>
<td align=\"center\">".$row[img_products]."</td>
<td align=\"center\">".$row[name_products]."</td>
<td align=\"center\">".$row[description_products]."</td>
<td align=\"center\">".$row[price_products]."</td>
<td align=\"center\">".$row[size_products]."</td>
<td align=\"center\">".$row[color_products]."</td>
<td align=\"center\">".$row[nick_products]."</td>
<input type=\"hidden\" name=\"id_products\" value=\"".$id."\"/>
<td><input type=\"submit\" name=\"buy\" value=\"Acquista\"/></td>
</tr>");
}
?>
</table>
</form>
You should open and close your form within the while-loop.
EDIT
A little bit more explanation why you should open and close from within the while loop:
If the while-loop is inside the form tags, that means the hidden field is outputted multiple times within the same form. Since they are all named the same, you're only retrieving one value after the submit (the value of the last hidden input).
If you open and close the form within the while-loop, each hidden input and button are in their own form. Which means, when that form gets submitted, you're only retrieving the value of that specific hidden field. :-)
I'm trying to get the website to send the calculation results to another page. The code below is working but I have no idea how to get the rows with the results to be shown in a new page.
I know that i have to change the action below to /mynewpage
But I just want the results not the whole table.
I have no idea what to do to the code to make it show the results only in a new page. IF everything statys in the same page the calculator works well.
It's my first attempt with PHP, I clearly have no idea of what I'm doing. Many thanks in advance.
<?php
if (isset($_POST['valuea'])) $valuea = $_POST['valuea'];
if (isset($_POST['valueb'])) $valueb = $_POST['valueb'];
if (isset($_POST['valuec'])) $valuec = $_POST['valuec'];
if (isset($_POST['valued'])) $valued = $_POST['valued'];
if (isset($_POST['valuee'])) $valuee = $_POST['valuee'];
$balance = $valuec * $valuee;
$newphone = $valuea;
$total = $balance + $valuea;
$total2 = $balance + $valueb;
echo <<<_END
<form method='post' action='/'>
<table border='0' width='500px' cellpadding='3' cellspacing='1' class="table">
<tr class="calcheading"><td colspan="2"><strong>CALCULATOR</strong></td></tr>
<tr class="calcrow"><td>Phone Value:</td><td align="center"><input type='text' name='valuea' value="$valuea"/></td></tr>
<tr class="calcrow"><td>Phone upfront cost:</td><td align="center"><input type='text' name='valueb' value="$valueb"/></td></tr>
<tr class="calcrow"><td>Monthly contract cost:</td><td align="center"><input type='text' name='valuec' value="$valuec"/></td></tr>
<tr class="calcrow"><td>Contract duration:</td><td align="center"><input type='text' name='valued' value="$valued"/></td></tr>
<tr class="calcrow"><td>No. months left in the contract:</td><td align="center"><input type='text' name='valuee' value="$valuee"/></td></tr>
<tr class="submit"><td colspan="2"><input type='submit' value='Calculate'/></td></tr>
_END;
?>
<tr class="calcheading"><td colspan="2"><strong>OPTION 1 - PAY REMAINING OF THE CONTRACT AND BUY SAME PHONE UNLOCKED</strong></td></tr>
<tr class="calcrow">
<td><i>Payment left to network:</td>
<td align="center"><input type="text" value="<?php echo round($balance)?>"></td></i>
</tr>
<tr class="calcrow">
<td><i>New unlocked phone:</td>
<td align="center"><input type="text" value="<?php echo round($newphone)?>"></td></i>
</tr>
<tr class="calcrow">
<td><i>TOTAL:</td>
<td align="center"><input type="text" value="<?php echo round($total)?>"></td></i>
</tr>
<br>
<tr class="calcheading"><td colspan="2"><strong>OPTION 2 - PAY BALANCE LEFT AND GET SAME PHONE ON A NEW CONTRACT*</strong></td></tr>
<tr class="calcrow">
<td><i>Payment left to network:</td>
<td align="center"><input type="text" value="<?php echo round($balance)?>"></td></i>
</tr>
<tr class="calcrow">
<td><i>New contract phone initial cost:</td>
<td align="center"><input type="text" value="<?php echo round($valueb)?>"></td></i>
</tr>
<tr class="calcrow">
<td><i>TOTAL:</td>
<td align="center"><input type="text" value="<?php echo round($total2)?>"></td></i>
</tr></table>
</form>
You can either send the values in a form and receive them on the other page using
$value1 = $_GET['value1'];
$value2 = $_GET['value2']; // etc
The other method would be saving them in a session variable, at the top of any pages where you wish to use session variables, call session_start(), then save them
$_SESSION['value1'] = $value1;
Then in another page, you can call them by simply
echo $_SESSION['value1'];
I'm not sure what you mean by new page? If you have a script like process.php that has that code then you can add session_start(); as your first line after the php start tag. By using $_Session['result']=$calc_result; on the 'process.php' you will store the value in your session. In the 'new page' script you call session_start(); again and you can get the stored value by saying $_Session['result'].
There are many ways to print your answers on a new page but lets keep it simple: A good way to do it would be for you to separate out the HTML form that posts the values and the php calculation logic on two different pages. So for example, your HTML form is in one file values.php (does not have any php code, you can name it with a .html prefix as well) and the php code is in another file calc.php. Now, to your form, specify an action such as
<form method='post' action='calc.php'>
This will post all the values to calc.php where your calculation code is and you can display the results however you please (not limited to a form again) but in a table or so on. Once you learn ajax, you'll never want to come back to doing this.
Here is a working barebones example: http://runnable.com/VEKvtTTrkXFwjAwL/calculator555-for-php
I’m trying to update multiple rows in a mysqli table from an HTML form. The data seems to be getting from the form to my "update database" page. But it’s not going into the database.
Here’s the relevant part of the form:
for($i=0;$i<$rowcount;$i++)
{
$row = mysqli_fetch_array($result);
echo "<tr>
<td> $row[SubFirstName] $row[SubLastName] </td>
<td> $row[PerfFirstName] $row[PerfLastName] </td>
<td style='display:none'><input type='text' class='input' name='PerformerID[]' value= '$row[PerformerID]' /> Years</td>
<td><input type='text' class='input' size= '5' name='GKYears[]' value= '$row[GKYears]' /> Years</td>
</tr>";
}
And here’s the code to insert the values into the database:
for($i=0;$i<$count;$i++)
{
mysqli_query($con, "UPDATE Performers SET
GKYears = '$_POST[GKYears][$i]'
WHERE PerformerID = '$_POST[PerformerID][$i]'");
}
When I do a var_dump of the POST data, it all seems to be there. Can someone explain how to fix this, and why it’s wrong? I’ve got other more complex variants of the same issue for the other pages.
Bad structure. Don't use CSS to simulate a hidden form field, and you don't even need the hidden field:
echo <<<EOL
<tr>
<td>... name stuff ...</td>
<td>... perf stuff ...</td>
<td><input type="text" name="GKYears[{$row['PerformerID']}]" value="{$row['GKYears']}" /></td>
</tr>
EOL;
Note how the ID value gets embedded in the field name, so you'll end up with
<input ... name="GKYears[42]" ... />
<input ... name="GKYears[103]" ... />
Then your PHP-side stuff becomes simply:
foreach($_POST['GKYears'] as $rowID => $value) {
... update db for record Id $rowID with value $value
}
Beyond that, your code is gaping wide and just begging for an SQL injection attack.
I am new here and i trying to make some PHP page working but failed miserably.
I am not very good with logic nor PHP, so please bear with my stupid question and my messy codes :)
I have array of textboxes with value and there are array of buttons next to it.
what i want is each button capture specific value what i typed into the corresponding textbox
here's the piece of my code
<?php
$data = mysql_query("SELECT * from tempimg");
while($hasil = mysql_fetch_assoc($data)){
$i++;
echo "<tr>
<td align=center><input type= checkbox name=check[] value=$hasil[idFoto]</td>
<td align=center><img src=$hasil[thumbPath]></td>
<td align=center>$hasil[imgName]</td>
<td align=center>$hasil[thumbPath]</td>
<td align=center>$hasil[Path]</td>
<td align=center>
<input type=text align=center value=$hasil[imgLink] name=link[{$hasil['idFoto']}] id=link />
<td align=center>
<button type=submit onClick=\"return confirm('you clicked button with ID: $hasil[idFoto] '+'value: '+(document.getElementById('link').value))\">
<img src=images/sav.png alt=search-btn id=img />
</button>
</td>
<td align=center><img src=images/del.png></img></td>";
}
?>
and here's the link of image for the PHP page I'm talking about
so I humbly request of help from people here, please help me.
EDIT: thanks to Mr. Barmar i manage to pop out the value of the text box inside the dialog box with the corresponding button,
here a new question, how to save the value from the text box that i got from clicking the corresponding button into the database?
or more simple, how to capture the value from the text box by using the button next to it and then post it on the screen using "echo"
You need to give all the id=XXX attributes unique values, by including $i in the ID. Then your onclick code can get the value of the input from the same row.
<?php
$data = mysql_query("SELECT * from tempimg");
while($hasil = mysql_fetch_assoc($data)){
$i++;
echo "<tr>
<td align='center'><input type='checkbox' name='check[]' value='$hasil[idFoto]'</td>
<td align='center'><img src='$hasil[thumbPath]'></td>
<td align='center'>$hasil[imgName]</td>
<td align='center'>$hasil[thumbPath]</td>
<td align='center'>$hasil[Path]</td>
<td align='center'>
<input type='text' align='center' value='$hasil[imgLink]' name='link[{$hasil['idFoto']}]' id='link$i' />
<td align='center'>
<button type='submit' onclick='return confirm(\"you clicked button with ID: $hasil[idFoto] \"+\"value: \"+(document.getElementById(\"link$i\").value))'>
<img src='images/sav.png' alt='search-btn' id='img$i' />
</button>
</td>
<td align='center'><img src='images/del.png' /></td>";
}
?>
You should also put quotes around all attribute values.
I am making a page which do a search result. To brief the scene is that I have a login page which will direct you to another page (let's say homepage) This page contains 1 drop-down box ( and ), 1 textbox, 1 button and 1 iframe which contains the page where I have my table. Now I have a list of user which is displayed on that table having a header of firstname, lastname and middlename which is all the data is displayed on at startup Now I selected the firstname from the drop-down box then key in my name which should result to a filter for those who have the same name as mine. I used a filter on my table page in which I add the parameters e.g. //localhost/test/table.php?fname=test
Now the thing is that the iframe should be the only one that will change making my homepage intact. Now the iframe src will be changed on click based on what I selected on the drop-down box as I already said without using a form submit and the value will be based on the text on the text box. And also if possible without using http:// on the src link.
Well I almost done the part of onclick will change the iframe page using this script:
<script type='text/javascript'>
function goTo(){
top.table.location = 'http://localhost/test/home.php;
}
</script>
It should be like this:
$dropdownvalue = dropdownselectedtext
$textvalue = valueoftextbox
//localhost/test/table.php?$dropdownvalue$textvalue
Well here it is my first work. commented for better understanding. Assume that '#' followed by text means some value. For reference.
$acct_no = "#LOG_IN_ID OF USER";
echo "<script type='text/javascript'>
function goTo(){
top.table.src = '#SOMEURLHERE';
}
</script>";
echo "<table border='0' align='center' bgcolor='#ffffff' width='800px'>
<tr>
<td style='padding-left:30px;padding-top:20px;'>
<h3>SELECTION TEST</h3>
</td>
<td align='right' style='padding-right:30px;' height='120px'>
<select name='filter' id='filter'>
<option value='fname'>fname</option>
<option value='lname'>lname</option>
<option value='mname'>mname</option>
</select>
<input type='text' value='Enter text here' id='textbox'>
<input type='button' value='Search' onClick='goTo();'> //this should give me the filters e.g: #SOMEURLHERE.php?#selectedfiltervalue=#textboxvalue
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<iframe src='table.php?ref=$acct_no' name='table' width='730px' height='300px' frameborder='0'></iframe>
</td>
</tr>
</table>";
I would suggest that you keep the <script> container outside of PHP area.
<script type="text/js" language="javascript">
//Your function goes here
</script
<?php echo "<form name='someName' action='#'>
echo "<table border='0' align='center' bgcolor='#ffffff' width='800px'>
<tr>
<td style='padding-left:30px;padding-top:20px;'>
<h3>SELECTION TEST</h3>
</td>
<td align='right' style='padding-right:30px;' height='120px'>
<select name='filter' id='filter'>
<option value='fname'>fname</option>
<option value='lname'>lname</option>
<option value='mname'>mname</option>
</select>
<input type='text' value='Enter text here' id='textbox'>
<input type='button' value='Search' onClick='javascript: return goTo(\"this.parent.filter.value, this.parent.textbox.value\");'> //this should give me the filters e.g: #SOMEURLHERE.php?#selectedfiltervalue=#textboxvalue
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<iframe src='' name='table' width='730px' height='300px' frameborder='0'></iframe>
</td>
</tr>
</table></form>";?>
You didn't use a <form> tag in your whole section, so managing fields is difficult. Also, try the javascript I defined in previous post.
Try using this in onclick/onchange handler in your drop down box(for each value):
javascript: return goto(\"$dropdownvalue\", \"$textvalue\");
And, to incorporate it
<script type='text/javascript'>
function goto(var1, var2){
finLink = "http://localhost/test/table.php?" + var1 + var2
top.table.location = finLink; //Not sure if it will be top.table.location or top.table.src
}
</script>
You can use jquery for this:
$('#myiframeid').attr('src', 'http://some.url.here');