PHP不会在联盟脚本中将数据保存到数据库

时间:2016-07-01 19:29:27

标签: php mysql

我是新来的php,我有一个联盟会员脚本,当我填写表单并提交表格时,在添加广告系列页面中"广告系列已添加"但表格数据没有保存在数据库中,

我的添加广告系列表单

<?php

session_start();

if(isset($_SESSION['myadminusername']))
{
    $myusername = $_SESSION['myadminusername'];

     include '../config.php';

     header( 'Content-Type: text/html; charset=utf-8' );
}
else
{
     echo"<script type='text/javascript'>
     window.location.href='login.php';
     </script>";
}

if( isset($_POST['text']) )
{ 

     mysql_query("Insert into link values ('', '".addslashes($_POST['text'])."', '".addslashes($_POST['caption'])."', '".addslashes($_POST['description'])."', '".$_POST['img']."', '".$_POST['site_us_pc']."', '".$_POST['site_oth_pc']."', '".$_POST['site_us_mob']."', '".$_POST['site_oth_mob']."', '".$_POST['status']."', '".$_POST['catname']."', '".$_POST['us_cpc']."', '".$_POST['uk_cpc']."', '".$_POST['au_cpc']."', '".$_POST['in_cpc']."', '".$_POST['oth_cpc']."', '".$_POST['pak_cpc']."', '".$_POST['star']."', '0')");

     echo"<script type='text/javascript'>
     alert('Campaign Added');
     </script>";
}

?>

<!doctype html>
<!--[if lte IE 9]> <html class="lte-ie9" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--> <html lang="en"> <!--<![endif]-->
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Remove Tap Highlight on Windows Phone IE -->
    <meta name="msapplication-tap-highlight" content="no"/>

    <link rel="icon" type="image/png" href="assets/img/favicon-16x16.png" sizes="16x16">
    <link rel="icon" type="image/png" href="assets/img/favicon-32x32.png" sizes="32x32">

    <title>Altair Admin v2.0.0</title>


    <!-- uikit -->
    <link rel="stylesheet" href="bower_components/uikit/css/uikit.almost-flat.min.css" media="all">

    <!-- flag icons -->
    <link rel="stylesheet" href="assets/icons/flags/flags.min.css" media="all">

    <!-- altair admin -->
    <link rel="stylesheet" href="assets/css/main.min.css" media="all">

    <!-- matchMedia polyfill for testing media queries in JS -->
    <!--[if lte IE 9]>
        <script type="text/javascript" src="bower_components/matchMedia/matchMedia.js"></script>
        <script type="text/javascript" src="bower_components/matchMedia/matchMedia.addListener.js"></script>
    <![endif]-->

</head>
<?php include 'head.php'; ?>

    <div id="page_content">
        <div id="page_content_inner">

            <h3 class="heading_b uk-margin-bottom">Blank Page</h3>

            <div class="md-card">
                <div class="md-card-content">
                    <div class="uk-grid" data-uk-grid-margin>
                        <div class="uk-width-1-1">

                                  <form method="post" action="campaign_add.php">
                                           <div class="form-group">
                                                <label>Campaign Title</label>
                                                <input class="md-input" name="text" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Suggested Caption</label>
                                                <input class="md-input" name="caption" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign Image Link</label>
                                                <input class="md-input" name="img" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign Description</label>
                                                <input class="md-input" name="description" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign US PC Link</label>
                                                <input class="md-input" name="site_us_pc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign Other PC Link</label>
                                                <input class="md-input" name="site_oth_pc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign US Mob Link</label>
                                                <input class="md-input" name="site_us_mob" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign Other Mob link</label>
                                                <input class="md-input" name="site_oth_mob" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign Status</label>
                                                <select name="status">
                                                     <option value="enable">Enable</option>
                                                     <option value="disable">Disable</option>
                                                </select>
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Campaign Category</label>
                                                <select name="catname">
                                                <?php
                                                $results = mysql_query("Select * from link_cat");
                                                while ($row = mysql_fetch_array($results))
                                                {
                                                     echo'<option value="'.$row['id'].'">'.$row['catname'].'</option>';
                                                }
                                                ?>
                                                </select>
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>US Pay per click (INR)</label>
                                                <input class="md-input" name="us_cpc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>UK Pay per click (INR)</label>
                                                <input class="md-input" name="uk_cpc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Australia Pay per click (INR)</label>
                                                <input class="md-input" name="au_cpc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>India Pay per click (INR)</label>
                                                <input class="md-input" name="in+cpc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Pakistan Pay per click (INR)</label>
                                                <input class="md-input" name="pak_cpc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Other Pay per click (INR)</label>
                                                <input class="md-input" name="oth_cpc" type="text">
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <label>Star</label>
                                                <select name="star">
                                                     <option value="false">No</option>
                                                     <option value="true">Yes</option>
                                                </select>
                                            </div>
                                            <br>
                                            <br>
                                           <div class="form-group">
                                                <input class="md-btn md-btn-primary" value="Add" type="submit">
                                            </div>
                                  </form>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <!-- google web fonts -->
    <script>
        WebFontConfig = {
            google: {
                families: [
                    'Source+Code+Pro:400,700:latin',
                    'Roboto:400,300,500,700,400italic:latin'
                ]
            }
        };
        (function() {
            var wf = document.createElement('script');
            wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
            '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
            wf.type = 'text/javascript';
            wf.async = 'true';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(wf, s);
        })();
    </script>

    <!-- common functions -->
    <script src="assets/js/common.min.js"></script>
    <!-- uikit functions -->
    <script src="assets/js/uikit_custom.min.js"></script>
    <!-- altair common functions/helpers -->
    <script src="assets/js/altair_admin_common.min.js"></script>


    <script>
        $(function() {
            // enable hires images
            altair_helpers.retina_images();
            // fastClick (touch devices)
            if(Modernizr.touch) {
                FastClick.attach(document.body);
            }
        });
    </script>

