<!doctype html>
<html>
<title>Search</title>
<script type="text/javascript">
function query() {
var adVarWChar = 202;
var adParamInput = 1;
var pad = "C:\\Users\\azi!z\\Desktop\\Project\\Test.accdb";
var cn = new ActiveXObject("ADODB.Connection");
var strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pad;
cn.Open(strConn);
var cm = new ActiveXObject("ADODB.Command");
cm.ActiveConnection = cn;
cm.CommandText = "SELECT * FROM ImportFromExcel WHERE Module LIKE ? OR TestCase LIKE ? OR Openedby LIKE ? OR Status LIKE ?";
//cm.CommandText = "SELECT * FROM ImportFromExcel where TestCase LIKE ?";
cm.Parameters.Append(cm.CreateParameter(
"?",
adVarWChar,
adParamInput,
255,
"%" + document.getElementById("searchTerm").value + "%"));
var rs = cm.Execute(); // returns ADODB.Recordset object
if (rs.EOF) {
document.write("<p>No data found.</p>");
} else {
while (!rs.EOF) {
document.write("<p>" + rs.fields(0).value + ", ");
document.write(rs.fields(1).value + ", ");
document.write(rs.fields(2).value + ", ");
document.write(rs.fields(3).value + ", ");
document.write(rs.fields(4).value + ", ");
document.write(rs.fields(5).value + ", ");
document.write(rs.fields(6).value + ", ");
document.write(rs.fields(7).value + ", ");
document.write(rs.fields(8).value + ", ");
document.write(rs.fields(9).value + ", ");
document.write(rs.fields(10).value + ", ");
document.write(rs.fields(11).value + ", ");
document.write(rs.fields(12).value + ", ");
document.write(rs.fields(13).value + ", ");
document.write(rs.fields(14).value + ", ");
document.write(rs.fields(15).value + ".</p>");
var row = row.parentNode.rows[ ++idx ];
document.write(rs.fields(1).value + ".</p>");
rs.MoveNext();
}
}
rs.Close();
cn.Close();
}
</script>
</head>
<body>
<form method="get" name="SearchEngine" target="_blank">
<p style="text-align: center;"><span style="font-family:times new roman,times,serif;"><span style="font-size: 36px;"><strong>EA Search Engine</strong></span></span></p>
<p style="text-align: center;"> </p>
<p style="text-align: center;"><input maxlength="300" id="searchTerm" name="KeywordSearch" size="100" type="text" value="Enter Your Keyword Here" /></p>
<p style="text-align: center;"> </p>
<p style="text-align: center;"><input name="Search" type="button" value="Search" onclick="query();" /></p>
</form>
</body>
</html>
Please help me modify the SELECT statement in such a way that it covers the entire table (Not just the "TestCase" column) for ?.
Tried with changing the SELECT query to "SELECT * FROM ImportFromExcel WHERE col1 LIKE ? OR col2 LIKE ? OR col3 LIKE ?; ...", but it's not working.
If you want to search string in all columns of your table
you can concatenate all columns values and search value in the new column. For example
SELECT * FROM ImportFromExcel
WHERE Module
& column1
& column2
& column3 like '*substring*'
Related
I am creating a JavaScript hangman game and am having trouble figuring out how I would prompt the user to guess the letters of the hangman puzzle, and then update the page with .innerHTML the guessed letter in place of the dashes I have on the screen.
I have a while loop set up to prompt for the guesses and do the work of placing the letters that are guessed in the length of the word, but it will prompt continually until more than 10 guesses are made and than print the dashes to screen.
This is the code that I am currently using.
function myGame()
{
var player_name = document.getElementById("player");
document.getElementById("user_name").innerHTML = "Welcome " + player_name.value + " to Wheel of Fortune";
var count = 0;
var phrase = "parseint";
var lgth = phrase.length; var checkWin = false; var correct_guess = false; var guess;
var numCols = lgth; new_word = ""; var crazyWord = ""; var new_word = ""; crzLgth = crazyWord.length;
for (var cols = 0; cols < numCols; cols++)
document.getElementById('wheel_game' + cols).innerHTML = ("/ ");
document.getElementById('hWord').innerHTML = "The word was " + (phrase);
while (checkWin === false && count < 10)
{
correct_guess = false;
guess = prompt("Guess a letter");
for (var j = 0; j < lgth; j++)
{
if (guess === phrase.charAt(j))
{
correct_guess = true;
count = count + 1;
document.getElementById('wheel_game' + j).innerHTML = guess;
for (var nw = 0; nw < lgth; nw++)
crazyWord = crazyWord + (document.getElementById('wheel_game' + nw).innerHTML);
}
new_word = crazyWord.substr((crzLgth - lgth), lgth);
checkWin = checkWord(phrase, new_word);
}
if (checkWin === true)
{
document.getElementById("result").innerHTML = ("You win!");
}
else if (checkWin === false)
{
document.getElementById("result").innerHTML = ("You Lose");
if (correct_guess === false)
count = count + 1;
if (count === 10)
{
guess = prompt("One last chance to guess the word");
}
if(guess.length !== 1 && guess !== "parseint") {
break;
}
else if(guess === 'parseint' && guess.length === 8) {
checkWin = true;
document.getElementById("result").innerHTML = ("You win!");
}
}
}
function checkWord(phrase, otherWord)
{
var cleanWord;
cleanWord = otherWord;
if (phrase === cleanWord)
return true;
else
return false;
}
}
Here is my HTML
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Hangman">
<title>Hangman</title>
</head>
<body>
<h1>Welcome player</h1>
<p> Please Enter your name. </p>
<input type="text" id="player" onchange="myGame();" />
<p id="user_name"> </p> <br>
<div id="wheel_game0"></div> <br>
<div id="wheel_game1"></div> <br>
<div id="wheel_game2"></div> <br>
<div id="wheel_game3"></div> <br>
<div id="wheel_game4"></div> <br>
<div id="wheel_game5"></div> <br>
<div id="wheel_game6"></div> <br>
<div id="wheel_game7"></div> <br>
<div id="wheel_game8"></div> <br>
<div id="wheel_game9"></div> <br>
<div id="hWord"><p></p></div>
<div id="result"><p></p></div>
<script src="myScript_2.js"></script>
</body>
</html>
I tried using a continue statement because I thought that it would skip the iteration of the loop which would keep guessing but unfortunately that did not work. I essentially need the program to prompt the user to guess a letter and than display the letter in place of a dash but for every guess.
Any help would be appreciated.
I have the following script that i use to update multiple rows from the SQL table ''account''.
In the table ''account'' I have column named category, the cat_ID form table ''categories'' is inserted as value in the table ''accounts'' in the column category.
I now have those values hard coded and i want them to be selectable as dropdown list from the table categories, cat_ID as value and cat_name as name of the category. I have tried a lot, googled a lot, but i cant get this to work.
All i want is to have the options fetched from the SQL table categories and use them as dropdown select option in the update option of the script, which are now hard coded now and is working fine.
The hard coded part:
html += '<td class=\"footer\"><select name="category[]" id="category_'+$(this).attr('id')+'" class="editbox"><option value="4">Moet gerankt worden</option><option value="6">Wordt gerankt</option><option value="5">Current BF Holder</option><option value="7">Main Account</option><option value="8">Money Private</option><option value="11">CB/Suc</option><option value="13">Casino Holder</option><option value="15">Wordt Gestockt</option><option value="10">Dont use, ask first!</option><option value="14">Stockgeld</option><option value="0"></option></select></td>';
The SQL select call:
$query = "SELECT a.*, c.cat_color, c.cat_name, c.cat_txt FROM account a LEFT JOIN categories c ON c.cat_ID = a.category WHERE `betaald` = 'Yes' AND `secret` = 'No'";
$statement = $connect->prepare($query);
if($statement->execute())
{
while($row = $statement->fetch(PDO::FETCH_ASSOC))
{
$data[] = $row;
}
echo json_encode($data);
}
The whole script.
<script>
$(document).ready(function(){
$(document).on('click', '.loginBtn', function(e) {
e.preventDefault();
var row = $(this).closest('tr');
var tds = row.find('td');
var name = ''
var cnt = 0;
$.each(tds, function() {
if(cnt == 1) {
name = $(this).text();
return false;
}
cnt++;
});
$.ajax({
url:"select_login_update.php",
method:"POST",
data: {name: name},
dataType: 'JSON',
success:function(data)
{
if(data !== '') {
var email = data[0].email;
var pword = data[0].password
var frm = document.createElement('form');
frm.setAttribute('action', 'http://login.php');
frm.setAttribute('method', 'post');
frm.setAttribute('target', 'view');
var frmEmail = document.createElement('input');
frmEmail.setAttribute('type', 'hidden');
frmEmail.setAttribute('name', 'email');
frmEmail.setAttribute('value', email);
var frmPass = document.createElement('input');
frmPass.setAttribute('type', 'hidden');
frmPass.setAttribute('name', 'password');
frmPass.setAttribute('value', pword);
frm.appendChild(frmEmail)
frm.appendChild(frmPass)
document.body.appendChild(frm);
window.open('', 'view');
frm.submit();
} else {
console.log('empty data');
}
},
error:function(xhr, status, err)
{
console.log('select_login_update.php error ' + err);
}
});
});
function fetch_data()
{
$.ajax({
url:"select_update_all.php",
method:"POST",
dataType:"json",
success:function(data)
{
var html = '';
for(var count = 0; count < data.length; count++)
{var purpose = data[count].purpose;
if(purpose == "BFH") purpose = "Holders";
else if(purpose == "CAS") purpose = "Ranking";
else if(purpose == "PWA") purpose = "Money Rankers";
else if(purpose == "Crew") purpose = "PW Accounts";
else if(purpose == "Crew2") purpose = "The Colombo Family";
else if(purpose == "Crew3") purpose = "Hassinions";
else if(purpose == "aa") purpose = "Admin Account";
else if(purpose == "slist") purpose = "Stocklist";
else if(purpose == "Eragon") purpose = "Eragon";
else if(purpose == "NP") purpose = "Non Paying";
else if(purpose == "DA") purpose = "Deadly Alliance";
html += '<tr >';
html += '<td class=\"footer\"><input type="checkbox" id="'+data[count].id+'" data-name="'+data[count].name+'" data-bullets="'+data[count].bullets+'" data-rang="'+data[count].rang+'" data-category="'+data[count].category+'" data-door="'+data[count].door+'" data-ranker="'+data[count].ranker+'" data-purpose="'+data[count].purpose+'" data-notes="'+data[count].notes+'" class="check_box" /></td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+data[count].name+'</td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+data[count].bullets+'</td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+data[count].rang+'</td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+data[count].ranker+'</td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+data[count].cat_name+'</td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+purpose+'</td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+data[count].notes+'</td>';
html += '<td style="color:'+data[count]['cat_color']+' " class=\"footer\">'+data[count].door+'</td>';
html += '<td class=\"footer\"><button type="button" class="loginBtn" >Login</button></td></tr>';
}
$('tbody').html(html);
}
});
}
fetch_data();
$(document).on('change', '.check_box', function(){
var html = '';
if(this.checked)
{
html = '<td class=\"footer\"><input type="checkbox" id="'+$(this).attr('id')+'" data-name="'+$(this).data('name')+'" data-bullets="'+$(this).data('bullets')+'" data-rang="'+$(this).data('rang')+'" data-category="'+$(this).data('category')+'" data-door="'+$(this).data('door')+'" data-ranker="'+$(this).data('ranker')+'" data-purpose="'+$(this).data('purpose')+'" data-notes="'+$(this).data('notes')+'" class="check_box" checked /></td>';
html += '<td class=\"footer\"><input type="text" name="name[]" class="editbox" value="'+$(this).data("name")+'" /></td>';
html += '<td class=\"footer\"><input type="number" onClick="this.select()" style="width:58px !important;" name="bullets[]" class="editbox" value="'+$(this).data("bullets")+'" /></td>';
html += '<td class=\"footer\"><select name="rang[]" id="rang_'+$(this).attr('id')+'" class="editbox"><option value="Bacteria">Bacteria</option><option value="Low Life">Low Life</option><option value="Apprentice">Apprentice</option><option value="Hitman">Hitman</option><option value="Assassin">Assassin</option><option value="Local Boss">Local Boss</option><option value="Boss">Boss</option><option value="Godfather">Godfather</option></select></td>';
html += '<td class=\"footer\"><input type="text" name="ranker[]" class="editbox" value="'+$(this).data("ranker")+'" /></td>';
html += '<td class=\"footer\"><select name="category[]" id="category_'+$(this).attr('id')+'" class="editbox"><option value="4">Moet gerankt worden</option><option value="6">Wordt gerankt</option><option value="5">Current BF Holder</option><option value="7">Main Account</option><option value="8">Money Private</option><option value="11">CB/Suc</option><option value="13">Casino Holder</option><option value="15">Wordt Gestockt</option><option value="10">Dont use, ask first!</option><option value="14">Stockgeld</option><option value="0"></option></select></td>';
html += '<td class=\"footer\"><select name="purpose[]" id="purpose_'+$(this).attr('id')+'" class="editbox"><option value="">-- No Type --</option><option value="Killer">Killers</option><option value="BFH">Holders</option><option value="CAS">Ranking</option><option value="PWA">Money Rankers</option><option value="Crew">PW Accounts</option><option value="Crew2">The Colombo Family</option><option value="Deadly Alliance">Deadly Alliance</option><option value="Crew3">Hassinions</option><option value="aa">Admin Account</option><option value="NP">Non Paying</option><option value="Eragon">Eragon</option><option value="slist">Stocklist</option></select></td>';
html += '<td class=\"footer\"><input type="text" name="notes[]" class="editbox" value="'+$(this).data("notes")+'" /></td>';
html += '<td class=\"footer\"><input disabled="" style="width:50px !important;" name="door[]" class="editbox" value="'+$(this).data("door")+'" /><input type="hidden" name="hidden_id[]" value="'+$(this).attr('id')+'" /></td>';
html += '<td class=\"footer\"><input type="submit" name="multipleupdatedata2allacc" id="multipleupdatedata2allacc" class="submit" value="Update" /></td>';
}
else
{
html = '<td class=\"footer\"><input type="checkbox" id="'+$(this).attr('id')+'" data-name="'+$(this).data('name')+'" data-bullets="'+$(this).data('bullets')+'" data-rang="'+$(this).data('rang')+'" data-category="'+$(this).data('category')+'" data-door="'+$(this).data('door')+'" data-ranker="'+$(this).data('ranker')+'" data-purpose="'+$(this).data('purpose')+'" data-notes="'+$(this).data('notes')+'" class="check_box" /></td>';
html += '<td class=\"footer\">'+$(this).data('name')+'</td>';
html += '<td class=\"footer\">'+$(this).data('bullets')+'</td>';
html += '<td class=\"footer\">'+$(this).data('rang')+'</td>';
html += '<td class=\"footer\">'+$(this).data('ranker')+'</td>';
html += '<td class=\"footer\">'+$(this).data('category')+'</td>';
html += '<td class=\"footer\">'+$(this).data('purpose')+'</td>';
html += '<td class=\"footer\">'+$(this).data('notes')+'</td>';
html += '<td class=\"footer\">'+$(this).data('door')+'</td>';
html += '<td class=\"footer\"><button type="button" class="loginBtn">Login</button></td></tr>';
}
$(this).closest('tr').html(html);
$('#rang_'+$(this).attr('id')+'').val($(this).data('rang'));
$('#category_'+$(this).attr('id')+'').val($(this).data('category'));
$('#purpose_'+$(this).attr('id')+'').val($(this).data('purpose'));
});
$('#update_form').on('submit', function(event){
event.preventDefault();
if($('.check_box:checked').length > 0)
{
$.ajax({
url:"update_multiple.php",
method:"POST",
data:$(this).serialize(),
success:function()
{
alert('Data Updated');
fetch_data();
}
})
}
});
});
</script>
Well, it is somewhat easy, and believe it or not, even easier for what you need. So, based on what you have, you really only need a string of <option> tags for the <select>, which only needs to be fetched once for reference. The tougher part is usually making the new handling work with code that already exists, if possible, without having to refactor.
Try the things below, I've added another ajax to pre-fetch the category options after the document is ready: (see the two // New comment markers)
$(document).ready(function() {
var categoryOptions = ''; // New var
$.ajax({ // New ajax
url: 'get_categories.php',
method: 'GET',
dataType: 'text',
success:function(data)
{
categoryOptions = data;
},
error:function(xhr, status, err)
{
console.log('get_categories.php error ' + err);
}
});
$(document).on('click', '.loginBtn', function(e) {
Content of get_categories.php: (replace with your DB handling)
<?php
$db = new mysqli('localhost', 'root', '', 'test');
// Get the category id/name pairs
$result = $db->query("SELECT cat_ID, cat_name FROM categories");
$options = '';
// Build the options
while ($row = $result->fetch_array()) {
$options .= '<option value="' . $row['cat_ID'] . '">' . $row['cat_name'] . '</option>';
}
// The option 0 was last, keeping the same way.
$options .= '<option value="0"></option>';
echo $options;
Then change the categories html from:
html += '<td class=\"footer\"><select name="category[]" id="category_'+$(this).attr('id')+'" class="editbox"><option value="4">Moet gerankt worden</option><option value="6">Wordt gerankt</option><option value="5">Current BF Holder</option><option value="7">Main Account</option><option value="8">Money Private</option><option value="11">CB/Suc</option><option value="13">Casino Holder</option><option value="15">Wordt Gestockt</option><option value="10">Dont use, ask first!</option><option value="14">Stockgeld</option><option value="0"></option></select></td>';
...to:
html += '<td class=\"footer\"><select name="category[]" id="category_'+$(this).attr('id')+'" class="editbox">' + categoryOptions + '</select></td>';
I believe that should achieve the desired goal.
I have a rudimentary page from which I am calling a PHP service--using an AJAX call--to get an RSS feed and display it in a DIV tag.
I have a PHP page that returns the RSS feed as a JSON array. I have confirmed that the service works, as I can run it from the browser and get appropriate output.
But when I run it from the AJAX call, I get success, but undefined response. I have tried putting a callback function, but no joy. I'm sure the solution is pretty simple.
Here is the PHP page (TestService.php)
<?php
header('Content-Type: application/json');
$url = $_REQUEST['sUrl'];
$year = $_REQUEST['getYear'];
$rss = simplexml_load_file($url);
$outlist = array();
//echo json_encode($outlist);
$i = 0;
foreach ($rss->channel->item as $item) {
$i = $i + 1;
$yr = date('Y', strtotime($item->pubDate));
if ($yr == $year && $i < 5) {
$outlist[] = array('title' => $item->title,
'pubDate' => $item->pubDate,
'description' => $item->description);
}
}
//$serializedList = serialized($outlist);
$encodedList = json_encode($outlist);
echo $encodedList;
?>
Here is the HTML (TestPage.html):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JQuery RSS Demo</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<script>
$(document).ready(function () {
//set the initial URL call
var sNewsUrl = "http://rss.cnn.com/rss/cnn_topstories.rss?xml";
var today = new Date();
var curYear = today.getFullYear();
for (var yr = curYear; yr >= 2017; yr--) {
$('#SelectYear').append("<option>" + yr + "</option>");
}
$('#news').html();
$('#news').append("<li>" + sNewsUrl + "</li>");
$.ajax({
type: "POST",
url: "TestService.php",
contentType: "application/json; charset=utf-8",
data: "{ 'sUrl': '" + sNewsUrl + "', 'getYear': '" +
curYear + "' }",
dataType: "json",
success: function (response) {
var jsonData = JSON.parse(response.d);
$('#news').empty();
if (jsonData.length <= 0)
$('#divNews').hide();
else {
$('#divNews').show();
for (var i = 0; i < jsonData.length; i++) {
if (i < 3)
$('#news').append("<li>" +
jsonData[i].pubDate +
" <a href='" + jsonData[i].link
+ "' target='_blank'>" +
jsonData[i].title + "</a>" + "
</li>");
}
}
},
error: function (xhr, status, error) {
//debugger;
alert("Result: " + status + " " + error + " " +
xhr.status + " " + xhr.statusText)
}
});
});
<div id="divNews">
News:<br />
<ul id="news"></ul>
</div>
</body>
</html>
I'm using this
auto-complete plugin with my new project. It's working fine. See image
But I want to populate these fields when I select the result.
Here is my code:
var as = $("#query" + x + "").autocomplete({
minChars: 1,
maxHeight: 100,
serviceUrl: 'index.php?r=purchaseorder/list',
});
IN CONTROLLER
public function actionList() {
$criteria = new CDbCriteria;
$criteria->select = array('id','description','unit','rate');
$criteria->addSearchCondition("description", $_GET['query']);
$criteria->limit = $this->limit;
$items = Item::model()->findAll($criteria);
$suggestions = array();
$data = array();
foreach ($items as $c) {
$suggestions[] = $c->description;
$data[] = $c->id;
}
header('Content-type: application/json; charset=utf-8');
echo CJSON::encode(
array(
'query' => 'q',
'suggestions' => $suggestions,
'data' => $data
)
);
exit;
}
grid jquery
jQuery("#addrow").click(function() {
jQuery(".item-row:last").after('<tr class="item-row">\n\
<td>\n\
<span id="delete' + x + '" style="cursor: pointer" class="icon-remove"></span>\n\
</td>\n\
<td class="item-code"><input autocomplete="off" name="code[]" id="code' + x + '" type="text" class="input-code"/></td>\n\
<td class="item-description"><input autocomplete="off" name="q" id="query' + x + '" type="text" class="input-description"/></td>\n\
<td class="item-unit"><input readonly autocomplete="off" name="unit[]" id="unit' + x + '" type="text" class="input-unit"/></td>\n\
<td class="item-qty"><input name="qty[]" autocomplete="off" value="0" id="qty' + x + '" type="text" class="input-qty"/></td>\n\
<td class="item-rate"><input readonly name="rate[]" autocomplete="off" value="125.25" id="rate' + x + '" type="text" class="input-rate"/></td>\n\
<td class="item-discount"><input name="discount[]" autocomplete="off" value="0.00" id="discount' + x + '" type="text" class="input-discount"/></td>\n\
<td class="item-total"><input name="total[]" readonly autocomplete="off" value="0.00" id="total' + x + '" type="text" class="input-amount"/></td>\n\
</tr>');
controller is already there
I have done it like this...
IN JQUERY....
var as = $("#query").autocomplete({
minChars: 1,
maxHeight: 100,
serviceUrl: 'index.php?r=purchaseorder/list',
onSelect: function(suggestion) {
var row = $(this).closest('tr');
row.find('.input-code').val(suggestion.id).attr('readonly', 'readonly');
row.find('.input-description').attr('readonly', 'readonly');
row.find('.input-unit').val(suggestion.unit).attr('readonly', 'readonly');
row.find('.input-rate').val(suggestion.rate).attr('readonly', 'readonly');
row.find('.input-qty').focus();
}
});
AND THEN IN CONTROLLER
public function actionList() {
$criteria = new CDbCriteria;
$criteria->select = array('description', 'id','unit','rate');
$criteria->addSearchCondition("description", $_GET['query']);
$criteria->limit = $this->limit;
$items = Item::model()->findAll($criteria);
$suggestions = array();
$x=0;
foreach ($items as $c) {
$suggestions[$x]['value'] = $c->description;
$suggestions[$x]['id'] = $c->id;
$suggestions[$x]['rate'] = $c->rate;
$suggestions[$x]['unit'] = $c->unit;
$x++;
}
header('Content-type: application/json; charset=utf-8');
echo CJSON::encode(
array(
'suggestions' => $suggestions,
)
);
exit;
}
thats it...!
Sample code as shown below
$('#yourautoCompleteId').change(function(){
var selecteddata=$(this).val();
$.ajax({
url: "'.$this->createUrl('Controller/yourMethod').'",
data: {
//special:specialisation,
data :selecteddata,
},
type:"GET",//you can also use POST method
dataType:"html",//you can also specify for the result for json or xml
success:function(response){
//write the logic to get the response data as u need and set it to the fields
$("#dataId").val("SetHere");
$('#quantityId').val("setHere");
},
error:function(){
//TODO: Display in the poll tr ifself on error
alert("Failed request data from ajax page");
}
});
})
get the data in the controller using post and query with this data and send the result as u need and set to the fields as shown in the sample
This question already has answers here:
How to save an image from SQL Server to a file using SQL [closed]
(4 answers)
Closed 8 years ago.
I have written the following code to place the image path into sql server 2005 but its not working is their any alternate way to place images into sql server from clientside application.
example.html
<form id="addresslistingform" name="addresslistingform">
<fieldset id="fieldset1">
<legend>Address for listing</legend> Zipcode:<br />
<input size="30" type="text" id="zipcode" /><br />
Street No:<br />
<input size="30" type="text" id="addstreetno" class="number" name=
"streetno" /><br />
Street Name:<br />
<input size="30" type="text" id="addstreetname" class="required" name=
"streetname" /><br />
Upload a couple of pictures:<br />
<input size="30" type="file" id="addpicture" /><br />
</fieldset><input id="Addresslisting" type="image" src="images/Submit.png" align=
"left" />
</form>
example.js
$("#Addresslisting").click(function () {
var zipcode = ($("#addzipcode").val());
var streetno = ($("#addstreetno").val());
var streetname = ($("#addstreetname").val());
var image = ($("#addpicture").val());
var submitaddress = "{\"zipcode\":\"" + zipcode + "\",\"streetnumber\":\"" + streetno + "\",\"streetname\":\"" + streetname + "\",\"streetname\":\"" + streetname + "\",\"Imagelocation\":\"" + image + "\"}";
$.ajax({
type: "POST",
url: "/exampleproject/Afterlogin.asmx/addresslisting",
data: submitaddress,
contentType: "application/json; charset=utf-8",
success: ajaxSucceed,
dataType: "json",
failure: ajaxFailed
});
});
asmx webservices file
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool addresslisting(string zipcode, string streetnumber, string streetname, string Imagelocation)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "";
con.Open();
SqlCommand sqlcom = new SqlCommand();//declaring a new command
sqlcom.CommandText = "insert into Address_Listing(Zip_Code,Street_Number,Street_Name,Image_Location) values ('" + zipcode + "','" + streetnumber + "','" + streetname + "', '" + Imagelocation + "')"; //query for inserting data into contact table
sqlcom.Connection = con;//connecting to database
try
{
int success = sqlcom.ExecuteNonQuery();
con.Close();
if (success > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
con.Close();
return false;
}
I do not recommend storing images in SQL server, what you really should do is store the path to the image on your server in the SQL server.
Also p.campbell wasn't very helpful but very correct. Your database is going to get hacked with the code you currently have. You need to use SQL Parameters to prevent malicious SQL code from being injected.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx