0

I have some PHP code and when executed the code doesn't send the values to the other PHP page on my site. My permissions are 755.

Page 1:

       <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bay Area Buckets</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
  <style>

  .navbar {
    margin-bottom: 0;
    background-color: #ff4d4d;
    z-index: 9999;
    border: 0;
    font-size: 12px !important;
    line-height: 1.42857143 !important;
    letter-spacing: 4px;
    border-radius: 0;
}

.navbar li a, .navbar .navbar-brand {
    color: #fff !important;
}

.navbar-nav li a:hover, .navbar-nav li.active a {
    color: #f4511e !important;
    background-color: #fff !important;
}

.navbar-default .navbar-toggle {
    border-color: transparent;
    color: #fff !important;
}
.resize {
   border: 2px solid;
    padding: 20px; 

    resize: vertical;
    overflow: auto;


}
textarea {
    width: 100%;
}

  </style>
</head>
<body>

 <nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
     <a href="index"><img src="https://pbs.twimg.com/media/CnvlpmKUAAArtx_.png:large" alt="Logo" height="60" width="60"></a> 
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right">

     <li><a href="index">HOME</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="about">ABOUT</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="hats">HATS</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="socialMedia">SOCIAL MEDIA</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="cart">Cart</a></li>

      </ul>
    </div>
  </div>
</nav>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
    <div>
        <center><h1 ><span style="color:#ff6666;">Contact Us</span></h1></center>
    </div>
<br/>
<br/>
<br/>
<?php
echo '<div class="col-md-3"></div>
<div class="col-md-6">
    <form action="contact.php" method="post">
    Name:
    <br>
    <input type="text" name="name"/ >
    Email: 
    <br>
    <input type="text" name="email"/>
    Message:
    <br>
    <textarea class="riseize" value="text" name="message"></textarea>
    <br>
    <center><input type="submit" value="submit"/></center>
    </form>
</div>
</div>
<div class="col-md-3"></div>'
?>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</body>
</html>

Calls contact.php which is:

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$sql = "INSERT INTO help (name, email, message) VALUES ( '$name' , '$email' , '$message' )";

if (!mysql_query($sql)) {
die ('Error: ' . mysql_error());
}
else {
echo "<html><script language='JavaScript'> alert('Thank you for your submission.'),window.location = 'index'</script></html>";
};

I think the problem is the get $_GET and $_POST because it executes contact.php and calls the variable values, but it doesn't get the values from the page 1.

Will
  • 122
  • 1
  • 9

3 Answers3

1

Your form uses method="post" so the inputs will be sent to the PHP script in the $_POST array

<form action="contact.php" method="post" />
                                   ^^^^

So change these 2 lines to use $_POST

$name = $_POST['name'];
$email = $_POST['email'];

BUT

Your script is at risk of SQL Injection Attack Have a look at what happened to Little Bobby Tables Even if you are escaping inputs, its not safe! Use prepared parameterized statements

AND

Every time you use the mysql_ database extension in new code this happens it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the PDO or mysqli database extensions and prepared statements. Start here

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
1

Seems like you're trying to pass using post by in the file contact.php you are getting by get the name and the email

If you want to pass your values by post you must get it all by post

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

If you want to do it by get you must get it all by get

<form action="contact.php" method="post" />

In your form you are using post

Ignacio Olcina
  • 104
  • 1
  • 7
1

You close the form when you open it. Change:

<form action="contact.php" method="post" />

to:

<form action="contact.php" method="post">

the / closes the element, basically you have

<form action="contact.php" method="post"></form>

then all your other inputs go to nothing.

(Other issues mentioned also are true, but this is why your form is empty)

In your browser you also should use the developer console (location and options vary by browser) to see how the request is sent and processed. https://wpscholar.com/blog/view-form-data-in-chrome/ This will show you first if it is an issue with the form sending, or the PHP processing it (e.g. if the values aren't sent you know it is not a PHP issue).

As it turned out in this case you had a rewrite in place that stripped the .php, also removing parameters. Making a direct request to the page, bypassing the rewrite rule resolved this.

action="contact"
chris85
  • 23,846
  • 7
  • 34
  • 51
  • I am on GoDaddy hosting and they are both on .php files. I used `print_r($_POST);` on contact.php to check the values and there are none in POST array – Will May 27 '17 at 04:28
  • where would I put echo – Will May 27 '17 at 04:31
  • I get the form on the webpage when I go to my site. In the headers it thinks I am sending a get request – Will May 27 '17 at 04:40
  • I think I figured it out. I hide all .php and .html at the end of my site's address for all addresses. This causes my code to run /contact.php and then tries /contact , but /contact doesn't receive the data from page 1. Simple mistake. – Will May 27 '17 at 04:48
  • yes that worked! thank you so much for your help and sorry for wasting a lot of your time for such a simple solution. – Will May 27 '17 at 04:53