简体   繁体   English

PHP条件块不起作用..我是php新手

[英]PHP Conditional Block not working.. I'm new to php

httPHP Mysqli condition block is not working.. Earlier it was working, later i added few more scripts thn its not working.. I'm new to PHP. httPHP Mysqli条件块不起作用。.早先它起作用,后来我又添加了一些脚本,使其不起作用..我是PHP的新手。

note : Database insertion is working. 注意:正在插入数据库。 only the condition is not working 只有条件不起作用

<?php

if (!$_GET)
{
header('location:index.php');
}
else
{
$language['english'] = array(
    'url' => 'http://example.com'
);
$language['chinese'] = array(
    'url' => 'http://example.com'
);
$language['japanese'] = array(
    'url' => 'http://example.com'
);
if (isset($_POST['submit']))
    {
    $count_me_in = sanitize($_POST['con_in']);
    $email = sanitize($_POST['email']);
    $comments = sanitize($_POST['comments']);
    $ip = $_SERVER['REMOTE_ADDR'];
    $sql = "INSERT INTO $table_name (count_me_in, email, comments, REMOTE_Addr) VALUE (" . PrepSQL($count_me_in) . ", " . PrepSQL($email) . ", " . PrepSQL($comments) . ", " . PrepSQL($ip) . ")";
    $query = mysqli_query($conn, $sql);
    var_dump($query);
    if ($query)
        { /// this condition not working
        echo "Thanks for submitting";

        // echo "<script type='text/javascript'>alert('Thank you for your feedback');</script>";

        }
      else
        {
        echo "Error: " . $sql . "<br />" . mysqli_error($conn);
        }
    }

function sanitize($data)
    {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
    }

function PrepSQL($value)
    {

    // Stripslashes

    if (get_magic_quotes_gpc())
        {
        $value = stripslashes($value);
        }

    include 'connect.php';

    // Quote

    $value = "'" . mysqli_real_escape_string($conn, $value) . "'";
    return ($value);
    }

   ?>

  <html>My html program <html>

 <?php
 }

?>

Use the below code. 使用下面的代码。 You have missed the closing brace 你错过了大括号

if(!$_GET){
            header('location:index.php');
        }else{
            $language['english'] = array('url' => 'http://example.com');
            $language['chinese'] = array('url' => 'http://example1.com');
            $language['japanese'] = array('url' => 'http://example2.com');
            if(isset($_POST['submit'])){
                $count_me_in = sanitize($_POST['con_in']);
                $email = sanitize($_POST['email']);
                $comments = sanitize($_POST['comments']);
                $ip = $_SERVER['REMOTE_ADDR'];
                include 'connect.php';
                $sql = "INSERT INTO $table_name (count_me_in, email, comments, REMOTE_Addr) VALUE (".
                        PrepSQL($count_me_in) . ", " .
                        PrepSQL($email) . ", " .
                        PrepSQL($comments) . ", " .
                        PrepSQL($ip) . ")";
                if(mysqli_query($conn, $sql)){  /// this condition not working
                    echo "Thanks for submitting";
                    //echo "<script type='text/javascript'>alert('Thank you for your feedback');</script>";
                } else {
                    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM