We help IT Professionals succeed at work.
Get Started

Have a MySQL Database, PHP Form isn't working, but connection is Successful

mSprout
mSprout asked
on
230 Views
Last Modified: 2016-03-30
I created a PHP form, and I would like to record the results to a database. When I test the connection file on its own it is successful. When I attempt to include the file with the connection instead, the form does not save the information? Am I missing a step here?

<body onload="myUploadFunction()">
  <!-- Primary Page Layout
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <div class="container">
    <div class="row">
      <div class="one column" style="margin-top: 2%">


      <?php
         if(isset($_POST['add'])) {
         require '*********.php';
            
            if(! get_magic_quotes_gpc() ) {
               $PTitle = addslashes ($_POST['PTitle']);
               $PContent = addslashes ($_POST['PContent']);
            }else {
               $PTitle = $_POST['$PTitle'];
               $PContent = $_POST['PContent'];
            }
            
            $PType = $_POST['PType'];
            $PDisplay = $_POST['PDisplay'];
            $POrder = $_POST['POrder'];
            
               
            mysql_select_db('**************');
            $retval = mysql_query( $sql, $conn );
            
            if(! $retval ) {
               die('Could not enter data: ' . mysql_error());
            }
            
            echo "Entered data successfully\n";
            
            mysql_close($conn);
         }else {
            ?>
            

         <form method = "post" action = "dor.php">
  <fieldset>
    <legend>Create A Page</legend>
    Title: <input type="text" name="PTitle"> Page Type: <select name="PType">
  <option value="home">Home</option>  
  <option value="event">Event</option>
  <option value="vehicle">Vehicle</option>
  <option value="testimonial">Testimonial</option>
  <option value="special">Special</option>
  <option value="about">About</option>
  <option value="quote">Quote</option>
</select> Page Order: <input type="text" name="POrder"> 
  <textarea id="PContent">Please enter text and images only. Images will automatically be formatted based on the number of images included.

</textarea>  
<br>
    <select name="PDisplay">
  <option value="False">Hide</option>  
  <option value="True">Show</option>
</select><input type="submit" id="add" value="Save">
  </fieldset>
Upload New Image:
<input type="file" id="myFile" multiple size="50" onchange="myUploadFunction()">


<p id="demo"></p>
    
<script>
function myUploadFunction(){
    var x = document.getElementById("myFile");
    var txt = "";
    if ('files' in x) {
        if (x.files.length == 0) {
            txt = "Select one or more files.";
        } else {
            for (var i = 0; i < x.files.length; i++) {
                txt += "<br><strong>" + (i+1) + ". file</strong><br>";
                var file = x.files[i];
                if ('name' in file) {
                    txt += "name: " + file.name + "<br>";
                }
                if ('size' in file) {
                    txt += "size: " + file.size + " bytes <br>";
                }
            }
        }
    } 
    else {
        if (x.value == "") {
            txt += "Select one or more files.";
        } else {
            txt += "The files property is not supported by your browser!";
            txt  += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead. 
        }
    }
    document.getElementById("demo").innerHTML = txt;
}
</script>

<p><strong>Tip:</strong> Use the Control or the Shift key to select multiple files.</p>

Set Page Image:
Image: <input type="text" name="ImageLink">

</form>

     <?php
         }
      ?>
   
      </div>
    </div>
  </div>
<!-- End Document
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>
</html>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 3 Answers and 34 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE