how to create pc calculator script in php - php

I have 2 tables one is category and one is products. Now I want to PC calculator.
I have all the fields generated dynamically based on the database. So how can I write script to make like this.
<table ALIGN=CENTER WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=3>
<tr>
<th>Category Name</th>
<th>Product Name</th>
<th>Price</th>
</tr>
<tr class="odd">
<td>Speaker</td>
<td>
<select name="1" size="1" id="1">
<option value="1200.00">intex</option>
<option value="2100.00">creative</option>
<option value="1400.00">intex 2.1</option>
<option value="2000.00">intex 2.1 with woofer</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Laptop</td>
<td>
<select name="3" size="1" id="3">
<option value="31000.00">sony</option>
<option value="31500.00">hp</option>
<option value="31000.00">Acer</option>
<option value="36000.00">ibm</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Mouse</td>
<td>
<select name="4" size="1" id="4">
<option value="120.00"> teccom</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>CPU</td>
<td>
<select name="6" size="1" id="6">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Projector</td>
<td>
<select name="7" size="1" id="7">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Anti Virus</td>
<td>
<select name="23" size="1" id="23">
<option value="450.00">McAfee</option>
<option value="1200.00">AVG</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Processor</td>
<td>
<select name="59" size="1" id="59">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>testing</td>
<td>
<select name="60" size="1" id="60">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>sadfasdfasdfadsfad</td>
<td>
<select name="61" size="1" id="61">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>dfgd</td>
<td>
<select name="62" size="1" id="62">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr>
<td></td>
<td>Total</td>
<td><div id="total"></div></td>
</tr>
</table>
here is jQuery
jQuery(document).ready(function() {
$("#sellp").change(function () {
var str = 0.00;
$("#sellp :selected").each(function () {
var test = $(this).val();
//alert(test);
var tr = parseInt(str) + parseInt(test);
//alert(tr);
$("#t1").text(test);
});
});
var sum = 0;
$("form :element").change(function() {
$('.price').each(function() {
sum += parseFloat($(this).text());
});
$('#total').html(sum) });
});

Firstly show some code.
Assuming all items are in the page when it loads, you need to add some event handlers
Here is plain JS - jQuery may be more elegant. You will likely need to start with this and then add the validation. You will make your life much easier if you name your fields in a way that is easy to get to
<html>
<head>
<script>
function calc(theForm) {
var total = 0;
for (var i=1;;i++) {
var item = theForm.elements["item_"+i];
if (item) {
var price = item.options[item.selectedIndex].value;
if (price && !isNaN(price)) {
price = parseFloat(price);
total+=price;
var priceId = item.id.replace('item','price');
document.getElementById(priceId).innerHTML=price.toFixed(2);
}
}
else break;
}
if (total) document.getElementById('total').innerHTML="$"+total.toFixed(2);
}
window.onload=function() {
var theForm = document.forms[0]; // first form on page
for (var i=0,n=theForm.elements.length;i<n;i++) {
if (theForm.elements[i].type.indexOf("select") !=-1) {
theForm.elements[i].onchange=function() { calc(this.form); }
}
}
theForm.onsubmit=function() { calc(this); return validate(this) }
calc(theForm)
}
</script>
</head>
<body>
<form>
<table ALIGN=CENTER WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=3 >
<tr>
<th>Category Name</th>
<th>Product Name</th>
<th>Price</th>
</tr>
<tr class="odd">
<td>Speaker </td>
<td><select name="item_1" size="1" id="item_1">
<option value="1200.00"> intex</option>
<option value="2100.00"> creative</option>
<option value="1400.00"> intex 2.1</option>
<option value="2000.00"> intex 2.1 with woofer</option>
</select>
</td>
<td><div id="price_1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Laptop </td>
<td><select name="item_2" size="1" id="item_2">
<option value="31000.00"> sony</option>
<option value="31500.00"> hp</option>
<option value="31000.00"> Acer</option>
<option value="36000.00"> ibm</option>
</select>
</td>
<td><div id="price_2" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Mouse </td>
<td><select name="item_3" size="1" id="item_3">
<option value="120.00"> teccom</option>
</select>
</td>
<td><div id="price_3" class="price">0</div></td>
</tr>
</table>
</form>
Total: <span id="total"></span>

