-2

Here's the form:

<form id="secursendmsg" action="server.php" method="post">
        <div id="body_errors">
        </div>

        <textarea id="msg_body" name="msg_body'">
        </textarea>

        <script type="text/javascript">
          function showMe (box) {

            var chboxs = document.getElementsByName("read");
            var vis = "none";
            for(var i=0;i<chboxs.length;i++) {

              if(chboxs[i].checked){
                vis = "block";
                break;
              }
            }
            document.getElementById(box).style.display = vis;


          }
        </script>

        <p id="notifycheck" class="notify">
          <input type="checkbox" name="read" name="notify" onclick="showMe('notify')"/>

          <label for="id_notify">
            Enable Read Receipts
          </label>
        </p>
        <div id="notify" style="display:none">
          <div id="email_errors">
          </div>

          <div class="left">
            <p>
              <label for="email">
                Contact email (suggest Anonmail address):
              </label>

              <br>
              <input id="email" type="text" name="sender_email" size="35" rows="3" maxlength="100"/>
            </p>

          </div>
        </div>
        <p id="pwrapper">
          <div class="button1">
            <i class="fa fa-lock"></i> Submit
        </div>

        <div class="settings">

          <i class="fa fa-cog" style="font-size: 20px;">
          </i>
        </div>

      </div>
    </form>

My PHP code is below:

<?
if( $_POST )
{
  $con = mysql_connect("192.99.xxx.xxx","root","LAxxxxxd!");

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

  mysql_select_db("SecurSend", $con);

  $sent = $_POST['msg_body'];
  $email = $_POST['email'];


  $sent = mysql_real_escape_string($sent);
  $email = mysql_real_escape_string($email);




  $query = "
INSERT INTO `SecurSend`.`SecurMSG` (`email`,`sent`) VALUES         ('".$sent."','".$email."');";"

  mysql_query($query);

  echo "<h2>Test Complete!</h2>";

  mysql_close($con);
}
?>

No matter what, I never get the echo, and the information isn't populating. I can't wrap my head around why. The form & PHP isn't hosted on the server, it is hosted in-app via Cordova.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
CodeSpent
  • 1,684
  • 4
  • 23
  • 46
  • `('".$sent."','".$email."');";"` <= extra quote and using the wrong POST variable for "email". Having error reporting set and checking for error on query would have signaled those. – Funk Forty Niner Nov 25 '14 at 17:20
  • `$email = $_POST['sender_email'];` – Anand Shah Nov 25 '14 at 17:21
  • Add error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Nov 25 '14 at 17:27
  • 1
    I knew you were waiting for me to say....Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). You will also want to [Prevent SQL Injection!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Nov 25 '14 at 17:29
  • ` Submit` - How are you submitting the form? – Funk Forty Niner Nov 25 '14 at 17:38
  • Okay, I added error reporting, I am receiving the echo, but it shows as: Test Complete!"; or die(mysql_error()) mysql_close($con); } ?> – CodeSpent Nov 25 '14 at 17:56
  • @Autonomous is the database getting updated – Johny Nov 25 '14 at 17:57
  • "Test Complete!"; or die(mysql_error()) mysql_close($con); } ?>" that shows up as code? Is your file `.php` extension? Something is not right. – Funk Forty Niner Nov 25 '14 at 17:58
  • Yeah, the file name is server.php. I'm not sure what's going on here.. – CodeSpent Nov 25 '14 at 18:00
  • Ok, I think I know why. `` isyour opening (PHP) tag. It seems that short open tags are not set. You will need to change that to ` – Funk Forty Niner Nov 25 '14 at 18:01
  • Did that, I'm still receiving the same output. – CodeSpent Nov 25 '14 at 18:11
  • Create a `test.php` file with ` – Funk Forty Niner Nov 25 '14 at 18:15
  • Doesn't echo, does the PHP HAVE to be hosted on the server as opposed to being included in the app package on the device? – CodeSpent Nov 25 '14 at 18:18
  • Both files need to be inside your server. If you're trying to access someone else's server, then that could explain it. You could also try Ajax/Curl. – Funk Forty Niner Nov 25 '14 at 18:19
  • I am using Cordova. The site files are being accessed directly on the Android device. What would be the proper way of sending data from the Android device, to the database? – CodeSpent Nov 25 '14 at 18:22
  • That I couldn't help you with. I know nothing about Android. You will need to Google it, where you're most likely going to end up back on Stack from Q&A's found. – Funk Forty Niner Nov 25 '14 at 18:23

2 Answers2

1

Change this

 $email = $_POST['email'];

to

$email = $_POST['sender_email'];

You have named email in the form as sender_email and you used email in php.

Also you have an extra double quote in the $query string. After removing that code will be:

$query = "INSERT INTO SecurSend.SecurMSG(email,sent)VALUES('".$sent."','".$email."')";

As far as the code you have shown you are not submitting the form.

So change

<div class="button1">
     <i class="fa fa-lock"></i> Submit
</div>

to

<button class="button1" type="submit">
    <i class="fa fa-lock"></i> Submit
</button>
Johny
  • 2,128
  • 3
  • 20
  • 33
  • I'm wondering how OP is submitting the form. This ` Submit` is hard to say whether OP is trying to use that which doesn't qualify as a submit button. Probably a contributing factor. – Funk Forty Niner Nov 25 '14 at 17:38
  • Yeah I did catch that, but forgot to throw it in here. I am using a different button for testing purposes. – CodeSpent Nov 25 '14 at 17:44
  • 1
    @Autonomous Are you by any chance reading the comments left under your question? Specifically the one about [checking for errors](http://stackoverflow.com/questions/27132811/form-data-not-populating-in-mysql-database#comment42764580_27132811). – Funk Forty Niner Nov 25 '14 at 17:49
  • @Fred-ii-Nope, just saw that now. Kinda still getting used to Stack Overflow's interface. I'll try that. – CodeSpent Nov 25 '14 at 17:52
1

Other than the email text name issue, your sql line is messed up:

$query = "INSERT INTO SecurSend.SecurMSG(email,sent)VALUES('".$sent."','".$email."')";
raidenace
  • 12,789
  • 1
  • 32
  • 35
  • Thanks, guys. The syntax is showing correctly now, however, no data is being populated. Thanks for catching the email error, I'm only testing with msg_body at the moment & that's not going through. – CodeSpent Nov 25 '14 at 17:25