du94414 2014-02-05 00:04
浏览 29
已采纳

目录与我的PHP页面冲突?

So this question is sort of complicated, so I'm going to be as descriptive as possible.

I recently started implementing AJAX into my website, so I thought I'd improve user experience by making it so if you didn't have an account, you could just click on the link below the login box and it would just load the registration.php file from the views folder.

And it is just giving me a hard time. The registration just goes back to the index page and it doesn't update the database at all. But when I go to the actual registration page that is being loaded, it works. Since I'm loading it from the index.php file that is in the root of the folder, does that mean I must change the nature of the links in the registration page?

Here's my JavaScript:

$(document).ready(function(){
    /* Switch to registration */

    $('a#registration').click(function(){
            $('#login').load('./views/registration.php');
    }); 
});

Here's my registration page code:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method='post'>

<label> Username </label><br><input type='text' name='reg_username' size='20'>

<?php

if (isset($_POST['reg_username'])) {
//standard validation
}
?>
<br>
<label> E-Mail </label><br><input type='email' name='email' size='20'>
<?php
if (isset($_POST['email'])) {
//standard validation
}
?>
<br>
<label> Password: </label><br><input type='password' name='reg_password' size='20'>
<?php
if (isset($_POST['reg_password'])) {
//standard validation
}
?>
<br>
<input type='submit' name='submitted' value='Register'>
</form>

<?php
if (isset($_POST['submitted'])) {
if ($valid) { 
    $username = $_POST['reg_username'];
    $email = $_POST['email'];
    $password = $_POST['reg_password'];
    $register_query = sprintf("INSERT INTO users(username, email, password) values('%s', '%s', '%s');", mysql_real_escape_string($username), 
        mysql_real_escape_string($email), mysql_real_escape_string(crypt($password, $username)));
    require_once '../models/dbconnect.php';
    database_connect();
    require_once '../models/database_validation.php';
    account_duplicate($username, $email);
    if ($valid) {
    $result = mysql_query($register_query);
    if ($result) {
        echo "Registration Successful!";
    } ELSE {
        echo "I think something went wrong...";
    }
    }   
}
}
?>

I think the focus is on the form action and the require functions on the page. Am I using the require function right? What do you think what's wrong?

If you want to play with it hands on, here's the repository for it. It's my first open source project.

https://github.com/Lalien/Test_Site

  • 写回答

1条回答 默认 最新

  • drwiupraq047311240 2014-02-05 00:12
    关注

    PHP_SELF sends you to the page that is loaded on the browser, in this case, the index page. Change your form action to the registration page so that it will send the form to the correct page.

    Plus, because you are missing echo in there, your action is a blank string, which will always submit to the current page.

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

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)