duanjia1870 2014-03-14 22:17 采纳率: 0%
浏览 74
已采纳

将单选按钮值插入SQL

Working out a simple star ratings script. Data not inserting into SQL. I am passing a 'id' in the url from the form action to coincide with the rating. I'm using GET to retreive that value. I'm using POST to insert the radio button value. I've tested and the url is passing the id. The script runs to completion. SQL is connecting.

index.html

    <form method="POST" action="rating.php?id=<?php echo $id; ?>">
      <fieldset class="rating">
          <legend>. . .</legend>
              <input type="radio" id="star3" name="starno" value="3" onclick="this.form.submit()"/>
                  <label for="star3" title="Meh">3 stars</label>
              <input type="radio" id="star2" name="starno" value="2" onclick="this.form.submit()"/>
                  <label for="star2" title="Kinda bad">2 stars</label>
              <input type="radio" id="star1" name="starno" value="1" onclick="this.form.submit()"/>
                  <label for="star1" title="Sucks big time">1 star</label>
      </fieldset>
    </form>

ratings.php

    <?php
    isset($_GET['id']);
    $con=mysqli_connect ("","","","");
    mysqli_query($con,"INSERT INTO ratings (storyidr, rank, entry_date) VALUES ('$_GET[id]','$_POST[starno]',now())");
    mysqli_close($con);
    header('Location: http://www.website.com/'); 
    ?>

SQL

    CREATE TABLE IF NOT EXISTS `ratings` 
    (
      `ratingid` int(11) NOT NULL AUTO_INCREMENT,
      `storyidr` varchar(11) NOT NULL,
      `rank` int(11) NOT NULL,
      `entry_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    PRIMARY KEY (`ratingid`),
    UNIQUE KEY `ratingid` (`ratingid`)
    ) 
    ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='rating for stories' AUTO_INCREMENT=1 
  • 写回答

2条回答 默认 最新

  • douliaodan2738 2014-03-15 01:36
    关注

    You are setting:

    $storyidr = $_POST['id']; 
    

    but it is actually passed in the URL. therefore you need to use:

    $storyidr = $_GET['id'];
    

    The form 'method' does not need to be changed.

    I have looked at the generated sql and it now contains all the input.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