The following code is to used to display an alert box with the order number when a html form is submitted successfully!
$mysql="SELECT MAX(OrderNo.) FROM `order` ";
$results=mysqli_query($db,$mysql);
$row=mysqli_fetch_array($results);
echo '<script type="text/javascript">';
echo 'alert("Successful signup your order number is"';
echo $row['OrderNo.'];
echo ")";
echo '</script>';
Though the alert box appears with "Successful signup your order number is" part, the OrderNo. part(retrieved from a databse table) does not appear in the alert box! Here max is used because the latest orderNo. is to be displayed and the OrderNo. field is auto incremented.
please help me to correct this error
You are not closing double quotes correctly.
It should be:
echo 'alert("Successful signup your order number is ';
echo $row['OrderNo.'];
echo '")';
Or better:
echo 'alert("Successful signup your order number is '.$row['OrderNo.'].'")';
Try to create an alias for the grouped number like this:
SELECT MAX(OrderNo) AS number FROM order
And show with:
echo 'alert("Successful signup your order number is' . $row['number'] . '")';
Related
I trying to use an alert message when someone enters incorrect login details, and I then want to redirect them back to the same login page. I'm doing this inside a php file that is called when someone submits a login form. I'm trying something like this:
echo '<script language="javascript">';
echo 'alert("Invalid Username or Password")';
echo 'location.replace("target.php")';
echo '</script>';
but it goes to the php file itself, which shows nothing.
update it you have missing ; for alert
echo '<script language="javascript">';
echo 'alert("Invalid Username or Password");';
echo 'window.location("target.php")';
echo '</script>';
echo '<script>';
echo 'alert("Invalid Username or Password"); ';
echo 'location.replace("http://mywebsite.com/target.php"); ';
echo '</script>';
language attribute is deprecated
location.replace("target.php") must have valid url: location.replace("http://mywebsite.com/target.php") or you can use history.back()
and as noted, don't miss semicolon
I have a "Bootstrap" form. When the user press "Submit" data is sent to file.php If the database is updated, I have an alert in that php file which echos an alert with "success". Now I'd like to alert a timed message. Not the alertbox with "OK" button. Is there some small simple code for this?
This is what I have now!
PHP
//Echo succes
echo "<script type='text/javascript'>";
echo "alert('Välkommen ".$row['usr_fname']." ".$row['usr_lname']."');";
echo 'window.location = "../back_to_form.html"';
echo "</script>";
die();
You could potentially use something like Jquery UI to fake a dialog box. Then the reloading could happen just like you want it to. The code would look something like this (untested, you'd need to adapt it to your app):
echo "<html><body>";
echo '<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>';
echo "<div id="dialog" title="Basic dialog">";
echo "<p>Välkommen ".$row['usr_fname']." ".$row['usr_lname']."</p>";
echo "</div>";
echo "<script type='text/javascript'>window.settimeout(window.reload(), 5000)</script>";
echo "</body></html>";
More info with a better javascript example for the jquery ui message box can be found here
I would like to embed a JavaScript alert box into php code and would like the text to report variable values. The following code gives multiline but does not enable me to use variables.
?>
<script type="text/javascript">
alert("Total size of all files too large.\nConsider uploading files in smaller sets.\nYou can append to existing sets.");
document.location.href="SomewhereElse.php";
</script>
<?php
The following code lets me use variables but does not give multiline.
$Str="Total size cannot be not more than " . ini_get('post_max_size');
echo "<script type='text/javascript'>\n";
echo "alert('" . $Str . "');";
echo "</script>";
When I try this code, no alert box comes up.
$Str="Unable to load (all of) these files because of their (total) size" .
"\nPlease make the upload set conform to the following parameters";
echo "<script type='text/javascript'>\n";
echo "alert('" . $Str . "');";
echo "</script>";
I do get an alert box if I leave the \n (before the Please) out but it is not multiline. I am wondering if the \n dismisses the alert box. At any rate, how do I get a multiline alert box with variables?
try something like this:
<?php
$max_size = ini_get('post_max_size');
echo '<script>';
echo 'alert("Total size cannot be more than ' . $max_size . '!\nPlease make sure...");';
echo '</script>';
?>
ok I've searched stackoverflow and many other sites, I've tried all kinds of solutions for this but nothing seems to work.
I am processing a form in PHP, checking for missed entries and erroring if missed or adding to the SQL DB if ok, the form itself works just fine, the processing works, the form is either error thrown and displayed or added to the Database, I want that page to then display either error or sucess wait a short time and then auto forward either back to the form if there was an error, or to the page that displays the db contents if the add was successful. Nothing I seem to try here works. please help: My code so far:
//If errors present
if ($errormsg) {
echo "<div class=\"box red\">$errormsg</div>";
sleep(2);
echo '<script>' . "\n";
echo 'window.location="blogmake.html?blogid=" + blogid;';
echo '</script>';
}
if ($secim == "3"){ //If all present and correct post comment to DB
if ($valname && $valemail && $valcom){
$con = mysql_connect("xxxx","User","pass");
if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db("dbname", $con);
$fulcom = mysql_real_escape_string ($_POST['comment']);
mysql_query("INSERT INTO tabname(blogid, date, email, name, comment) VALUES ('$blogid', CURRENT_TIMESTAMP(),'$valemail','$valname','$fulcom')") or die('Error: ' . mysql_error());
mysql_close($con);
echo "<div class=\"box green\">Your comment has been submitted</div>";
sleep(2);
echo '<script>' . "\n";
echo 'window.location="blogread.php?blogid=" + blogid;';
echo '</script>';
}
}
?>
</div>
You should probably use either an HTML meta tag:
<meta http-equiv="refresh" content="2;URL='http://yoursite.com/blogread.php?blogid=<?= $blogid ?>'" />
or JavaScript's setTimeout function:
setTimeout(function(){
window.location="blogread.php?blogid=<?= $blogid ?>";
}, 2000);
The meta tag has two important parameters: 2 is the number of seconds after which a redirection happens; and URL=... is the url to which it should redirect.
SetTimeout has two parameters in this case, the first one is the function that will be executed (the whole function part); and the other one is the delay time in milliseconds after which that function will be executed (the number 2000).
Note that I used <?= $blogid ?> in both cases - that's just a short code for this: <?php echo $blogid; ?>. Of course, you can use it however you want, for example using echo to echo the whole code, just like you were doing.
You need:
<meta http-equiv="refresh" content="3;url=http://www.google.com/" />
Change 3 for your seconds and url= by your webpage, ie:
echo '<meta http-equiv="refresh" content="2;url=blogread.php?blogid='.blogid.'" />';
I'm having troubles with the price formatting on a product page of a downloadable product.
The format (as defined globally) should be EUR 15.23. It work's fine in the sidebars, category pages, homepage and so on.
Anyway, on the product page the price is shown wrong (without space): EUR15.23
catalog/product/view.phtml:
//calling once - price EUR15.23
<?php echo $this->getPriceHtml($_product, true); ?>
//calling twice - first price EUR15.23 second price EUR 15.23 (correct)
<?php echo $this->getPriceHtml($_product, true); ?>
same problem when calling:
<?php echo $this->getChildHtml('product_type_data'); ?>
I think it has to do with the reloadPrice : function() JavaScript Code in
downloadable/catalog/product/links.phtml
Anyone also had this problem?
Actually I don't want to get through the JavaScript-Code and change something here as I do not want to change the core files.
Thanks!
Sure it isn't right solution, but if I got you right and it is always true that "first price EUR15.23 second price EUR 15.23 (correct)", then why not just
<?php $this->getPriceHtml($_product, true); // no output ?>
<?php echo $this->getPriceHtml($_product, true); // correct output ?>