I have a form that inserts data into mySQL. It works fine.
After the submission, I have a success page that displays 'part_no'. I need to also show 'add_qty', as well.
How do i alter my post script to show two field data's on the success page?
Here is part of my code (that already works):
$part_no = $_REQUEST['part_no'] ;
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no));
}
else {
header("location: inv_fc_add_fail.php");
}
?>
Just append it as another $_GET variable i.e part_no="part"&quantity=1
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no)."&qty=".$quantity );
You need 3 things.
First, you'll need:
$add_qty = $_REQUEST['add_qty'];
Alternatively you can simply use $_REQUEST['add_qty'] directly instead of assigning it to a new variable ($add_qty).
Then instead of:
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no));
you need:
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no) . "&add_qty=" . urlencode($add_qty));
Then, on the page inv_fc_add_success.php (which you will need to edit), you display the variable the same way that you display $part_no. As always, you can either assign it to a variable, like you already do at the top, or you can just use $_REQUEST['add_qty'] directory.
Related
I just installed Twitter Typeahead (older vesion 0.9.3).
Right now it links to a search.php page which queries the MySQL database to get the results. It gets the results I need, however, when I select the results, I can't figure out how to pass the ID or other information create a link to another page.
Here is the function in the HTML page that's calling the search.php page:
<script>
$(document).ready(function(){
$('input.typeahead').typeahead({
name: 'typeahead',
remote:'search.php?key=%QUERY',
limit : 10
});
});
</script>
Then search.php is called which queries the database correctly and gets the results I need:
<?php
$key=$_GET['key'];
$array = array();
$con=mysql_connect("hostname","username","password");
$db=mysql_select_db("databasename",$con);
$query=mysql_query("select * from customers where clientDisplayName LIKE '%{$key}%' OR clientPhNumber LIKE '%{$key}%' OR clientAltPhNumber LIKE '%{$key}%'");
while($row=mysql_fetch_assoc($query))
{
//$array[] = "<a href='customer-details.php?cid=".$row['id'] ."'><tr><td>" . $row['clientDisplayName'] . "</tr></td></a>";
$array[] = $row['clientDisplayName'];
}
echo json_encode($array);
?>
You can see the comment there, if I use that instead of the array that's uncommented, It will create a link as I desire, however.. it's buggy that way.
By Buggy I mean:
I HAVE to click on the actual text instead of anywhere in the result row
I cannot simply arrow-down and hit enter to select a response (it must be mouse clicked)
and even if it is clicked with the mouse, I can see the whole
Any ideas on what I can do here?
Do not use twitter typeahead. It is abandoned, no longer maintained, it has 250 issues, some of them very serious regarding basic behavior and severe bugs. I would recommend github.com/bassjobsen/Bootstrap-3-Typeahead instead.
I am using this cool script http://qpoit.com/marcofolio_demo/apple_search/ however when I click on a search result, I want it to be added as html content to an id which I will use like . I know this is done with $("#displayContent").html(data); however I need the content of search result that I clicked on to be and not all the results found. Please help
The rpc.php-file of the search, contains the function, which generates the output of the search.
In line 29, change the content to a JavaScript-function, which does this work for you.
// Used in line 29 in rpc.php
echo '<a href="'.$result->url.'">';
// Change it to something like
echo '<a onclick="applyContent('.$result->url.')">'
After that, head back to the index.html (or the file in which you are using the apple-search), make sure jQuery is loaded and add something like this:
<script type="text/javascript">
// Use the same function name, as in the php-file
function applyContent (resultURL) {
// Use jQuerys get-function to get the content of the file you've found in the search
$.get(resultURL, function(data) {
// Change '#finalResult' to the css-selector, of the element, which should contain the result at the end
$('#finalResult').html(data);
});
}
</script>
Once you click on a search-result, it should make it the content of #finalResult, or whatever element you choose.
Please help to correct a filter problem.
Its a facebook fan page like website for users to add and like fanpages for each other.
want to do:
no duplicate Facebook fan page gets added to site database.
filter (http or https) and facebook fan-page link (with or without / ) as same.
example
http://www.facebook.com/Shareitto
https://www.facebook.com/Sharetto
http://www.facebook.com/Sharetto/
They all could be added to the site (this is problem, I want to filter)
Below is the complete code with filter
if(isset($_POST['add'])){
if(!preg_match("/\bfacebook.com\b/i", $_POST['url']))
{$msg = "<div class=\"msg_error\">ERROR: You need to add facebook page!
</div>";}
else if($_POST['title'] == ""){$msg = "<div class=\"msg_error\">
ERROR: Title can't be empty!</div>";}
else{
mysql_query("INSERT INTO 'facebook' (user, facebook, title, cpc)
VALUES('{$data->id}', '{$protectie['url']}', '{$protectie['title']}',
'{$protectie['cpc']}' ) ");
$msg = "<div class=\"msg_success\">Page added with success!</div>";
}}
?>
If need more, please reply!
The way I'd approach this is to only store the part of the URL after http://facebook.com/, so in the case you mentioned only "Sharetto" is stored. This makes lookups a lot easier, as performing REGEX in MySQL is an unnecessary use of resources in this case. When pulling out the data from the database you would then prepend the fanpage name with the Facebook URL.
I would pick out the important part of the URL using a regular expression like this:
$url = "http://www.facebook.com/Sharetto/";
$matches = array();
if (preg_match('~^https?://(?:www\.)?facebook.com/(.+)/?$~',$url,$matches)) {
$fanpageName = $matches[1]; // In this case: "Sharetto"
// Do lookup in DB for $fanpageName, not $url
}
Basically, throw away the Facebook URL completely, and just pick out the important part.
There is some HTML code which appears on the page as the result of AJAX request/response. This HTML contains GET requests to another php script. Links containing this requests are not working while "real" HTML (added on the page manually) works normally.
When I open the page source with Ctrl+U I see empty div's (but they actually have HTML retrieved via AJAX) and the full-fledged HTML code added manually. Can't figure out how can I make the AJAX-retrieved links working.
This is how I try to form the HTML code which must be added to the page as the result of AJAX response.
<?php
//some selections from the database...
//all subsequent varibles are the members of $row = mysql_fetch_array($query) array;
$html_to_be_inactive =
'<li id="productID_' . $productID . '">
<a href=work.php?action=deleteFromBasket&productID=' . $productID . ' onClick="return false;">
<img src="images/delete.png" id="deleteProductID_' . $productID . '">
</a> ' . $productName . '(' . $totalItems . ' items) - $' . ($totalItems * $productPrice) . '</li>';
echo $html_to_be_inactive;
?>
And that is it, result of 'echo' appears on the page after successful AJAX request as the simple HTML, and it does nothing when I click the link.
I do not perform DOM 'append' methods as I'm not familiar with DOM yet. I can see all the elements mentioned in $thml_to_be_inactive but the link seems to be really inactive. Also this HTML is absent in the "Ctrl+U" output, I can see it only when I select "Inspect element" in the browser.
The HTML which was added manually operates the same items as usual, but I need AJAX-retrieved HTML to be working as well.
I suspect I need to perform some 'append' method via JavaScript or jQuery, but I don't know how to do it in a proper way.
Thanks.
You need to put your href in quotes.
onClick="return false;" will override the default action (go to href) of your link. You need to bind an other event to the link, or just remove `return false'.
Your links use relative paths.
You're probably inserting the HTML into a page in a different directory, breaking the relative paths.
If so, you need to switch to absolute paths.
I'm creating a sample website using xhtml with javascript support. Also using php for server side programming. I need to redirect the webpage to some other page from an html page, after checking some condition.What is the best method to implement this. I've done it using
header("link"); but since i'm using it inside the tag, it shows up a error. is it possible to redirect to a particular link from within the tag.
The best way would be using PHP. Javascript solutions only work when… well, when javascript is enabled.
<?php
if($do_redirect) {
header("location: http://www.google.de");
}
?>
Note that this only works, when there was absolutely no output so far.
It depends on what the condition is.
If it is something you can test for in PHP, then do it in PHP (as one of the very first things you do, before you start thinking about generating output to the browser):
<?php
if (condition()) {
header("Location: http://example.com/foo/bar/baz");
exit();
}
?>
If it is something you can test for only in JavaScript then:
<script type="text/javascript">
if (condition()) {
location = "http://example.com/foo/bar/baz";
}
</script>
… keeping in mind the principles of progressive enhancement.
Sure. Do it through javascript:
window.location.href = 'http://www.google.com'
From within a tag you can use something like this
<tag onclick="if(condition == true) window.location.href = 'http://mylocation.com/'>Tag text</tag>
Most HTML tags support the onclick event, so replace tag with the type of tag you need for your situation.
The condition part can be an inline code to find some value, or some Javascript function you defined earlier.
try this
<?php
.
.
//your php code here
.
.
if($condition){
?>
script type='css/javascript'>
window.location.href = 'http://domain.com'
/script>
<?php
} else{
.
.
//again your php code here
.
.
}
?>