dszsajhd237437 2015-10-09 16:43
浏览 24

PHP提交表单错误

Error below: I'm pretty much trying to see what the user chose from the checkboxes.

Notice: Undefined variable: ch1 in /Applications/XAMPP/xamppfiles/htdocs/ProjectOne/index.php on line 42 ch1

HTML CODE :

<form action='submit.php' method="GET">

<div id="self">
<input type='text' name='Name' value='Name' />
    <br>
<input type='text' name='Cwid' value='CWID' />
    <br>
</div>

<div id='gender'>
<strong>Gender:</strong><input type="radio" name="sex" value="male"checked>Male
Or
<input type="radio" name="sex" value="female">Female
<br>
<div>

<div id='class'>
<strong>Class:</strong> <select name='class'>
<option value='Freshman'> Freshman </option>
<option value='Sophomore'> Sophomore </option>
<option value='Junior'> Junior </option>
<option value='Senior'> Senior </option>
</select>
</div>
<br>
<div id='pref'>
<strong>Student Preferences</strong>
<br>
<!-- line 42 -->
<input type="checkbox" name="ch1" value="ch133" /> <?PHP echo $ch1; ?>  ch1 <br />
<input type="checkbox" name="ch2" value="Laundry on Premise" /> Laundry on Premise<br />
<input type="checkbox" name="ch3" value="Fully Equipped Kitchen" /> Fully Equipped Kichen<br />

</div>
<div id='submit'><input type="submit"  name='submit' value="Submit" />   </div>

</form>

PHP CODE BELOW :

<?php
$ch1 = 'unchecked';
$ch2 = 'unchecked';
$ch3 = 'unchecked';
if(isset($_GET['submit'])) 
{
$name = $_GET['Name'];
$cwid = $_GET['Cwid'];
$sex = $_GET['sex'];
$class = $_GET['class'];
$ch1 = $_GET['ch1'];
$ch2 = $_GET['ch2'];
$ch3 = $_GET['ch3'];
    if (isset($ch1)) {
    $ch1 = $_GET['ch1'];

    if ($ch1 == 'ch1') {
        $ch1 = 'checked';
    }
}
}
?>
  • 写回答

2条回答 默认 最新

  • doushu9253 2015-10-09 16:58
    关注

    You call an echo on a inexistant variable. When you submit your form, $ch1 does not exist yet. Add this :

    <?php $ch1 = 'unchecked'; ?>
    

    in the line before :

    <input type="checkbox" name="ch1" value="ch133" /> <?PHP echo $ch1; ?>  ch1 <br />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测