How to insert value to muliple column from textarea use PHP? - sql

I want to insert value to multiple database from Textarea, example i enter value to textarea and submit :
1|Vo Huu Nhan 1
2|Vo huu Nhan 2
3|Vo Huu Nhan 3
After submit i want insert value before "|" to column tap and value after "|" to column player
My code :
<form action="Post.php" method="POST">
<textarea name="tapphim"></textarea>
<input type="submit" value="submit"/></form>
Please help me create Post.php file right way

Firstly which programming language are you using?
For all programming languages, the concept is similar.
Take the input text from the textarea , then explode the '|' out of it ....then it becomes an array .
After that insert the first value of the array into the tap column then the other one into the players column.
The expression might look like this:
array[0] into tap column,
array[1] into players column
But i will like to know the programming language you want to use in achieving this
I hope it enlightens you.
Since you are using php
`if(isset($_POST['tapphim']) && !empty($_POST['tapphim'])
{
$textAreaInput = explode("|", $_POST['tapphim']);
$tapValue = $textAreaInput[0];
$playerName = $textAreaInput[1];
$sql = mysqli_query($con,"insert into
playersTble(tap,players)
values('$textAreaInput','$playerName");
if($sql){
echo "data saved!";
}
}`
i Hope this solves your problem.
Make sure you read about sanitizing input in PHP

Try this,
if(isset($_POST['tapphim'])){
$lineSplit=explode("\n", $_POST['tapphim']);
foreach ($lineSplit as $line) {
$splitArr=explode("|", $line);
$fieldOne=$splitArr[0];
$fieldTwo=$splitArr[1];
// insert to db
}
}
You may want to use htmlspecialchars($_POST['tapphim']) or mysql_real_escape_string($_POST['tapphim']) to clear post variables from dangerous characters for security reasons especially if you don't use PDO connection to connect your database.

Related

simplecart js setting column widths

I've used this site for assistance many times but never had to ask a question so finally joined...anyway, trying to set up simplecart checkout and having some trouble formatting cart output. I have my cart set to table and by default the simpleCart_items class displays the table and it's cells only as wide as they need be to fit the data. I can change this by specifying all cells(columns) as a percentage of the whole table. Unfortunately with 7 columns each only gets about 14% and this is way to much for a 1 or 2 digit quantity and not near big enough for all the characters in the item name without wrapping. What I want is a way to define a different width for each column. I have not found a way to do this even with colgroup but maybe just not doing it right. Any and all help would be appreciated!
Okay, so this may or may not help. This line is located in the simpleCart.js file. I changed it to something simple.
cartColumns : [
{ view: function(item, column){
return"<img src='"+item.get('image')+"' width='250px' height='250px'><br /><center><h3 ><span>"+item.get('name')+"</span></h3><p><a href='javascript:;' class='simpleCart_decrement'><button>-</button></a> "+item.get('quantity')+" <a href='javascript:;' class='simpleCart_increment'><button>+</button></a></p><p>$"+item.get('price')+"</p><p><a href='javascript:;' class='simpleCart_remove remove_icon'><img src='images/icon_x.png' /></a></p></center>";
},
}
],
You can change it to your own html
cartColumns : [
{ view: function(item, column){
return" YOUR HTML HERE ";
},
}
],
It MUST all be in ONE (1) LINE or else it may not work.
here are some values that are used
image = item.get('image')
name = item.get('name')
quantity = item.get('quantity')
price = item.get('price')
you can look at all the values here
http://simplecartjs.org/documentation/displaying_cart_data
but the point is that you can make a cart and display it how you want; with you own html and css. I hope this helped.

Possibly missing something very simple in this PHP foreach loop

This question is an extension for this question.
Basically the script compares two arrays and outputs the difference (what to show to the user).
$urlsToShow = array_diff($siteUrls, $seenUrls);
if (!empty($urlsToShow)) {
// Echo the url to show for the iframe within browse.php and add an entry to the database that the user has seen this site
foreach ($urlsToShow as $urlToShow) {
echo $urlToShow;
$entry = "INSERT INTO views VALUES ('', '$currentUsername', '$urlToShow')";
mysqli_query($con, $entry);
break;
}
}
The problem is that I get two entries into the database with one iteration? The first site from the $urlsToShow array is displayed (echoed into the iframe) and gets added to the database along with the next site from the same array. But the user will never see the next site.
Am I using break incorrectly?
It is possible that using break; will not be in your best interest. I suggest using continue;.

