0

I want to have a form that updates mySQL database. The database is called userStuff. When I hit sumbit on my form, it just takes me to my php file and does not actually update the database. Any idea why? This is my html code:

<form method="post" name="update" action="update.php" /> 
  Name:   <input type="text" name="username" />
  Password:   <input type="text" name="password" /> 
  <input type="submit" name="Submit" value="update" />
</form>

Here is my php code:

<?php 
  mysql_connect("localhost", "", "") or die("Connection Failed");
  mysql_select_db("userStuff")or die("Connection Failed");
  $username = $_POST['username'];
  $password = $_POST['password'];
  $query = "UPDATE test SET password = '$password' WHERE name = '$username'";
  if(mysql_query($query)){
    echo "updated";
  }
  else{
    echo "fail";
  }
?>
Logan Wayne
  • 5,961
  • 16
  • 31
  • 48
  • 2
    What do you mean by "it just takes me to my php code"? Does the php run? Or do you see all of your code in the web browser? – kittykittybangbang Sep 01 '15 at 01:02
  • @kittykittybangbang it just shows my code in the web browser – Zachary Cheshire Sep 01 '15 at 01:05
  • Do you have php installed on the machine your site is running on? – kittykittybangbang Sep 01 '15 at 01:06
  • Make sure you [enable errors in PHP](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php). Also make sure your PHP is surrounded by ``. Finally you want to avoid `mysql` and use the updated `mysqli` or `PDO`. Along with that escape your input before doing a query with `mysqli_read_escape_string()`. – Spencer Wieczorek Sep 01 '15 at 01:07
  • If you see the code on your browser then php is not installed on your server. BTW you should be using mysqli since mysql is deprecated – CodeGodie Sep 01 '15 at 01:08
  • @codegodie I have it installed now, but im getting the connection failed message – Zachary Cheshire Sep 01 '15 at 01:20
  • So if you are seeing errors, why did you say you are seeing the code in your browser? What errors are you seeing? – CodeGodie Sep 01 '15 at 01:23
  • @codeGodie Now i'm seeing the "fail" message. It is a result of the echo failing, but i'm not sure what that means – Zachary Cheshire Sep 01 '15 at 01:27

0 Answers0