Related

PHP function in HTML

I have a form for tracking an investment's performance.
The code looks like this:
<form style="margin-top: 60px" action="" method="post">
<p>
<table>
<tr>
<th>Name of Investment</th>
</tr>
<tr>
<td><select name="">
<?php
$sql = 'SELECT DISTINCT deal_name FROM tbl_deal';
$result = mysqli_query($DBconnect, $sql);
if(mysqli_num_rows($result) > 0)
{
echo "<option value=''>Select Investment</option>";
while($row = mysqli_fetch_array($result))
{
echo "<option value='$row[0]'>$row[0]</option>";
}
}
else
{
echo "<option value=''>No Investments Found</option>";
}
?>
</select></td>
</tr>
</table>
<p>
<table>
<tr>
<th></th>
<th colspan="2">Year 1</th>
<th colspan="2">Year 2</th>
<th colspan="2">Year 3</th>
<th colspan="2">Year 4</th>
<th colspan="2">Year 5</th>
</tr>
<tr>
<th>Month</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
</tr>
<tr>
<th>January</th>
<td>
<select name="">
<option value="">Distribution Received</option>
<option value="">Return of Capital</option>
<option value="">Capital Call</option>
</select>
</td>
<td><input type="text" name="" size="5"></td>
<td>
<select name="">
<option value="">Distribution Received</option>
<option value="">Return of Capital</option>
<option value="">Capital Call</option>
</select>
</td>
<td><input type="text" name="" size="5"></td>
<td>
<select name="">
<option value="">Distribution Received</option>
<option value="">Return of Capital</option>
<option value="">Capital Call</option>
</select>
</td>
<td><input type="text" name="" size="5"></td>
<td>
<select name="">
<option value="">Distribution Received</option>
<option value="">Return of Capital</option>
<option value="">Capital Call</option>
</select>
</td>
<td><input type="text" name="" size="5"></td>
<td>
<select name="">
<option value="">Distribution Received</option>
<option value="">Return of Capital</option>
<option value="">Capital Call</option>
</select>
</td>
<td><input type="text" name="" size="5"></td>
</tr>
...and so on for everything month. As you can see, it's very repetitive. I tried making a PHP function to at least minimize the dropdown menu's redundancy, but I get an 'unexpected <' error.
It seems that the HTML tags are giving me problems?
Any advice how to write PHP functions containing HTML?
Any other advice on minimizing the redundancy?
The new and concise code:
<?php
echo '
<table>
<tr>
<th></th>
<th colspan="2">Year 1</th>
<th colspan="2">Year 2</th>
<th colspan="2">Year 3</th>
<th colspan="2">Year 4</th>
<th colspan="2">Year 5</th>
</tr>
<tr>
<th>Month</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
<th>Category</th>
<th>$</th>
</tr>
';
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$distribReceived = 1;
$returnCapital = 2;
$capitalCall = 3;
$category = "category";
$amount = "amount";
//Loop for each month
for($monthNum = 0; $monthNum < 12; ++$monthNum)
{
echo '<tr>
<th>'. $months[$monthNum] .'</th>
';
//Loop for each year
for($year = 1; $year < 6; ++$year)
{
echo '
<td>
<select name="'.$months[$monthNum].$year.'">
<option value="'.$distribReceived.'">Distribution Received</option>
<option value="'. $returnCapital .'">Return of Capital</option>
<option value="'. $capitalCall .'">Capital Call</option>
</select>
</td>
<td><input type="text" name="'.$amount.$months[$monthNum].$year.'" size="5"></td>
';
}
echo '</tr>';
}
echo' </table><p>';
?>`

PHP: Insert Multiple rows to sql database

I am trying to insert multiple rows of data from my form into my sql database. I have been looking up arrays and been trying to apply what I have found but to no avail. I am beginner to programming never took any formal classes, been learning snipits of code as I need, so my fundamentals are nonexistent.
PlayerID is not auto-increment but an actually number provided by the user.
Here is my form code
<table border="1">
<tr>
<td align="center">Form Input Employees Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="/wp/wp-content/plugins/FormSubmit/FSdotaArray.php">
<tr>
<td></td>
<td><b>Captain</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<td></td>
<td><b>Player 2</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
Here is my php code, The header is needed because I am using wordpress and running the code as a plugin.
<?php
/*
Plugin Name: FSdota
Description: submit form data into sql database
Author: F. May
Version: 1.0
*/
//inserting data order
$con=mysqli_connect("XXXXXX","XXXXXXXX","XXXXXXXX","XXXXXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysqli_query($con,"XXXXXXXXXX");
$row_data = "($playerid,$firstname, $lastname, $position,$team,$Game)";
if (is_array($row_data));
{
foreach($_POST['playerid'] as $row=>$playerid) {
$playerid = mysqli_real_escape_string('playerid');
$firstname = mysqli_real_escape_string($con,($_POST['firstname'][$row]));
$lastname = mysqli_real_escape_string($con,($_POST['lastname'][$row]));
$position = mysqli_real_escape_string($con,($_POST['position'][$row]));
$team = mysqli_real_escape_string($con,($_POST['team'][$row]));
$game = mysqli_real_escape_string($con,($_POST['game'][$row]));
}
}
if (!empty($row_data)) {
$sql="INSERT INTO wp_es_fstest (PlayerID,FirstName,LastName,Position,Team,Game) VALUES".implode(',', $row_data);
$query = mysqli_query($con, $sql);
if (mysql_query($query))
echo 'Successful inserts: ' . mysql_affected_rows($con);
else
echo 'query failed';
}
?>
You are not sending multiple values for the same fields. Your name attributes are like name="playerid" so that means that every new entry with the same name will overwrite the previous one and only one gets sent to the server.
You should use arrays to group your fields:
<input type="text" name="playerid[SOME_ID]" size="20">
...
<input type="text" name="firstname[SOME_ID]" size="20">
...
// etc.
...
<input type="text" name="playerid[SOME_OTHER_ID]" size="20">
...
<input type="text" name="firstname[SOME_OTHER_ID]" size="20">
...
// etc.
For the SOME_ID, SOME_OTHER_ID, etc. values you could use a value from a database if it already exist or a simple counter, as long as the fields in a group use the same number / ID.
About the php-side, as mentioned by #Fred-ii- you should only use one sql API, in this case mysqli.
Also note that:
$playerid = mysqli_real_escape_string('playerid');
should be:
$playerid = mysqli_real_escape_string($con, 'playerid');
Personally I would also use a prepared statement with bound variables so that you can prepare your statement once and then run it several times with the different groups of values without having to worry about sql injection / escaping the values.
One additional remark:
This is going to fail:
$row_data = "($playerid,$firstname, $lastname, $position,$team,$Game)";
if (is_array($row_data));
{
You have just set your $row_data variable to be a string, probably with a bunch of undefined variables so checking one line after that whether it is an array is never going to work.
Alright so it has been a while since the last point, life got busy and I wanted to do a little more research.
I have modified my form.html to specify that they are arrays and created a new php file to go with it. here is the code below.
<body>
<table border="1">
<tr>
<td align="center">Dota 2 Open Team Registration</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="/wp/wp-content/plugins/FormSubmit/FSdotaArray.php">
<tr>
<td></td>
<td><b>Captain</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[playerid_1]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_1]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_1]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_1]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_1]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_1]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player 2 -->
<td></td>
<td><b>Player 2</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_2]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_2]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_2]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_2]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_2]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_2]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!--Player 3 -->
<td></td>
<td><b>Player 3</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_3]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_3]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_3]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_3]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_3]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_3]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player 4 -->
<td></td>
<td><b>Player 4</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_4]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_4]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_4]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_4]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_4]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_4]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player 5 -->
<td></td>
<td><b>Player 5</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_5]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_5]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_5]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_5]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_5]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_5]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player Sub 1 [6] -->
<td></td>
<td><b>Sub 1 (Optional)</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_6]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_6]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_6]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_6]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_6]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_6]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player Sub 2 [7] -->
<td></td>
<td><b>Sub 2</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_7]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_7]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_7]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_7]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_7]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_7]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
and then the PHP code
<?php
/*
Plugin Name: FSdota
Description: submit form data into sql database
Author: F. May
Version: 1.0
*/
//inserting data order
$con=mysqli_connect("xxxxxxxx","xxxxxxx","xxxxxx!","xxxxx");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
//define values
$player_a = array($playerid_1,$playerid_2,$playerid_3,$playerid_4,$playerid_5,$playerid_6,$playerid_7);
$firstname_a = array($firstname_1,$firstname_2,$firstname_3,$firstname_4,$firstname_5,$firstname_6,$firstname_7);
$lastname_a = array($lastnanme_1,$lastnanme_2,$lastnanme_3,$lastnanme_4,$lastnanme_5,$lastnanme_6,$lastnanme_7);
$position_a = array($position_1,$position_2,$position_3,$position_4,$position_5,$position_6,$position_7);
$team_a = array($team_1,$team_2,$team_3,$team_4,$team_5,$team_6,$team_7);
$game_a = array($game_1,$game_2,$game_3,$game_4,$game_5,$game_6,$game_7);
$playerid = mysqli_real_escape_string($con, '$playerid_a');
$firstname = mysqli_real_escape_string($con, '$firstname_a');
$lastname = mysqli_real_escape_string($con, '$lastname_a');
$position = mysqli_real_escape_string($con,'$position_a');
$team = mysqli_real_escape_string($con, '$team_a');
$game = mysqli_real_escape_string($con, '$game_a');
for ($i = 1; $i < 7; $i++) {
//define arrays into variables with counter
// $a = $playerid_a[$];
// $b = $firstname_a[$i];
// $c = $lastname_a[$i];
// $d = $position_a[$i];
// $e = $team_a[$i];
// $f = $game_a[$i];
$str[ ] = "('{$player_[$i]}','{$firstname_[$i]}','{$lastname_[$i]}','{$position_[$i]}','{$team_[$i]}','{$game_[$i]}')";
}
$s= implode(',', $str);
$sql="INSERT INTO wp_es_fstest (playerid, firstname, lastname, position, team, game) VALUES $s";
echo $sql;
mysqli_close($con);
?>
I dont think I have defined everything correctly, in the echo i am null values.
INSERT INTO wp_es_fstest (playerid, firstname, lastname, position, team, game) VALUES ('','','','','',''),('','','','','',''),('','','','','',''),('','','','','',''),('','','','','',''), ('','','','','','')

display form main page and action page in wordpress for plugin frontend side user

I have created one plugin which inserts vehicles to DB table,displays vehicles at admin side from that table.One page is for settings of that plugin.admin side of plugin is mostly complete.now i want to display a form for taxi booking.when user submit that form in action page, i want to display google map with locations and distance with payment option.i googled it but not found best way.How sholud i create plugin front side?from where should I start?can anyone suggest me?
this is the form that i want to display at front side
<form name="book_form" id="book_form" action="" method="POST">
<!--<input type="hidden" name="action" value="tBM_taxibooking_save_booking" />-->
<table>
<tbody>
<tr>
<th>Select Location Points On Google Map</th>
<td>
<select name="location_points" id="location_points">
<option value="points">Points</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr>
<th>First Address Point</th>
<td><input type="text" name="first_point" id="first_point"></td>
</tr>
<tr>
<th>Second Address Point</th>
<td><input type="text" name="second_point" id="second_point"></td>
</tr>
<tr>
<th>Third Address Point</th>
<td><input type="text" name="third_point" id="third_point"></td>
</tr>
<tr>
<th>Fourth Address Point</th>
<td><input type="text" name="fourth_point" id="fourth_point"></td>
</tr>
<tr>
<th>Adult Seats</th>
<td>
<select name="adult" id="adult">
<option value="Adult Seats">Adult Seats</option>
<?php
$i=1;
for($i=1;$i<=10;$i++)
{ echo'<option value="'.$i.'">'.$i.'</option>'; }
?>
</select>
</td>
</tr>
<tr>
<th>Child Seats</th>
<td>
<select name="child" id="child">
<option value="Child Seats">Child Seats</option>
<?php
$i=1;
for($i=1;$i<=10;$i++)
{ echo'<option value="'.$i.'">'.$i.'</option>'; }
?>
</select>
</td>
</tr>
<tr>
<th>Suitcases</th>
<td>
<select name="suitcases" id="suitcases">
<option value="Suitcases">Suitcases</option>
<?php
$i=1;
for($i=1;$i<=50;$i++)
{ echo'<option value="'.$i.'">'.$i.'</option>'; }
?>
</select>
</td>
</tr>
<tr>
<th>Select Vehicle</th>
<td>
<select name="vehicle" id="vehicle">
<option value="vehicles">Select Vehicle</option>
<?php
while($row=mysql_fetch_assoc($results))
{
echo'<option value="'.$row['vechicle_id'].'">'.$row['vechicle_title'].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th>Date</th>
<td><input type="text" name="date" id="date"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Get Map & Distance" id="submit" name="submit"></td>
</tr>
</tbody>
</table>
</form>

php - drop down from database

Im a newbie ih php.Im trying to show drop down list values from database using this but the data not shown up.There is no error as well. Need some experts advice.
Code
<?php
include('connectdb.php');
$sql="SELECT id,name FROM companydetailstbl";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
//echo $id;
$thing=$row["name"];
$options.="<OPTION VALUE=\"$id\">".$thing;
}
?>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Company Name </td>
<td width="3%">:</td>
<td width="75%"><SELECT NAME="thing">
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT></td>
</tr>
<tr>
<td>Installation Date </td>
<td>:</td>
<td><input type="text" name="ins_dt" />
(ddmmyyyy)</td>
</tr>
<tr>
<td>Expiry Date </td>
<td>:</td>
<td><input type="text" name="ex_dt" />
(ddmmyyyy)</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Update" />
<input type="submit" name="Submit2" value="Reset" /></td>
</tr>
</table>
Please help. Thanks
I don't know what DTD you are currently using, but according to the HTML 4.0 Specification, you need to close your option tag.
$options .= '<option value="' . $id . '">' . $thing . '</option>';
Also there,
<select name="thing">
<option value="0">Choose</option>
<?php echo $options; ?>
</select>
please try to close the tag
$options.="<OPTION VALUE=\"$id\">".$thing."</OPTION>";
also edit
<SELECT NAME="thing">
<OPTION VALUE=0>Choose</OPTION>
<?=$options?>
</SELECT>
<?php
include('connectdb.php');
$sql="SELECT id,name FROM companydetailstbl";
$result=mysql_query($sql);
?>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Company Name </td>
<td width="3%">:</td>
<td width="75%">
<select name="thing">
<?php
while($row = mysql_fetch_object($result)){
?>
<option value="<?=$row["id"]; ?>"><?=$row["name"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Installation Date </td>
<td>:</td>
<td><input type="text" name="ins_dt" />(ddmmyyyy)</td>
</tr>
<tr>
<td>Expiry Date </td>
<td>:</td>
<td><input type="text" name="ex_dt" />(ddmmyyyy)</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="Update" />
<input type="submit" name="Submit2" value="Reset" />
</td>
</tr>
</table>
Hope it helps

two dropdown and checkboxes on same page not working

I have to use same checkboxes and dropdowns according to the if condition ,---->
<div id="5" <? if($long_term_rental!=1) {?> style="display:none" <? } else {?>style="display:block" <? } ?>>
<table width="85%" >
<tr class="td3">
<td>City </td>
<td><select style="width:100px;" name="citylong" size="1" class="textfeild1" id="citylong">
<option <? if($citylong=="None")echo "selected='selected'";?>>None</option>
<option <? if($citylong=="Palm Springs")echo "selected='selected'";?>>Palm Springs</option>
<option <? if($citylong=="Cathedral City")echo "selected='selected'";?>>Cathedral City</option>
<option <? if($citylong=="Rancho Mirage")echo "selected='selected'";?>>Rancho Mirage</option>
<option <? if($citylong=="Palm Desert")echo "selected='selected'";?>>Palm Desert</option>
<option <? if($citylong=="La Quinta")echo "selected='selected'";?>>La Quinta</option>
<option <? if($citylong=="Indian Wells")echo "selected='selected'";?>>Indian Wells</option>
</select></td></tr>
<tr class="td2">
<td align="left">Upper/Lower/Town House/Single Story</td>
<td align="left"><select style="width:100px;" name="floorlong" size="1" class="textfeild1" id="floorlong">
<option <? if($floorlong=="None")echo "selected='selected'";?>>None</option>
<option <? if($floorlong=="Upper")echo "selected='selected'";?>>Upper</option>
<option <? if($floorlong=="Lower")echo "selected='selected'";?>>Lower</option>
<option <? if($floorlong=="TH")echo "selected='selected'";?>>TH</option>
<option <? if($floorlong=="Single Story")echo "selected='selected'";?>>Single Story</option>
</select></td>
</tr>
<tr class="td2">
<td> </td>
<td >Pets Allowed : </td>
<td ><input class="textfeild1" type="checkbox" name="petslong" id="petslong" value="Pets" <? if($petslong==1) echo "checked='checked'";?>/></td>
<td>Pool : </td>
<td><input class="textfeild1" type="checkbox" name="poollong" id="poollong" value="Pool" <? if($poollong==1) echo "checked='checked'";?>/></td>
<td align="right"> </td>
</tr>
<tr class="td2">
<td> </td>
<td>Jacuzzi : </td>
<td><input class="textfeild1" type="checkbox" name="jacuzzilong" id="jacuzzilong" value="Jacuzzi" <? if($jacuzzilong==1) echo "checked='checked'";?>/></td></div>
And on condition false display the below code---->
<div id="mylng" <? if($long_term_rental!=1) {?> style="display:block" <? } else {?>style="display:none" <? } ?>>
<table width="100%" >
<tr class="td3">
<td> </td>
<td>City </td>
<td><select style="width:100px;" name="city" size="1" class="textfeild1" id="city">
<option <? if($city=="None")echo "selected='selected'";?>>None</option>
<option <? if($city=="Palm Springs")echo "selected='selected'";?>>Palm Springs</option>
<option <? if($city=="Cathedral City")echo "selected='selected'";?>>Cathedral City</option>
<option <? if($city=="Rancho Mirage")echo "selected='selected'";?>>Rancho Mirage</option>
<option <? if($city=="Palm Desert")echo "selected='selected'";?>>Palm Desert</option>
<option <? if($city=="La Quinta")echo "selected='selected'";?>>La Quinta</option>
<option <? if($city=="Indian Wells")echo "selected='selected'";?>>Indian Wells</option>
</select></td>
<td align="right" style="width: 223px;">Upper/Lower/Town House/Single Story</td>
<td align="left"><select style="width:100px;" name="floor" size="1" class="textfeild1" id="floor">
<option <? if($floor=="None")echo "selected='selected'";?>>None</option>
<option <? if($floor=="Upper")echo "selected='selected'";?>>Upper</option>
<option <? if($floor=="Lower")echo "selected='selected'";?>>Lower</option>
<option <? if($floor=="TH")echo "selected='selected'";?>>TH</option>
<option <? if($floor=="Single Story")echo "selected='selected'";?>>Single Story</option>
</select></td></tr>
<tr class="td3">
<td> </td>
<td >Pets Allowed : </td>
<td ><input class="textfeild1" type="checkbox" name="pets" id="checkbox9" value="Pets" <? if($pets==1) echo "checked='checked'";?>/></td>
<td>Pool : </td>
<td><input class="textfeild1" type="checkbox" name="pool" id="checkbox8" value="Pool" <? if($pool==1) echo "checked='checked'";?>/></td>
<td align="right"> </td>
</tr>
<tr class="td3">
<td> </td>
<td>Jacuzzi : </td>
<td><input class="textfeild1" type="checkbox" name="jacuzzi" id="checkbox6" value="Jacuzzi" <? if($jacuzzi==1) echo "checked='checked'";?>/></td>
<td> </td>
<td> </td>
</tr>
</table></div>
But the code under <div id="5" is NOT WORKINg and the same code under <div id="mylng" is working PERFECTLY
Please help
at first you did not closed your
/tr
/table
at the end of
div id=5
please send us code with your form tag maybe your fault its on you HTML

Categories