We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Thanks,

    If I set the id to anything other than the id of the document it is taking me to the error page. I don’t want the form to be sent according to the ID, I just want it to use self.

    If I set id to the id of the document it displays the username I typed in followed by the congrats message, however the information is not being sent to the database.

    I will keep trying but so far it’s nothing... I noticed that the connection message isn’t appearing. If it was connecting or not it should display the message.
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 4041
      • 788 Posts
      Sorry, I basically copied what you had in the previous post and reformatted it.
      Note that I changed the "table" to "phpwork" in the insert statement and also changed id to Uid (in case this is conflicting with MODx id).
      As far as the connection message, the way it was would only show if it does not connect.
      Try this version and see if it is any better smiley
      <?php
      
      $output ="";
      $output .="
      <html>
      <head>
      <title>Form to DB</title>
      </head>
      <body>";
      
      // check if $_POST['Uid'] is set, if so do the db stuff
      if(isset($_POST['Uid'])){
      $conn = mysql_connect("localhost", "mydb", "pass")
      or die("no connection" .mysql_error());
      $db = mysql_select_db("phpwork")
      or die("connected" .mysql_error());
      
      if($conn){
        $output .="<p>Conn: yes</p>";
      }
      if($db){
        $output .="<p>db: yes</p>";
      }
      
      $Uid = $_POST['Uid'];
      $username = $_POST['username'];
      $password = $_POST['password'];
      $query = "INSERT INTO phpwork (id, username, password) VALUES ('$Uid', '$username', '$password')";
         if($query){
           $output .="<p>Congratulations ".$username.", the form was filled out</p>";
         }else{
           $output .="<p>An error occured while saving the information</p>";
         }
         
      }else{
      // show the form
      $output .="<p>
      <form action='".$PHP_SELF."' method='post'>
      Username: <input type='text' name='username'
      value=''><br>
      Password: <input type='password' name='password'
      value=''><br>
      id: <input type='text' name='Uid'
      value=''><br>
      
      <input type='submit' name='submit' value='Register'>  
      <input type='reset' value='Clear\">
      </form>
      </p>";
      }
      
      $output .="</body>
      </html>
      ";
      
      echo $output;
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution