我是PHP的新手,并且正在使用小型货币转换器页面进行练习。我的PHP和HTML代码都在一个名为" index.php":
的页面中<?php
$originalAmount = $_POST["originalAmount"];
$convertedAmount = 0.00;
$currency1 = $_POST["currency1"];
$currency2 = $_POST["currency2"];
function convertCurrency($input, $origCurr, $convertCurr) {
if ($origCurr === 1){
if ($convertCurr === 2){
$convertedAmount = $input * 0.78;
return $convertedAmount;
}
elseif ($convertCurr === 3){
$convertedAmount = $input * 0.90;
return $convertedAmount;
}
else {
$convertedAmount = $input;
return $convertedAmount;
}
}
if ($origCurr === 2){
if ($convertCurr === 1){
$convertedAmount = $input * 1.29;
return $convertedAmount;
}
elseif ($convertCurr === 3){
$convertedAmount = $input * 1.16;
return $convertedAmount;
}
else {
$convertedAmount = $input;
return $convertedAmount;
}
}
if ($origCurr === 3){
if ($convertCurr === 2){
$convertedAmount = $input * 0.86;
return $convertedAmount;
}
elseif ($convertCurr === 1){
$convertedAmount = $input * 1.11;
return $convertedAmount;
}
else {
$convertedAmount = $input;
return $convertedAmount;
}
}
}
$convertedAmount = convertCurrency($originalAmount, $currency1, $currency2);
?>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Currency Converter</title>
<!--jQuery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<!--Bootstrap 3-->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!--Custom CSS-->
<link href="main.css" type="text/css" rel="stylesheet">
</head>
<body>
<div class="container">
<!--Header Row-->
<div class="row page-header">
<div class="col-xs-6">
<h1>Currenccy Converter</h1></div>
<div class="col-xs-6">
<p>Add items via the input below.
<br>Click to mark complete (Completed Items will be marked with a green background.)
<br>To delete a task, Click on the X.
<br>Double Click to edit the item, it will be moved to the add item box</p>
</div>
</div>
<!--Add Task / Input Row-->
<div class="row">
<div class="col-xs-12 well">
<h2 class="text-xs-center"><?php print $convertedAmount; ?></h2>
<form class="form-control" id="converterForm" action="index.php" method="post">
<select name="currency1" id="currency1">
<option value="zzz">Starting</option>
<option value="1">USD</option>
<option value="2">GBP</option>
<option value="3">EUR</option>
</select>
<select name="currency2" id="currency2">
<option value="zzz">Converted</option>
<option value="1">USD</option>
<option value="2">GBP</option>
<option value="3">EUR</option>
</select>
<div class="form-group">
<label for="originalAmount" id="origLabel">Amount:</label>
<input id="originalAmount" type="number" value="0.00" name="originalAmount">
<input type="submit" id="submit" name="submit" value="SUBMIT">
</div>
</form>
</div>
</div>
</div>
</body>
</html>
我的问题是,它似乎无法在服务器上运行。我曾经有一个readonly输入,我试图通过php echo
更新作为值,但是当我点击提交时,它不起作用。然后我用包含echo
的H2元素替换了输入。
我对此页面的目标是在没有javascript / ajax的帮助下通过HTML和PHP完成所有操作。
为什么某个值中的echo
不会返回$converted
的值,是否有任何超级明显的理由?我宁愿使用CSS的readonly输入和样式,而不是使用H2元素,但我想其中任何一个都可行。
期待你的好人们的想法。谢谢。
答案 0 :(得分:2)
问题:如果条件<div *ngIf="visible">
<div class="dashhead">
<div class="dashhead-titles">
<h6 class="dashhead-subtitle">Bootops</h6>
<h3 class="dashhead-title">Role Builder</h3>
</div>
<div class="dashhead-toolbar">
<span class="dashhead-toolbar-divider hidden-xs"></span>
</div>
</div>
<ul class="nav nav-bordered">
<li [class.active]="isCurrentRoute(['Environments'])"><a
<li><a (click)="logout()">Logout</a></li>
</ul>
</div>
用于比较值和变量的类型,那么您在所有情况下都使用===
。在您的情况下,===
是字符串类型,您正在将字符串与数字进行比较。 $_POST['your_variable']
。阅读比较运算符here
解决方案:使用类型转换变量或使用if ($origCurr === 1)
仅比较值。 ==
答案 1 :(得分:0)
Rohit发现了这个错误的原因。我还想为转换函数提供这种替代方法,仍然需要考虑输入变量的类型。
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-keepattributes Signature
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dontwarn android.support.**
-dontwarn com.instagram.common.json.**
-dontwarn com.fasterxml.jackson.databind.ext.DOMSerializer
-dontwarn com.squareup.javawriter.JavaWriter
-dontwarn com.google.common.primitives.UnsignedBytes*
-dontwarn sun.misc.Unsafe
-dontwarn javax.annotation.**
-dontwarn com.squareup.picasso.**
-dontwarn okio.Okio.**
-dontoptimize
-dontpreverify
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
# Facebook library
-keep class com.facebook.** {
*;
}
-dontwarn com.squareup.okhttp.**
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}