dqrb4228 2013-12-26 17:20
浏览 40
已采纳

为什么我的订阅页面没有将字段放在MySQL数据库中?

I'm with a doubt,

I'm trying sending data to my database but it doesn't insert it them. How can i put them to send it?

index.php (script part):

<div id="wel">
        <p id="title-call">Junta-te <font color="gray">a n&oacute;s!</font></p><hr color="#c96308"  noshadow />
        <p id="subx">Percorre este mundo e torna-te o treinador n&uacute;mero <font color="#c96308">UM</font>!</p> 
    </div>  
    <div id="loading"><br /></div>
    <div id="warn2"><br /></div>
    <div id="success"><br /></div>
    <div id="subscribe">
        <form id="sub" action="" method="POST" >
            <input type="text" name="username" id="username" placeholder="Escreve aqui o teu Nome..." /><br />
            <br />
            <input type="text" name="email" id="email" placeholder="Escreve aqui o teu E-mail..." /><br /><br />
            <input type="submit" id="submit" value="Subscrever" />
        </form>
    </div>
<script type="text/javascript">
    $(document).ready(function() {

        $("#sub").submit(function() {

            if($("#username").val()==""||$("#email").val()=="") {
                $("#warn2").hide(36000);
                $("#loading").css("display:inline");
                $("#loading").html("<img src='images/ajax-loader.gif' width='1%' height='3%' /> A carregar...");
                $("#loading").fadeIn(200);
                $("#loading").fadeOut(200);
                $("#warn2").css("display:none");
                $("#warn2").html("Por favor escreve o teu nome e/ou email!<br />");
                $("#warn2").hide(36000);
                $("#warn2").fadeIn(1000);                   
                $("#warn2").css("display:inline");
                $("#warn2").fadeOut(7000);

            }

            else {
                var s = $("#sub").serializeArray();

                $.ajax({
                    url: "subscribe.php",
                    method: "POST",
                    data: s,
                    success: function() {


                            $("#success").css("display:none");              
                            $("#success").hide(36000);
                            $("#loading").css("display:inline");
                            $("#loading").html("<img src='images/ajax-loader.gif' width='1%' height='3%' /> A carregar...");
                            $("#loading").fadeIn(200);
                            $("#loading").fadeOut(200);
                            $("#success").css("display:none");
                            $("#success").html("A tua subscri&ccedil;&atilde;o foi efectuada com successo!");
                            $("#success").hide(36000);
                            $("#success").fadeIn(1000);                 
                            $("#success").css("display:inline");
                            $("#success").fadeOut(7000);

                    }

            });

        }

        return false;




    });

        $("#MGa").click(function() {

            $("#hidGames").css("display: inline");
            $("#hidGames").fadeToggle(1000);


            return false;
        });

        $("#MGa").mouseover(function() {

            $("#arrow").html('<img src="images/arrow_wbm_hover.png" width="1%" height="1%" />');


        });

        $("#MGa").mouseout(function() {

            $("#arrow").html('<img src="images/arrow.png" width="1%" height="1%" />');


        });


        $("#arrow").html('<img src="images/arrow.png" width="1%" height="1%" />');

    });
</script>

subscribe.php :

<?php

include_once('db.php');

$username = $_POST["username"];
$email = $_POST["email"];
$date = date("Y-m-d h:i:s:A");


          $sql = mysql_query("INSERT INTO subscribers VALUES('','$username','$email','$date')");

         // mail function //

         $to = $email;
         $header = "From: info@wbm.pt";
         $header. = "Content-Type: text/html;";
         $subject = "Bem-vindo ao WBM!";
         $body = "
         Bem vindo ao WBM (World Basket Manager) <b>$username</b>,<br />
         <br />
         S&ecirc; o treinador n&uacute;mero <i>UM</i> deste mundo de treinadores.<br />
         - Cria a tua equipa;<br />
         - Compra e Vende jogadores;<br />
         - Calend&aacute;rio real;<br />
         - Equipas Originais (NBA);<br />
         - Est&aacute;dios;<br />
         - Forma as tuas pr&oacute;prias t&aacute;ticas;<br />
         <br>
         Tudo isto no mundo de treinadores de basquetbol!<br />
         Lan&ccedil;amento da vers&atilde;o BETA:<br />
            <b>Data prev&iacute;sivel: <i>25 de Maio de 2014</i></b><br />
         <br />
         Muito Obrigado,<br />
         <b>Equipa WBM</b>
         <br />
         <br />
         <h6>N&atilde;o responder a este e-mail!</h6>

         "; 

         // mail //

         mail($to,$header,$subject,$body);

    $rw = mysql_query("SELECT * FROM subscribers");

    $rows = mysql_num_rows($rw);

    if($rows!=0) {
        $nrow = $rows;
    } 
    else {

    }

         $to1 = "cell phone number";
         $header1 = "From: 15030@wbm.pt";
         $header1. = "Content-Type: text/play;";
         $subject1 = "Bem-vindo ao WBM!";
         $body1 = "
            T&ecirc;m $nrow que se subscreveram.

            Muito Obrigado.
            (Não responder a esta mensagem)

         "; 

         //sms to my cell phone //
         mail($to1,$header1,$header1.,$subject1,$body1);


?>

db.php:

<?php

$connect = mysql_connect('localhost','root','');
mysql_select_db('subscribers');

?>

What can I do to this thing work guys?

  • 写回答

1条回答 默认 最新

  • dongwo5449 2013-12-26 17:24
    关注

    You need to be checking for mysql errors, that would give you a big clue.

    $query = "INSERT INTO subscribers VALUES('','$username','$email','$date')";
    $sql = mysql_query($query) or throw new Exception("Query Failed: {$query}. Error: ".mysql_error());
    

    Your code is open to SQL Injection, you should really be using MySQLi or PDO at this point, and if you're going to stick with mysql, escape your data.

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

报告相同问题?

悬赏问题

  • ¥15 eNSP拓扑图配置实验
  • ¥20 有没有兄弟会替换fmod studio的.bank文件内的音效?
  • ¥20 如何解决访问网址被屏蔽的情况
  • ¥15 本地运行的vue2项目,使用内网穿透,前端界面一直转圈圈
  • ¥20 powerbuilder datawindow控件导出Excel数据,可不可以不自动覆盖原数据,而是在后面新插入入数据。
  • ¥100 无轴承永磁同步电机控制
  • ¥15 eps里添加本地倾斜模型
  • ¥15 telegram 问题
  • ¥15 nrf52810-c三个a 程序
  • ¥50 求一个半透明没有锯齿的圆角窗体的实现例子