0

Alright, Im sorry to ask such a simple question. But I have been set back a few days playing with this stupid form... So I'm going to keep it short.

So Ive tried all types of forms, all with the same problem.

This one I pulled straight from W3Schools and its not working either...

They all cause a new page with: NO DATA RECEIVED, ERR_EMPTY_RESPONSE

EDIT: Tables, User, pass etc... removed for security.

        <?php
        if(isset($_POST['submit']))
        {
        $dbhost = 'localhost';
        $dbuser = '';
        $dbpass = '';
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        if(! $conn )
        {
          die('Could not connect: ' . mysql_error());
        }

        if(! get_magic_quotes_gpc() )
        {
           $emp_name = addslashes ($_POST['firstname']);
           $emp_address = addslashes ($_POST['lastname']);
        }
        else
        {
           $emp_name = $_POST['firstname'];
           $emp_address = $_POST['lastname'];
        }

        $sql = "INSERT INTO `` . `` ".
               "(name,img-path) ".
               "VALUES('$emp_name','$emp_address')";
        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 action="add-nexts.php" method="post">
            First name:
            <br>
            <input type="text" name="firstname" value="Mickey">
            <br> Last name:
            <br>
            <input type="text" name="lastname" value="Mouse">
            <br>
            <br>
            <input type="submit" name="submit" id ="submit" value="Submit">
        </form>

        <?php
           }
        ?>

I have no idea what I am doing wrong. Hoping maybe you guys do. Thanks alot guys!

EDIT: Well Ive got my script working with GET. But POSTing is what is causing the problem. If this helps narrow it down for anyone... I will need to use POST when my site goes live. But for now at least I can move forward.

EDIT: Confirmed not my hosting provider.... Can anyone at least tell me what I should do next lol??? Im stumped, and cannot move forward with image uploads and other things!! Very tired of wasting time!!

TheNodeCommode
  • 93
  • 1
  • 2
  • 8
  • using this on your own machine or hosted site? – Funk Forty Niner Jul 21 '15 at 17:51
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Jul 21 '15 at 17:53
  • Where is your php script? – hemnath mouli Jul 21 '15 at 17:54
  • Directly below this form, do you need to see it? Also Fred, didnt yield anything. – TheNodeCommode Jul 21 '15 at 17:56
  • I went into edit mode; the PHP is not there. – Funk Forty Niner Jul 21 '15 at 17:57
  • have you tried a var_dump($_POST) to see if anything has come through? – Rob Jul 21 '15 at 18:04
  • you have duplicate arrays here `$emp_name = $_POST['firstname']; $emp_address = $_POST['firstname'];` then this is an issue `img-path` your query is off. and where is the table name for the INSERT? and do you have a value for `mysql_select_db('');`? – Funk Forty Niner Jul 21 '15 at 18:04
  • I removed for security. I cant tell if anythings getting through as it send me straight to NO DATA RECEIVED page on submit. On local it does not do that. I can insert raw data, but the form isnt submitting correctly, or id be done with this problem. There shouldn't be any database issues in the code. – TheNodeCommode Jul 21 '15 at 18:07
  • If you can, you should [stop using `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](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 21 '15 at 18:08
  • this column name `img-path` - the hyphen is an issue. MySQL is interpreting that as "img MINUS path". change it to an underscore or use ticks around it `\`` that is one problem here. – Funk Forty Niner Jul 21 '15 at 18:09
  • I suggest you try this. Make up 2 files. One with your form, the other with your SQL without those fancy in-and-out of HTML/PHP bracing. To test, make up a new file while only passing the POST arrays to echo. If that works, you'll know what to go after. – Funk Forty Niner Jul 21 '15 at 18:12
  • Well, even when I add just the form on a new page without mysql, it still sends me directly to "no data received page." Could it be a problem with my server host? – TheNodeCommode Jul 21 '15 at 18:14
  • 1
    Maybe. Contact them to see. I don't know what else I can say/do to further help. – Funk Forty Niner Jul 21 '15 at 18:18
  • Well Ive got my script working with GET. But POSTing is what is causing the problem. If this helps narrow it down for anyone... I will need to use POST when my site goes live. But for now at least I can move forward. Thanks for trying Fred. – TheNodeCommode Jul 21 '15 at 19:42
  • Confirmed not my hosting provider.... Can anyone at least tell me what I should do next lol??? Im stumped, and cannot move forward with image uploads and other things!! Very tired of wasting time!! – TheNodeCommode Jul 21 '15 at 22:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83917/discussion-between-thenodecommode-and-fred-ii). – TheNodeCommode Jul 21 '15 at 22:57
  • @TheNodeCommode Did you get the solution for it ? – Gaurav Jan 16 '16 at 10:46
  • @TheNodeCommode I'm having the same issue. If you found a solution for this issue then you should post it as an answer. – John Odom Jul 01 '21 at 15:15

1 Answers1

0

I encountered the same problem. When I submit a form which has a action="login.php" attribute, it just displayed the errors described by OP. I resolved it by adding <!DOCTYPE html> at the beginning of the file. I'm not sure why however.

JavaMaMocha
  • 70
  • 1
  • 11