<div id="style_switcher">
    <div id="style_switcher_toggle"><i class="material-icons">&#xE8B8;</i></div>
    <div class="uk-margin-medium-bottom">
        <h4 class="heading_c uk-margin-bottom">Colors</h4>
        <ul class="switcher_app_themes" id="theme_switcher">
            <li class="app_style_default active_theme" data-app-theme="">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
            <li class="switcher_theme_a" data-app-theme="app_theme_a">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
            <li class="switcher_theme_b" data-app-theme="app_theme_b">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
            <li class="switcher_theme_c" data-app-theme="app_theme_c">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
            <li class="switcher_theme_d" data-app-theme="app_theme_d">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
            <li class="switcher_theme_e" data-app-theme="app_theme_e">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
            <li class="switcher_theme_f" data-app-theme="app_theme_f">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
            <li class="switcher_theme_g" data-app-theme="app_theme_g">
                <span class="app_color_main"></span>
                <span class="app_color_accent"></span>
            </li>
        </ul>
    </div>
    <div class="uk-visible-large">
        <h4 class="heading_c">Sidebar</h4>
        <p>
            <input type="checkbox" name="style_sidebar_mini" id="style_sidebar_mini" data-md-icheck />
            <label for="style_sidebar_mini" class="inline-label">Mini Sidebar</label>
        </p>
    </div>
</div>

<script>
    $(function() {
        var $switcher = $('#style_switcher'),
            $switcher_toggle = $('#style_switcher_toggle'),
            $theme_switcher = $('#theme_switcher'),
            $mini_sidebar_toggle = $('#style_sidebar_mini');

        $switcher_toggle.click(function(e) {
            e.preventDefault();
            $switcher.toggleClass('switcher_active');
        });

        $theme_switcher.children('li').click(function(e) {
            e.preventDefault();
            var $this = $(this),
                this_theme = $this.attr('data-app-theme');

            $theme_switcher.children('li').removeClass('active_theme');
            $(this).addClass('active_theme');
            $('body')
                .removeClass('app_theme_a app_theme_b app_theme_c app_theme_d app_theme_e app_theme_f app_theme_g')
                .addClass(this_theme);

            if(this_theme == '') {
                localStorage.removeItem('altair_theme');
            } else {
                localStorage.setItem("altair_theme", this_theme);
            }

        });

        // change input's state to checked if mini sidebar is active
        if((localStorage.getItem("altair_sidebar_mini") !== null && localStorage.getItem("altair_sidebar_mini") == '1') || $('body').hasClass('sidebar_mini')) {
            $mini_sidebar_toggle.iCheck('check');
        }

        // toggle mini sidebar
        $mini_sidebar_toggle
            .on('ifChecked', function(event){
                $switcher.removeClass('switcher_active');
                localStorage.setItem("altair_sidebar_mini", '1');
                location.reload(true);
            })
            .on('ifUnchecked', function(event){
                $switcher.removeClass('switcher_active');
                localStorage.removeItem('altair_sidebar_mini');
                location.reload(true);
            });

        // hide style switcher
        $document.on('click keyup', function(e) {
            if( $switcher.hasClass('switcher_active') ) {
                if (
                    ( !$(e.target).closest($switcher).length )
                    || ( e.keyCode == 27 )
                ) {
                    $switcher.removeClass('switcher_active');
                }
            }
        });

        if(localStorage.getItem("altair_theme") !== null) {
            $theme_switcher.children('li[data-app-theme='+localStorage.getItem("altair_theme")+']').click();
        }
    });
</script></body>
</html>

Database Table Column List screen short

1 个答案:

答案 0 :(得分:0)

你必须改变:

<input class="md-input" name="in+cpc" type="text">

为:

<input class="md-input" name="in_cpc" type="text">

并检查返回值:

if(isset($_POST['text']))
{ 
  $returnValue = mysql_query("Insert into link 
                              values ('', 
                                      '".addslashes($_POST['text'])."', 
                                      '".addslashes($_POST['caption'])."', 
                                      '".addslashes($_POST['description'])."', 
                                      '".$_POST['img']."', 
                                      '".$_POST['site_us_pc']."', 
                                      '".$_POST['site_oth_pc']."', 
                                      '".$_POST['site_us_mob']."', 
                                      '".$_POST['site_oth_mob']."', 
                                      '".$_POST['status']."', 
                                      '".$_POST['catname']."', 
                                      '".$_POST['us_cpc']."', 
                                      '".$_POST['uk_cpc']."', 
                                      '".$_POST['au_cpc']."', 
                                      '".$_POST['in_cpc']."', 
                                      '".$_POST['oth_cpc']."', 
                                      '".$_POST['pak_cpc']."', 
                                      '".$_POST['star']."', 
                                      '0')");
  if ($returnValue === FALSE) $message = 'Failure: '.mysql_error();
                         else $message = 'Campaign Added';
  echo"<script type='text/javascript'>
         alert('$message');
       </script>";
}

我无法保证我发现了所有错误。您可能会发现我的布局有点奇怪,但我可以更好地阅读它。

注意: PHP的mysql扩展已被删除,并且永远不会在查询中直接插入用户输入。