2

I'm using localhost and I want to go from index.php to register.php using a simple hyperlink. They are in the same folder. I can access register.php if I manually type it in the address bar.

I tried:

<button name="register"><a href="register.php">Register</a></button>

<button name="register"><a href="http://localhost:8080/MyProjectName/register.php">Register</a></button>

<button name="register"><a href="MyProjectName/register.php">Register</a></button>

Solution:

<form action="register.php">
    <input type="submit" value="Register">
</form>
Bacchus
  • 515
  • 8
  • 22

4 Answers4

1

After seeing your many (incremental) edits, I have decided to post the following.

Now knowing what you really wanted to do here from the get go...

FYI: Buttons only work when set inside <form></form> tags, or when you're using JS/Ajax.

You've made quite a few edits and should have posted your intention from the start.

What you could have done was

<a href="file.php"><button>Text</button></a> which works.

and not the other way around <button><a href="file.php">Text</a></button> (won't work).

Or others such as:

<a href="#" class="btn btn-info" role="button">Link Button</a> (bootstrap style)
<button type="button" class="btn btn-info">Button</button>
<input type="button" class="btn btn-info" value="Input Button">
<input type="submit" class="btn btn-info" value="Submit Button">

or a standard hyperlink that leads to another page, which was your original post https://stackoverflow.com/revisions/33756366/1 where you had the missing </a> closing tags.

Sidenote: Forms default to a GET method if omitted.

<form></form>

If you want to use a POST method, it needs to be specified.

<form method="post"></form>

Consult the following:

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
0

If the register.php is in the same direction as your index the first relative path ought to work.

alps
  • 183
  • 1
  • 10
0

simply use <a href="register.php">Register</a> you may have to use css with some class or id to make you a look like a button

goupil
  • 175
  • 10
0

The best practice to make this perfect is define your host like

define('HOST_URL', 'http://localhost');

and now you just ned to add this with your page link like

<button name="register"><a href="<?=HOST_URL?>/register.php">Register</a></button>

<button name="register"><a href="<?=HOST_URL?>/MyProjectName/register.php">Register</a></button>

<button name="register"><a href="<?=HOST_URL?>/MyProjectName/register.php">Register</a></button>

Now from one place you can change. Not to worry for change manually and searching them. Hope this helps

Ghulam Ali
  • 357
  • 4
  • 17