PHP Update Query didnt works - phpquery

I have one form text field in index.php and i fill 8080
http_port : <input size="5" name="http_port" value="3128">
and table 'squid' like this
no | tag | value
1 | http_port | 3128
when i click submit button its redirect to submit.php but the table didnt update the value or still 3128.
submit.php
<?php
include("conn.php");
$value = $_POST['http_port'];
$query = mysql_query("update squid set http_port='$value' where '$no'=1");
echo "Update was Succesful<br>
Bac";
?>
whats wrong with my script? Thanks and sorry for my bad english :)

There's a mistake in your mysql_query call, it should be:
$query = mysql_query("update squid set tag ='$value' where no=1");
I haven't coded anything in PHP for ages, but there are plenty of tutorials for such simple MySQL/PHP forms. Code I provided updates tag column, and in similar way you can update other columns...
$query = mysql_query("update squid set value ='$value' where no=1 and tag = 'http_port'");

Try this:
index.html:
<html>
<body>
<form action="submit.php" method="post">
http_port :
<input size="5" name="http_port" value="3128" />
<input type="submit" />
</form>
</body>
</html>
submit.php:
<?php
require("conn.php");
if(isset($_POST['http_port']))
{
$value = $_POST['http_port'];
//You should sanitize data before inserting into table
$value = mysql_real_escape_string(htmlentities(strip_tags(trim($value))));
$no="your table field name";
$sql = "UPDATE squid SET http_port=".$value." where ".$no."=1";
$query = mysql_query($sql) OR die("Err:".mysql_error());
echo "Update was Successful<br />Back";
}
else
{
echo "Something else";
}
?>

$value is in single quotes so will not get the value of variable $value.
$sql = "update squid set http_port='".$value."'where no=1";

Related

AMAZON: Add to remote cart without leaving site

Hey I'm trying to set up a remote cart. Very frustrating though since Amazon doesn't list any code examples for a remote cart without the customer leaving the site.
Here's where I'm at so far. I can get someone to leave my site and add the product from my site to Amazon using this (From: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/AddToCartForm.html):
<form method="GET" action="http://www.amazon.com/gp/aws/cart/add.html">
<input type="hidden" name="AWSAccessKeyId" value="Access Key ID" /> <br/>
<input type="hidden" name="AssociateTag" value="Associate Tag" /><br/>
<p>One Product<br/>
ASIN:<input type="text" name="ASIN.1"/><br/>
Quantity:<input type="text" name="Quantity.1"/><br/>
<p>Another Product<br/>
ASIN:<input type="text" name="ASIN.2"/><br/>
Quantity:<input type="text" name="Quantity.2"/><br/>
</p>
<input type="submit" name="add" value="add" />
</form>
But I want to make it so they can add an item to cart and stay on my site. It seems like this is how I accomplish that:
http://webservices.amazon.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
AssociateTag=[Associate Tag]&
Operation=CartCreate&
Item.1.OfferListingId=B000062TU1&
Item.1.Quantity=2
&Timestamp=[YYYY-MM-DDThh:mm:ssZ]
&Signature=[Request Signature]
But when I'm totally confused as to how to generate a timestamp and signature. Do I put this into a form action? Is there anywhere with code examples? I've been searching all day and can't find it. Any help greatly appreciated.
I'm using this method to generate api request url, and its totally working fine. Believe this will help you
$uri = "/onca/xml";
$asin = "B00C5AHTC0";
$end_point = "webservices.amazon.com";
$params = array(
"Service" => "AWSECommerceService",
"Operation" => "CartCreate",
'Version' => "2013-08-01",
"AWSAccessKeyId" => AWS_ACCESS_KEY,
"AssociateTag" => AWS_ASSOCIATE_TAG,
"Item.1.ASIN" => $asin,
"Item.1.Quantity" => "5",
"Timestamp"=> gmdate('Y-m-d\TH:i:s\Z')
);
// Sort the parameters by key
ksort($params);
$pairs = array();
foreach ($params as $key => $value) {
array_push($pairs, rawurlencode($key) . "=" . rawurlencode($value));
}
// Generate the canonical query
$canonical_query_string = join("&", $pairs);
$string_to_sign = "GET\n" . $end_point. "\n" . $uri . "\n" . $canonical_query_string;
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, AWS_SECRET_KEY, true));
$request_url = 'http://' . $end_point. $uri . '?' .$canonical_query_string . '&Signature='.rawurlencode($signature);

DOMXPath - Select only a few items

