使用Google OpenID的PHP编辑帖子 [英] PHP Edit Post with Google OpenID

查看:55
本文介绍了使用Google OpenID的PHP编辑帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的网站编写一个编辑帖子页面,该页面使用google openid登录到自己的网站,但是我只得到一个空白页面,而不是编辑表单.这是我正在使用的代码:

I'm trying to code an edit post page for my site which posts to itself using a google openid logon, however i just get a blank page, instead of the edit form. Here's the code i'm using:

<html>
  <head>
    <title>BQuotes</title>
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link href="votingfiles/voting.css" rel="stylesheet" type="text/css" />
    <script src="votingfiles/voting.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
    <link rel="stylesheet" type="text/css" href="http://bquotes.me/mystyle-a.css">
    <script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
    <style>
      .head_text {
        color: #ffffff;
      }
      a {
        text-decoration: none;
      }
    </style>

    <script type="text/javascript">
      $('#g-login').bind('click', function (event) {
        // event.preventDefault();
        // $('#form-id').attr('action', 'google-login.php').trigger('submit');
        alert("Clicked");
      });
    </script>
  </head>
  <body style="color:#d4ffaa">


    <!-- BQ Edit Post Start -->
    <div data-role="page" id="editPost">
      <div data-role="header" style="background-color:#5FBF00">
        <h1 class="head_text">BQuotes: Edit Statuses</h1>
      </div>
      <div data-role="main" class="ui-content">

        <?php





          ?>


      </div>



         <?php
          define ('HOSTNAME', 'host');
          define ('USERNAME', 'user');
          define ('PASSWORD', 'pass');
          define ('DATABASE_NAME', 'db');

          $db = mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die ('I cannot connect to MySQL.');

          mysql_select_db(DATABASE_NAME);

          $tbl='table';
          $id=$_POST['pid'];

          $query="SELECT * from $tbl WHERE $id=id";
          $result = mysql_query($query);

          while($row = mysql_fetch_array($result)) {
          $id=$row['id'];
          $username=$row['username'];
          $message=$row['message'];
          $tag=$row['tag'];



         session_start();
              if($_SESSION['myusername'] != null &&  isset($_SESSION['myusername'])){
              echo "<form action='logout.php' method='post' id ='form-logout' data-ajax='false'>
                    <br/><input type='submit' value='Logout'/>";
              echo "</form>";
              echo "<div style='margin-left:20px;'>Logged In As:  ".$_SESSION['myusername']."</div>";

             echo "<form name='post-edit' action='' method='post'>";
             echo "<input type='hidden' name='id' value=".$row['id'].">";
             echo "<input type='hidden' name='username' value=".$row['username'].">";
             echo "<textarea name='message' value=".$row['message'].">";
             echo "<input type='text' name='tag' value=".$row['tag'].">";
             echo "<input type='submit' name='submit' value='Edit!'>";
             echo "</form>";

              }
            else if($_SESSION['myusername'] == null){
              echo "<form action='google-login.php?login=true' method='post' id ='form-id' data-ajax='false'>";    
                 echo "<span class='loginreq'>Login to Edit</span>";           
                echo "<br/><input type='submit' value='Login with Google'/>";
                echo "</form>";
            }
            }



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

          $query = "UPDATE mybq_post_txt_main SET message=$message, tag=$tag WHERE id=$id ";

          $result = mysql_query($query);

          while ($row = mysql_fetch_array($result)) {

          echo "Your post has been edited to:";<br>
          echo $row['message'];
          echo $row['tag'];
          }

          mysql_free_result($result);
          mysql_close();

          }

        ?>



        <a href='mybq-index.php'>Home</a>


      </div>


  </body>
</html>

任何帮助将不胜感激. (不要管PHP SQL语句,稍后我将把它们转换为PDO.)

Any help will be appreciated. (never mind the PHP SQL statements, I will convert them to PDO later).

推荐答案

此处是有效的代码(代码段下方的完整代码). 最初的错误是您的帖子已被编辑为:"后的换行符(<br>),该格式未正确设置为php. 其他错误是正确地关联了$ _GET变量,错误的表名以及初始的"while"条件的错误循环.

Here is the code that worked (The Full code below the snippet). The initial bug was the line break ( <br> ) after the "your post has been edited to:" which was not properly formatted for php. The other bugs were relating the $_GET variable properly, wrong table name, and wrong looping of the initial 'while' condition.

谢谢!

这篇关于使用Google OpenID的PHP编辑帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