2014-11-30 23:21 阅读 133


I'm trying to write a simple script to write some data to mysql then read it. My code is working without a problem alone but I'm trying to use it inside a WordPress page, this is the point problem starts.

I have created a template file for WordPress, and using this template to create the page. Page shows up without a problem but whenever I try to submit the form inside it (my custom php form) it forwards me to index.php .

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<span>Enter Your Code : </span><br/>
<input type="text" name="sha256"><br/>
<p align = right><input type="submit" name="shaSubmit" value="Submit" /></p>

this is my form (inside custom php), and as you can see it posts the data to itself. At the the start of my custom php code I have


But it doesn't matter, as soon as I click on button, it forward me to

Btw, this custom php is on a page with such url

How can make this form work ?

ps. Code above is for reading from mysql.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dongyan1899 dongyan1899 2014-12-01 07:26

    You need to change 2 things.

    (1)make action=""

    don't need to use action=" echo htmlspecialchars($_SERVER["PHP_SELF"])"


    the code ....


    点赞 评论 复制链接分享
  • drzk21632 drzk21632 2014-11-30 23:25

    You're using the following conditional statement if(isset($_POST['Submit'])) along with the submit button's named element name="shaSubmit".

    You need to make those match.

    Either by changing the name of your submit button to name="Submit"

    or by changing your conditional statement to if(isset($_POST['shaSubmit']))

    which is why your code is failing because of the conditional statement you've set is relying on a form element named "shaSubmit".

    点赞 评论 复制链接分享