du4373 2013-12-10 16:44
浏览 53
已采纳

无法在url中显示id,并且插入数据库的数据显示为空白

I want to get get id at the url. It displays the name of id variable instead of displaying the id. I also want eventid, event, venue and username to be inserted into the database, but event and username shows blank but the id increases. Whats the problem ?

<?php
require 'database.php';

$qry = "SELECT b.event_id, b.event, b.venue, u.username, s.name, s.gender, s.email, s.phone FROM bulletin b JOIN unite u JOIN student s WHERE b.event_id = u.event_id AND u.username = s.username ORDER BY event_id";
$result = mysql_query($qry) OR die (mysql_error());
     while ($row = mysql_fetch_row($result)){

             $eventid = $row[0];
                 $event = $row[1];
                 $venue = $row[2];
                 $username = $row[3];
                 $name = $row[4];
                 $gender = $row[5];
                 $email = $row[6];
                 $phone = $row[7]; 

?>

    <tr>
    <td><center><?php echo $row[0]; ?></center></td>
    <td><center><?php echo $row[1]; ?></center></td>
    <td><center><?php echo $row[2]; ?></center></td>
    <td><center><?php echo $row[3]; ?></center></td>
    <td><center><?php echo $row[4]; ?></center></td>
    <td><center><?php echo $row[5]; ?></center></td>
    <td><center><?php echo $row[6]; ?></center></td>
    <td><center><?php echo $row[7]; ?></center></td>
    <td><center>
              <br><form method="post" action="attend.php?eventid=<?php echo $row['event_id']; ?>" name="event_form1" target="_top">
              <input type="submit" name="submit" value=" Attend "></form></br>
              <br><form method="post" action="not_attend.php" name="event_form1" target="_top">
              <input type="submit" name="submit" value=" Not Attend "></form></center></br>                       
             </td>

            </tr>
             <?php 
             } ?>

attend.php

<?php
session_start();
require 'database.php';
$events= $_GET['eventid'];

$qry = "INSERT INTO attend (event_id, name_event, username) VALUES ('$events', '$event', '$username')";

$result = mysql_query($qry) or die (mysql_error());
if ($result){
//echo $result;
    header("location:activity_a.php?success=&eventid=$events");
    exit();
}else {
    die ("Query failed");
}

?>
  • 写回答

1条回答 默认 最新

  • dongsong1911 2013-12-10 17:07
    关注

    you're not passing any of the variables through the form, right now, you're just setting the submit button. if you plan on using an attend/not attend system then you'll need to re-do the sql to pull the information again for the variables. OR, you'll need to set hidden inputs for each form

    change your attend.php to this:

    <?php
    session_start();
    require 'database.php';
    $events= $_GET['eventid'];
    
    $qry = "SELECT b.event, u.username FROM bulletin b JOIN unite u JOIN student s WHERE b.event_id = u.event_id AND u.username = s.username ORDER BY event_id";
    $result = mysql_query($qry) OR die (mysql_error());
    $row = mysql_fetch_array($result)
    $event = $row[0];
    $username = $row[1];
    
    $nqry = "INSERT INTO attend (event_id, name_event, username) VALUES ('$events', '$event', '$username')";
    
    $nresult = mysql_query($nqry) or die (mysql_error());
    if ($nresult){
    //echo $nresult;
        header("location:activity_a.php?success=&eventid=$events");
        exit();
    } else {
        die ("Query failed");
    }
    
    ?>
    

    change this accordingly to match with your db.

    EDIT:

    I accidentally set the same variable and it got overwritten.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题