Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从html javascript中获取值_Javascript_Php_Html_Mysql - Fatal编程技术网

如何从html javascript中获取值

如何从html javascript中获取值,javascript,php,html,mysql,Javascript,Php,Html,Mysql,我有一个弹出脚本来显示MySQL的完整数据 <?php $namedetails = $_GET['viewdetails']; include 'connection.php'; $result = mysqli_query($connect, "SELECT * FROM myTable WHERE Name='$namedetails' "); foreach ($result as $row); ?> <?php /* Here all data

我有一个弹出脚本来显示MySQL的完整数据

<?php
$namedetails = $_GET['viewdetails'];
    include 'connection.php';
    $result = mysqli_query($connect, "SELECT * FROM myTable WHERE Name='$namedetails' ");
    foreach ($result as $row);
?>
<?php /* Here all data row based on Name to show */ ?>

“无需刷新页面”闻起来像是需要Ajax来表示,如何触发弹出窗口打开?请提供代码示例。请注意:您的代码易受SQL注入攻击。您只需提供一个精心编制的
viewdetails
query参数,即可允许用户直接在您的数据库上运行SQL查询。我们只是想谈谈SQL注入,@JanneKlouman good catch。如果你正在做一个弹出窗口,你需要提供触发它的逻辑。
javascript:void(0)
不是一个可行的解决方案。如果您对链接的默认行为不满意,请使用按钮替换它,或在单击事件上使用
preventDefault
。。。
<a href="MyWebsite.com/listpage/?viewdetails=John">View details</a>
    <a href="javascript:void(0);" id="jwpopupLink" viewdetails="John" >View Full Details</a>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Popup</title>

<style>
body{
    font-family: Verdana, Geneva, sans-serif;
}
/* jwpopup box style */
.popheader { font-family: Verdana, Geneva, sans-serif; }
.jwpopup {
    display: none;
    position: fixed;
    z-index: 1;
    padding-top: 180px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0,0,0);
    background-color: rgba(0,0,0,0.7);
}
.jwpopup-content {
    position: relative;
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    max-width: 900px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s
}

.jwpopup-head {
    font-size: 21px;
    font-family: Verdana, Geneva, sans-serif;
    padding: 10px 16px;
    color: white;
    background: #006faa; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(#006faa, #002c44); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(#006faa, #002c44); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(#006faa, #002c44); /* For Firefox 3.6 to 15 */
    background: linear-gradient(#006faa, #002c44); /* Standard syntax */
}
.jwpopup-main {padding: 5px 16px;}
.jwpopup-foot {
    font-size: 14px;
    padding: 3px 16px;
    color: #ffffff;
    background: #006faa; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(#006faa, #002c44); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(#006faa, #002c44); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(#006faa, #002c44); /* For Firefox 3.6 to 15 */
    background: linear-gradient(#006faa, #002c44); /* Standard syntax */
}

/* animation */
@-webkit-keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}

@keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}

/* close */
.close {
    margin-top: 0px;
    color: white;
    float: right;
    font-size: 18px;
    font-weight: none;
}
.close:hover, .close:focus {
    color: #999999;
    text-decoration: none;
    cursor: pointer;
}
</style>

</head>
<body>

<?php
$namedetails = $_GET['viewdetails'];
    include 'connection.php';
    $result = mysqli_query($koneksi, "SELECT * FROM myTable WHERE Name='$namedetails' ");
    foreach ($result as $row);
?>
<a href="javascript:void(0);" id="jwpopupLink"></a> 
<!-- jwpopup box -->
<div id="jwpopupBox" class="jwpopup">
    <!-- jwpopup content -->
    <div class="jwpopup-content">
        <div class="jwpopup-head">
            <span class="close">Close</span>
            <?php echo "<span class='popheader' style='color: #ffff00;'><strong>+ ".$row['Name']."</strong></span>" ?>
        </div>
        <div class="jwpopup-main">
</br>       
<?php
     if($result->num_rows == 0) 
     {
     echo 
     "</br></br><h1 style='text-align: center;'><strong>Ups... No Data Found for <span style='color: #1512ba'>$dnview</strong></span></h1></br></br></br>";
     } 
     else 
    {
    echo "

<table style='width: 100%; font-weight: bold;' border='2'>
    <tbody>
        <tr>
            <th colspan='2' style='font-weight: bold;'><h4>Name</h4></th>
            <th style='font-weight: bold;'><h4>City</h4></th>
            <th style='font-weight: bold;'><h4>Country</h4></th>
        </tr>
        <tr>
            <td style='font-size: 12px;'>
                <span style='color: #1512ba;'>".$row['Name']."</span>
            </td>
            <td style='font-size: 12px;'>
                <span style='color: #1512ba;'>".$row['City']."</span>
            </td>
            <td style='font-size: 12px;'>
                <span style='color: #1512ba;'>".$row['Country']."</span>
            </td>

        </tr>
    </tbody>
</table>
</br>               
    ";
    }
?>

        </div>
        <div class="jwpopup-foot">
            <span><strong>MyDomain</strong></span>
        </div>
    </div>
</div>


<script>


var jwpopup = document.getElementById('jwpopupBox');

var mpLink = document.getElementById("jwpopupLink");

var close = document.getElementsByClassName("close")[0];

mpLink.onclick = function() {
    jwpopup.style.display = "block";
}

close.onclick = function() {
    jwpopup.style.display = "none";
}

window.onclick = function(event) {
    if (event.target == jwpopup) {
        jwpopup.style.display = "none";
    }
}

var url = window.location.href; {
if(url.indexOf('?viewdetails=') != -1) {
    jwpopup.style.display = "block"; }
}

</script>

</body>
</html>