Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

php - why it is not updating url in database

I have a page named ques.php. If the user's answer is correct he will be directed to next ques1.php. The answer posted by the user is checked by check.php and if it is correct I want to store the new URL (ques1.php) in the users account in the database.


check.php

<?php

  require_once("./include/membersite_config.php");

  if (!$fgmembersite->CheckLogin()) {
    $fgmembersite->RedirectToURL("login.php");
    exit;
  }

  mysql_connect("localhost", "root", "") or die(mysql_error()); 
  mysql_select_db("simplelogin") or die(mysql_error()); 

  $data = mysql_query("SELECT * FROM member") or die(mysql_error()); 

  while($info = mysql_fetch_array( $data )) {
    // print $info['username'];
    if ($info['username'] == $fgmembersite->UserName()) {
      $fullname = $info['name'];
      $username = $info['username'];
      $password = $info['password'];
      $email = $info['email'];
      $url = $info ['url'];
      break;
    }
  }

  $answer = $_POST['answer'];
  if ($answer == "correct") {
    "UPDATE `simplelogin`.`member`
     SET `url` = 'ques1.php'
     WHERE
       `member`.`name` = '$fullname' 
       AND `member`.`email` = '$email'
       AND `member`.`username` = '$username' 
       AND `member`.`password` = '$password' 
       AND `member`.`confirmcode` = 'y'
       AND `member`.`url` = '$url'";

    //in place of above update query i had also used
    //"UPDATE  member 
    //SET url = 'ques1.php'
    //WHERE username = '$username'"

    Header("Location:ques1.php");

  } else {

    Header("Location: ques.php");

  }

?>

function UserName() {
  return isset($_SESSION['user_name'])?$_SESSION['user_name']:'';
}

login.php

<?php

  require_once("./include/membersite_config.php");

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

    if ($fgmembersite->Login()) {

      //$fgmembersite->RedirectToURL("login-home.php");

      mysql_connect("localhost", "root", "") or die(mysql_error()); 
      mysql_select_db("simplelogin") or die(mysql_error());  

      $data = mysql_query("SELECT * FROM member") or die(mysql_error()); 
      while ($info = mysql_fetch_array( $data )) {
        if ($info['username']==($fgmembersite->SafeDisplay('username'))) {
          $url = $info['url'];
          break;
        }
      }

      $fgmembersite->RedirectToURL("$url");

    }
  }

?>

In login.php I am retrieving the URL from the database and redirecting the user - by default URLfor the user is ques.php.

Why is my query not updating the url in my database?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
"UPDATE `simplelogin`.`member` SET `url` = 'ques1.php' WHERE 
  `member`.`name`  ='$fullname' 
AND `member`.`email` = '$email' AND `member`.`username` = '$username' 
AND `member`.`password` = '$password' 
AND `member`.`confirmcode` = 'y' AND `member`.`url` = '$url'" ;

Doesnt appear to be running as a query, you haven't placed it within the mysql_query() function so it has no idea what you are trying to do with that statement.

Try this instead:

mysql_query(
"UPDATE `simplelogin`.`member` SET `url` = 'ques1.php' WHERE 
`member`.`name`  ='$fullname' 
AND `member`.`email` = '$email' AND `member`.`username` = '$username' 
AND `member`.`password` = '$password' 
AND `member`.`confirmcode` = 'y' AND `member`.`url` = '$url'");

Updated due to comments below:

Try this, it's been rewritten and simplified and should work, if not please port of you get the error message or not

mysql_query("
    UPDATE
        member
    SET
        url = 'ques1.php'
    WHERE
        name = '$fullname'
    AND
        email = '$email'
    AND
        username = '$username'
    AND
        password = '$password'
    AND
        confirmcode = 'y'
    AND
        url = '$url'
") or die('Unable to update members URL: ' . mysql_error());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...