How can I send $_POST values from a form to an image tag? Image is created by another PHP file with post values. Code example:
如何将表单中的$ _POST值发送到图像标记?图像由另一个带有帖子值的PHP文件创建。代码示例:
<form name="grafiks" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onsubmit="check()">
<select name="kolsk" onchange="this.form.submit()" >
<option></option>
<option <?php if(isset($_POST['kolsk']) && $_POST['kolsk'] == '1') echo 'selected="selected"' ?> value="1">1</option>
<option <?php if(isset($_POST['kolsk']) && $_POST['kolsk'] == '2') echo 'selected="selected"' ?> value="2">2</option>
<option <?php if(isset($_POST['kolsk']) && $_POST['kolsk'] == '3') echo 'selected="selected"' ?> value="3">3</option>
</select>
</form>
<?php
if(isset($_POST['kolsk'])){
$kolsk = $_POST['kolsk'];
}
echo '<img src = "myplot2.php" ?$kolsk >';
?>
2 个解决方案
#1
1
You just need to wrap your server-side code in the <?php ?>
tags, just as you do earlier in the file. Something like this:
您只需将服务器端代码包装在 标记中,就像在文件中先前一样。像这样的东西:
<?php
if(isset($_POST['kolsk'])){
$kolsk = $_POST['kolsk'];
?>
<img src="myplot2.php?<?php echo $kolsk ?>" />
<?php
}
?>
It's not 100% clear if that src
value is a valid URL for your needs. If that's a query string parameter then you'd need a key to go with that value, perhaps something like:
如果src值是满足您需求的有效URL,则不是100%清楚。如果这是一个查询字符串参数,那么你需要一个键来使用该值,可能是这样的:
<img src="myplot2.php?kolsk=<?php echo $kolsk ?>" />
#2
0
Not sure if you're trying to set the image src dynamically or something else, but
不确定您是否尝试动态设置图像src或其他内容,但是
<img src = "myplot<?php echo $_POST['kolsk'];?>.jpg" >
should produce myplot1.jpg, myplot2.jpg, myplot3.jpg depending upon the user selection.
应根据用户选择生成myplot1.jpg,myplot2.jpg,myplot3.jpg。
#1
1
You just need to wrap your server-side code in the <?php ?>
tags, just as you do earlier in the file. Something like this:
您只需将服务器端代码包装在 标记中,就像在文件中先前一样。像这样的东西:
<?php
if(isset($_POST['kolsk'])){
$kolsk = $_POST['kolsk'];
?>
<img src="myplot2.php?<?php echo $kolsk ?>" />
<?php
}
?>
It's not 100% clear if that src
value is a valid URL for your needs. If that's a query string parameter then you'd need a key to go with that value, perhaps something like:
如果src值是满足您需求的有效URL,则不是100%清楚。如果这是一个查询字符串参数,那么你需要一个键来使用该值,可能是这样的:
<img src="myplot2.php?kolsk=<?php echo $kolsk ?>" />
#2
0
Not sure if you're trying to set the image src dynamically or something else, but
不确定您是否尝试动态设置图像src或其他内容,但是
<img src = "myplot<?php echo $_POST['kolsk'];?>.jpg" >
should produce myplot1.jpg, myplot2.jpg, myplot3.jpg depending upon the user selection.
应根据用户选择生成myplot1.jpg,myplot2.jpg,myplot3.jpg。