duanhe4155 2010-02-23 22:11
浏览 61
已采纳

电子邮件未从表单插入到mysql数据库中

I have a newsletter for one of my sites and I can't the email posted to the mysql database.

Here is the html form code: subscribe

        <h2>newsletter</h2>
        <br /><input type="text" name="email" value="" id="email" />

        <input type="button" name="submit" onclick="submit_it()" value="OK" />

        <script type="text/javascript" charset="utf-8">

            function submit_it() {

                var cate_value = $('#cate').val();
                var email_value = $('#email').val();

                $.post("subscribe.php", { email: email_value , cate: category_value }, function(response) {

                    if (response!='') {alert(response)};
                    alert('ok');

                });

            }

        </script>


</body>

And here is the php processing code:

$host = "localhost";
$user = "some_user";
$password = "some_pass";
$database = "news";


$server = mysql_connect($host, $user, $password);
$connection = mysql_select_db($database, $server);


function sql_quote($value) {

    $value = str_replace('<?','',$value);
    $value = str_replace('script','',$value);

    if (get_magic_quotes_gpc()) {
        $value = stripslashes($value);
    }
    if (!is_numeric($value)) {
        $value = "'" . mysql_real_escape_string($value) . "'";
    } else {
        if ((string)$value[0] == '0') {
            $value = "'" . mysql_real_escape_string($value) . "'";
    }}
    return $value;
}



$q = "INSERT INTO emails (email,cate) VALUES (".sql_quote($_POST['email']).",".$_POST['cate'].")";

mysql_query($q);

?>

Any help would be much appreciated because I've been fooling with this for the last 5hrs trying to make it work and I just can't figure it out plus I can't look at it anymore. My eyes hurt now. lol Thanks again.

  • 写回答

4条回答 默认 最新

  • drhg24275 2010-02-23 22:41
    关注

    You should definitely rewrite your code as hobodave suggests. I think something is wrong with your db configuration, though. Try this in the meantime, to execute your query:

    $result = mysql_query($q);
    if( $result ){
        echo( 'OK' );
    } else {
        echo( 'Invalid query: ' . mysql_error() );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?