0

I have a have rented a server at www.unoeuro.com (I dont know if this matters) When i submit the form it gives me "HTTP Error 405.0 - Method Not Allowed"

<?php

define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_HOST', '')

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
 die('Could not connect: ' .mysql_error());
}

$db_selected = mysql_slect_db(DB_NAME, $link);

if (!$db_selected) {
 die('Could not connect: ' .mysql_error());
}

$value = $_POST['username'];

$sql = "INSERT INTO test (username) VALUES ('$value')";

if (!mysql_query($sql)) {
 die('Error: ' . mysql_error());
}
mysql_close();
?>
<!doctype HTML>
  <form action="test.php" method="post">
    <p>Username: <input type="text" name="username" /><p>
    <input type="submit" value="Submit" />
  </form>

Can anyone tell me what i am doing wrong? Just ask me for screenshots of anything you can use to help!

Sorry if the issue is obvious. This is my first time working with any kind of database, PHP and such.

Thanks!

Mads Nielsen
  • 106
  • 1
  • 5
  • 14
  • 1
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Feb 20 '16 at 19:38
  • 1
    You are making a post request. The server is saying that you aren't allowed to make a POST request to that URL. There's no much more to say without knowing more about the system. I'd guess you were using IIS which I have an impression needs explicit configuring to allow POST requests to any given URI. – Quentin Feb 20 '16 at 19:39
  • @Quentin Can i give you any helpful information? To help you "knowing more about the system"? – Mads Nielsen Feb 20 '16 at 19:48
  • Well, you could start by confirming my guess … but since I haven't used IIS since 2001 I'd then have to direct you to Google. – Quentin Feb 20 '16 at 19:50
  • @Quentin How do it configure the IIS? Sorry im so new – Mads Nielsen Feb 20 '16 at 19:52
  • I dont have acces to the host pc. Other than uploading files. – Mads Nielsen Feb 20 '16 at 19:53
  • Then talk to the host. I don't know how to configure IIS when I do have access to the PC (other than "Look in Control Panel, maybe"), I haven't used it for a decade and a half. – Quentin Feb 20 '16 at 19:56
  • @Quentin Ok i will do that. Thanks anyway! – Mads Nielsen Feb 20 '16 at 19:57

1 Answers1

1

First of all, if those are your actual database username and password, you're going to want to be changing those sharpish before someone else changes them for you :)

It's most likely down to how your server is configured to handle PHP files.

The first thing I would check is that the package you are leasing is designed to host PHP scripts. Looking at the UnoEuro package details (https://en.unoeuro.com/products.php#specs) it states 'ASP or PHP'. Is it possible that you are using a server setup for ASP?

If you are definitely on a PHP package, I would contact the service provider. They should know everything there is to know about configuring your server.

Also; there is a typo in your code 'mysql_slect_db'.

UberDoodles
  • 618
  • 5
  • 13
  • Thanks! The server is setup for ASP. But what am i supposed to use instead of PHP when i am runnig ASP? – Mads Nielsen Feb 21 '16 at 07:34
  • For a server that is setup for ASP and not PHP, you have to write ASP (Active Server Pages) scripts. ASP is one of the other popular server-side scripting technologies besides PHP. To put it simply, think of ASP as Microsoft's equivalent of PHP; they do the same job, but the languages and syntax are different and they may have slightly different capabilities. – UberDoodles Feb 21 '16 at 08:09