I asked a question on SO a few hours back.
How to insert an Array of field names from a form into SQL database in Codeigniter.
<tr>
<td><input type="text" name="user[0][name]" value=""></td>
<td><input type="text" name="user[0][address]" value=""><br></td>
<td><input type="text" name="user[0][age]" value=""></td>
<td><input type="text" name="user[0][email]" value=""></td>
<tr>
<td><input type="text" name="user[1][name]" value=""></td>
<td><input type="text" name="user[1][address]" value=""><br></td>
<td><input type="text" name="user[1][age]" value=""></td>
<td><input type="text" name="user[1][email]" value=""></td>
</tr>
..........//so on
This is the best answer I got
foreach($_POST['user'] as $user)
{
$this->db->insert('mytable', $user);
}
Now I want to pass a id generated from user session data into this array + a few other values like current time
Is it possible to tweak the above solution?
The Previous Discussion Here
foreach($_POST['user'] as &$user)
{
$user['additional_data'] = $_SESSION['additional_data'];
$user['current_time'] = time();
$this->db->insert('mytable', $user);
}
Note the & in &$user which is a pass by reference which allows manipulation of an array within a foreach loop. If you reference user later remember to unset($user) to remove the reference to the last element of the $_POST['user'] array.
I don't know if I'm missing something here, but can't you just remove the foreach and build your code like this:
$var1 = $_POST['user_var1'] * 3 + 1 / 5;
$this->db->insert('mytable', $var1);
$var2 = gettime();
$this->db->insert('mytable', $var2);
....
(where gettime() should be replace with whatever the PHP command for getting time is, plus maybe a formatting function)
Related
error:-The specified value "NaN" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?
when i place the values in input values the in quantity and in rate, then expected result of input likes should be 4*5 = 20 but it doesn't do so instead 4*5a where a is the variable where any value of integer is placed then it only gives the expected result 20
<table>
<tr v-for="(pro,index,k) in pr`enter code here`oduct" :key="k">
<td>{{index+1}}</td>
<td><input type="number" v-model="pro.qnt" #keypress="calculatetotal(index)" style="width:110px;"></td>
<td><input type="number" v-model="pro.rate" #keypress="calculatetotal(index)" style="width:110px;"></td>
<input type="number" v-model="pro.totalamount" class="form-control"></td>
<td><input type="number" v-model="pro.Amount" style="width:110px;" #keypress="discountamount(index)"></td>
<td><input type="number" v-model="pro.discount" style="width:110px;" #keypress="discountamount(index)" :disabled = "selected===1"></td>
<td><input type="number" v-model="pro.totalamount" class="form-control"></td>
</table>
methods:{
calculatetotal: function(index)
{
var total;
total=this.product[index].qnt * this.product[index].rate;
this.product[index].Amount=total
},
discountamount: function(index)
{
//check whether the discoun is disabled or not
if( this.selected===1)
{
this.product[index].totalamount=this.product[index].Amount
}
else{
var dsa;
dsa=this.product[index].Amount - this.product[index].discount;
this.product[index].totalamount = dsa
}
}
}
the output should be 2*4=8 but it gives 2*4=0 and gives correct answer when 2*4a where a is integer varaible then only gives expected result 8
If you take a look at this answer : https://stackoverflow.com/a/3396805/5543999
You will see that with the event on key press, the input is not already altered.
Change your #keypress for #keyup and everything should work properly.
I have 3 checkboxes with ID as id1,id2,id3 and name as name1,name2,name3.
<table id="ContentPlaceHolder1_cblType">
<tbody>
<tr>
<td>
<input id="ContentPlaceHolder1_cblType_0" type="checkbox"
name="ctl00$ContentPlaceHolder1$cblType$0" value="Clinician">
<label for="ContentPlaceHolder1_cblType_0">Clinician</label>
</td>
<td>
<input id="ContentPlaceHolder1_cblType_1" type="checkbox"
name="ctl00$ContentPlaceHolder1$cblType$1" value="Administration">
<label for="ContentPlaceHolder1_cblType_1">Administration</label>
</td>
<td>
<input id="ContentPlaceHolder1_cblType_2" type="checkbox"
name="ctl00$ContentPlaceHolder1$cblType$2" value="Therapist">
<label for="ContentPlaceHolder1_cblType_2">Therapist</label>
</td>
</tr>
</tbody>
</table>
I need to check it upon the value retrieving from excel.
data.getEmpType().get(rowCnt)
With above code I will get the value from excel.
How to do it?
First take string value from excel sheet.
Then collect all or required check boxes.
Loop the check boxes and verify against required value which collected from excel.
String requiredValue= "from excel file";
List<WebElement> checkBoxes=oWebDriver
.findElements(By.cssSelector("input[id^='ContentPlaceHolder1'][type='checkbox']"));
for (int i = 0; i < checkBoxes.size(); i++) {
if(checkBoxes.get(i).getAttribute("value").equals(requiredValue)){
checkBoxes.get(i).click();
break;
}
}
Or use more straight way through Xpath:
String excelValue = "from excel file";
String xpathExp = String.format(
"//table[#id='ContentPlaceHolder1_cblType']" +
"//td[label[text()='%s']]/input", excelValue );
driver.findElement(By.xpath(xpathExp)).click();
String ExcelValue= "data from excel";
**/*Create a list using common attributes of all three check boxes */**
List< WebElement> CB=driver.findElements(By.xpath("\\input[starts-with(#id,'ContentPlaceHolder1') AND #type='checkbox']"));
**/*Store size of List created in CB_size(as per your data is should be three */**
int CB_size=CB.size();
**/*below loop will execute for all three check boxes one by one and with which so ever your value from excel matches, it click and come out of the loop */**
for (int i = 0; i < CB_size; i++)
{
if(CB.get(i).getAttribute("value").equals(ExcelValue))
{
CB.get(i).click();
break;
}
}
Here is my code and output i was unable to create the different row for my each line using perl?
Here is my code:
use strict;
use warnings;
use CGI;
open(my $file1,"as.txt");
my $firstline=<$file1>;
$firstline=~s/.*=//g;
my #words=split /,/,$firstline;
my $finalline=join("\n",#words);
close $file1;
print "Content-type:text/html\n\n"
print<<"EOF";
<html><body>
<table style="width:100%">
<tr>
<th>UserName</th>
<th>Access</th>
</tr>
<tr>
<td>$finalline</td>
<td>
<input type="checkbox" value="check2" mulitple checked>Read
<input type="checkbox" value="check2" mulitple>Write
<input type="checkbox" value="check2" mulitple>Owner
</td>
</tr>
</table></body></html>
EOF
MY OUTPUT FOR PERL (I.E $finalline)
sankar
morien3
i got the following table as my output in table format:
UserName Access
sankar morien3 Read Write Owner
Expected output:
UserName Access
sankar Read Write Owner
morien3 Read Write Owner
Input file:(i.e as.txt)
cskTeam = sankar, mobrien3
[csk:/]
* = r
#cskTeam = rw
You must know about how HTML layout will work.
Even your code won't give your expected result in terminal.
In html \n not make sense, <br> it is for new line in html. But this logic also won't work in your code.
You are joining the array with \n, then printing the data it will execute the comment line by line what you have mentioned.
First you have printing the $finalline variable so it result is
sankar \n morien3
\n will not consider in html. Storing in one cell as per <td>
Then you are creating the another cell which holds the permission detail.
Finally your code should be as follows.
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
print "Content-Type: text/html \n\n";
open my $file1,"<","as.txt";
my $firstline=<$file1>;
$firstline=~s/.*=//g;
my #words=split /,/,$firstline;
close $file1;
print<<"EOF";
<html><body>
<table style="width:50%; ">
<tr>
<th style="text-align:left">UserName</th>
<th style="text-align:left">Access</th>
</tr>
EOF
foreach (#words)
{
print <<EOF;
<tr>
<td>$_</td>
<td>
<input type="checkbox" value="check2" mulitple checked>Read
<input type="checkbox" value="check2" mulitple>Write
<input type="checkbox" value="check2" mulitple>Owner
</td>
</tr>
EOF
}
print <<EOF;
</table></body></html>
EOF
Below is my code:
#{
Layout = "/_SiteLayout.cshtml";
var db = Database.Open("MyDatabase");
var query = "SELECT * FROM Team";
var Teams = db.Query(query);
}
<form>
<table>
<tr>
<td>Team Name</td>
<td>Played</td>
<td>Points</td>
</tr>
#{ foreach(var Team in Teams){
<tr>
<td>#Team.TeamName</td>
<td><input type="text" value="#Team.Played" name="Played"/></td>
<td><input type="text" value="#Team.Points" name="Points"/></td>
</tr>
}
}
</table>
</form>
This is the result:
So what I want to do is update my whole table.
What is the SQL query to do this? I want to update Points and Games Played in my database for all teams once the form is posted.
I don't actually understand what exactly you are trying to achieve (update your whole table with what?), but here is some information you might find useful:
SQL Update Tutorial, SQL Update, Update from Select
Following is My Solution. Anyone have an efficient Solution?
#{
var db = Database.Open("MYDATABSE");
var query = "SELECT * FROM Team";
var Teams = db.Query(query);
var InsertQuery = "";
if(IsPost){
foreach(var Team in Teams){
var Points = Request[Team.TeamName];
var TeamId = Team.TeamId.ToString();
var Played = Request[TeamId];
var executeQueryString="UPDATE Team Set Points=#0, Played=#1 WHERE TeamId=#2";
db.Execute(executeQueryString, Points, Played, Team.TeamId);
}
Response.Redirect("~/UpdateTable.cshtml");
}
}
<br /><br />
<form action="" method="post">
<table>
<tr>
<td><h5>Team Name</h5></td>
<td><h5>Played</h5></td>
<td><h5>Points</h5></td>
</tr>
#{ foreach(var Team in Teams){
<tr>
<td>#Team.TeamName</td>
<td><input type="text" value="#Team.Played" name="#Team.TeamId"/></td>
<td><input type="text" value="#Team.Points" name="#Team.TeamName"/></td>
</tr>
}
}
I'm fetching records from the SQL Server 2000 database using Classic ASP. This is what the code I have used.
ASP Code:
<form name="search" method="post" onsubmit="return attention();">
<table width="60%" border="0" cellpadding="2" cellspacing="0" style="margin:0 auto">
<tr>
<td colspan="2"><h1 style="color:#003399;">Search for Certificate of Analysis</h1></td>
</tr>
<tr>
<td valign="bottom">Product number <sup style="color:#EE0000;font-size:1.3em">*</sup></td>
<td valign="bottom">Lot number</td>
</tr>
<tr>
<td width="30%" valign="top">
<input type="text" name="input1" size="20"/>
</td>
<td valign="top">
<input type="text" size="20" name="input2"/>
<input style="background-color:#ffffff;border:0px;cursor:pointer" size="10" type="submit" name="sub" value=">>" />
</td>
</tr>
</table>
<%
if request.Form("sub") <> "" then
Dim fname, lname
fname= request.Form("input1")
lname= request.Form("input2")
session("n") = fname & lname
sql = "Select * from search where cat_no_batch_no LIKE '"&request.Form("input1")&"%' OR cat_no_batch_no='"&session("n")&"'"
rs.open sql, con, 1, 2
if rs.eof then
response.write("Please provide a valid Cat No.")
else
do while not rs.eof
%>
<table border="1" cellpadding="5" cellspacing="0" width="60%" style="margin:0 auto; border-collapse:collapse;border-color:#999999">
<tr>
<td width="50%"><%=rs("cat_no_batch_no")%></td>
<td width="10%">Click to open <a target="_blank" href="http://localhost/search1/<%=rs("pdf_path")%>"><%=rs("cat_no_batch_no")%></a></td>
</tr>
</table>
<%
rs.movenext
loop
end if
rs.close
end if
%>
</form>
Above the LIKE statement works as expected and displays multiple records which contains similar Cat No..
Issue rises when I input a Cat No in first Input box and Lot Number in another. My desired output should have been just a single record to display as I have given Cat No. and Lot Number , but it shows multiple records.
I have provided the images to be more clear.
In this image below I have put 6106021 as the product number so it displays two entries.
In this image I have put 6106021 as the product number and 218111 as the Lot Number, it shows two entries instead of 1. This is what the issue, it should show one entry as Lot number are unique while cat number can be the same.
Read your question to yourself and think about what you are saying:
You state "My desired output should have been just a single record to display as I have given Cat No. and Lot Number"
But in your SQL you write where cat_no_batch_no LIKE '"&request.Form("input1")&"%' OR cat_no_batch_no='"&session("n")&"'
The key words are AND vs. OR
In your mind you are thinking both conditions must be true, but your query says otherwise. If you want both conditions to be true then you must use the AND operator.
Naoki is on to something - you are going to have to modify your SQL depending upon which criteria are specified.
I guess you can write two separate SQL queries, according as the "Lot number" is provided or not.
Your code may goes like below:
if lname = "" then
sql = "Select * from search where cat_no_batch_no LIKE '"&request.Form("input1")&"%'"
else
sql = "Select * from search where cat_no_batch_no LIKE '"&session("n")&"%'"
end if
I hope this could help