can there be a tooltip with data from the database

I need to know can there be a tooltip populated with data from database to be displayed in the tooltip.
something like the tooltip should contain
name stauts
abc active
xyz active
pqr active
name and status are retrived from db
I need this tooltip onmouseover, am using CJSON decoded to render the content
i did go google but hardly did find that i would throughly understand and implement.
can anyone out there has any ideas for what am looking.
There is a extension named yii-bootstrap, which described clearly here.
For using tooltip easily in this extension, just look here.
I use cluetip for this. Its not related to Yii but will give you some idea :
JS
function renderInfoTips(opts){
var elements=$('#'+opts.form).get(0).elements;
for(i=0; i<opts.tips.length;i++){
$(elements[opts.tips[i].field]).parent().prepend(opts.tips[i].tip);
}
var clue_opts={arrows:true,splitTitle: '|',closePosition: 'title',sticky:true,dropShadow:false,mouseOutClose:true,
onShow:function(ct, ci){
if(!$.browser.webkit) $(ct).css('top',$(ct).position().top- 30+'px');
}
}
$('#'+opts.form).find(".infotip").cluetip(clue_opts);
}
PHP
function setInfoTipsJavascript($form_id,infotips){
if (count($this->infotips) <1 ) return '';
//get all tip names
$names_csv=join(',',array_keys(infotips));
//get tips details from db
$query="select name, description from infotips where FIND_IN_SET(name ,'$names_csv')";
//run the query, in Yii you have to use InfoTipsModel , I have skipped that portion
//$infotipS , lets say this is query object
$tips=array();
while($tip=$infotipS->Assoc()){
$this->infotips[$tip['name']]['tip']="<a href='javascript:void(0)' class='infotip' title='|{$tip['description']}'> </a>";
$tips[]=$this->infotips[$tip['name']];
}
$tips=json_encode($tips);
$script="\nrenderInfoTips({\"form\":'{$form_id}', \"tips\":{$tips}});\n\n";
echo $script;
}
I am sharing this hoping this will give u some idea. Its obvious you have to : create infotips table, a model for that, and create a widget etc to fetch infotips related to your form fields . As someone suggested, if you are using Bootstrap, you have better way to do that.

In yii how to access other tables fields

I am creating project in yii framework. I am having table as-
Qbquestion QbquestionOption
-questionId -optionId
-question -questionId
-userId -option
-isPublished -isAnswer
In QbquestionOption controller i want to access Qbquestion tables fields. I had written quesry as-
$Question=Qbquestion::model()->findAllByAttributes(array("questionId"=>$number));
where $number is some random number.
When i am using its fields as= $Question->isPublished then its giving error as "trying to get access to property of non-object"
Statement var_dump($Question) is showing all record and all values of Qbquestion table. So how can i access records?
Please help me
$Question is an array of models you cannot call model function on that..
what you can do is:
$questions = Qbquestion::model()->findAllByAttributes(array("questionId"=>$number));
foreach($questions as $question)
$question->isPublished()
or you can use findByAttribute to get single result..
findAllByAttributes returns an array of objects.
If you just want one question, use findByAttributes instead, then it should work as you want.
Try As I don't know your relation n all. Just give a try. I'll post other answers if it don't works. Also tel me in which table isPublished field is? If it in other table as your title mentioned you need to change it as echo $qRec->OtherTableRelationArrayKey->isPublished;
foreach($Question AS $qRec)
{
echo $qRec->isPublished;
echo "<br />";
}

LINQ - SQL Display data in html table

I would like to perform a select statement using a DataContext from the code behind page and then display the results in an HTML table.
Best ways to do this?
The best way to do this as always depends. One of the fastest and easiest way would be to directly bind the data to a DataGrid.
If you really need to create html table you can use a literal in frontend and add the literal text from back end
eg <asp:Literal ID="ltrUser" runat="server"></asp:Literal>
In backend code
if (!IsPostBack)
{
var data = datasource;
ltrUser.Text = "<table><tr><td>";
ltrUser.Text += "<h1>"+ data.name + "</h1>";
ltrUser.Text += "</td></tr></table>";
}