Let's say we have this html and the following DOMXPath code:
<div>
<div>
<p>1</p>
</div>
<div>
<p>2</p>
</div>
<div>
<p>3</p>
</div>
<div>
<p>4</p>
</div>
<div>
<p>5</p>
</div>
<div>
<p>6</p>
</div>
</div>
$doc = new DOMDocument();
$doc->loadHtml($strhtml);
$doc->preserveWhiteSpace = false;
$xpath = new DOMXPath( $doc );
$nodelist = $xpath->query('//div/div[2]/p');
foreach( $nodelist as $node ) {
$result = $node->nodeValue."\n";
}
echo $result;
Obviously, $result = '2', since we asked for the value of 'p' from the second 'div' node.
Now, how can I get the values for, say, from 'div[2]' to 'div[4]' and sum them?
To be precise, I would like to know how to get "from # to #" and also how to get "this #, that #, also # and #". So two questions, for two different problems.
Thanks in advance.
You are able to select range of elements with DOMXPath:
as for the first problem to get "from # to #" use the
following approach:
// select nodes within specified range of positions
$nodelist = $xpath->query('//div/div[position()>1 and position()<5]');
as for the second problem to get "this #, that #, also # and #"
try the following (with | union operator):
// extracts the 2nd, 4th and 6th elements respectively
$nodelist = $xpath->query('//div/div[2] | //div/div[4] | //div/div[6]);

Trying to validate one or more email extensions using regular expression

I'm getting a user to input their email address and trying to validate it using regular expressions and the preg match function. I'm unable to get the code to validate different email extensions (hotmail, gmail, blueyonder etc.) as I'm only able to get it to accept one and cannot use an OR function in the code. I'm not getting a specific error but as it is the user will have to be limted to just using the 'gmail.co.uk' extension. Any help?
Code:
<?php
$emailErr = "";
$email = "";
if(isset($_POST['submit'])){
if(empty($_POST["email"])) {
$emailErr = "Email is required";
}else{
$email = ($_POST["email"]);
if (!preg_match("/[a-zA-Z_-]+#[gmail]+.+[co]+.+[uk]/",$email)){
$emailErr = "Only letters and white space allowed";
}
}
}
?>
<html>
<head>
<title> symbol test</title>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<form name = "testform" method="POST">
<p>Email:<input type="text" name="email" style="width:20%"/>
<span class="error">*<?php echo $emailErr;?></span>
<p><br><input type="submit" name="submit" value="Submit"/></br></p>
</form>
<?php
echo $email;
?>
</body>
</html>
[gmail] is not the actual way to go. This matches g or m or a or i or l.
[a-zA-Z_-]+#gmail\.co\.\uk
Add anchors if necessary.
if (!preg_match("~^[a-zA-Z_-]+#gmail\.co\.uk$~",$email)){
If you are looking for a generic regex to match all kind of valid email-ID then you can try
^(?![\W_])((?:([\w-]{2,})\.?){1,})(?<![\W_])#(?![\W_])(?=[\w.-]{5,})(?=.+\..+)(?1)(?<![\W_])$
Look at the regex demo for detailed overview.

Database execution with Opencart

I am using this module which allows me to run a simple blog / news feed in OC which does what I need apart from one thing, I need to display the first 4 articles on the homepage.
I have got the following so far:
<?php
$sql = "SELECT * FROM " . DB_PREFIX . "blog b LEFT JOIN " . DB_PREFIX . "blog_description bd ON (b.blog_id = bd.blog_id) WHERE b.status = 1 AND b.date <= NOW() AND bd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
$query = $this->db->query($sql);
$blogs = array();
?>
<div class="box" id="news">
<div class="title">
<p>Latest News</p>
</div>
<div class="content">
<?php
foreach($query->rows as $result){
$blogs[] = $result;
}
?>
</div>
</div>
I have been developing OC templates for a while but modules are a whole new ball game for me, any help would be appreciated
First of all You should learn and understand how the MVC (or whatever it tends to be) is implemented in OpenCart - we have controllers, models and view templates.
Your approach is mixing all the controller and model part into a view template which is completely wrong.
So what should go where:
SQL query should go into the model
A new method for retrieving the data from the model and preparing it for the view template should go into the controller
Only HTML markup should be present in the view template
Let's say the extension You have downloaded has a controller here: catalog/controller/information/news.php - You should extend it's index() (or other appropriate) method (or even create a new one if needed) so that it calls the news model where You place Your new method getLastFourArticles() which should look like:
public function getLastFourArticles() {
$sql = "
SELECT *
FROM " . DB_PREFIX . "blog b
LEFT JOIN " . DB_PREFIX . "blog_description bd ON b.blog_id = bd.blog_id
WHERE b.status = 1
AND b.date <= NOW()
AND bd.language_id = " . (int)$this->config->get('config_language_id') . "
ORDER BY b.date DESC
LIMIT 4";
return $this->db->query($sql);
}
ORDER BY part will sort the blog entries from the newest to the latest and the LIMIT 4 part will make sure we only receive 4 rows maximally.
Now in the controller You should do something like:
$this->data['latest_entries'] = $this->model_information_news->getLastFourArticles();
while expecting the model to be catalog/model/information/news.php and that it is loaded ($this->load->model('information/news');).
Now in Your template only this part is needed:
<div class="box" id="news">
<div class="title">
<p>Latest News</p>
</div>
<div class="content">
<?php foreach($latest_entries as $entry) { ?>
<span class="date"><?php echo $entry['date']; ?></span>
<span class="entry"><?php echo $entry['text']; ?></span>
<?php } ?>
</div>
</div>
Keep in mind this is only instruction-like answer and You should pass in the right names and variables (and indices for the blog entry in the template).

how to replace "opencart" word from back-end

i want to replace the "Opencart" word from my back-end by the name of my store. I mean the "Opencart" written before the "Administration" in back end and from its footer in Dashboard. Will please any one help me out?
Thank you..
I think "Opencart" not word but it's an image logo.
You can edit this line :
<div class="div2">
<img src="view/image/logo.png" title="<?php echo $heading_title; ?>" onclick="location = '<?php echo $home; ?>'" />
</div>
location file : admin/view/template/common/header.tpl