Domanda

Ok, so my form is not working. No values are being passed from the form to the php. Do I NEED javascript? I know my form is communicating with the php because when I fill in the fields I get a blank row of fields with nothing in them. If I try it again, nothing will go in. If I delete the blank row, try it again another row of blank fields will be submitted.

My html form:

<!-- Contact Us -->
<div data-role="page" id="contact_us" data-theme="c" data-title="Contact Us">
    <div data-role="header">
        <h1>Contact Us</h1>
        <a data-rel="back" data-direction="reverse" href="#home">Back</a>
    </div>
    <div data-role="content">
        <div class="contact-thankyou" style="display: none;">
        Thank you.  Your message has been sent.  We will get back to you as soon as we can.
    </div>
    <p>Please Contact us if you wish to report any complaint or would like more information.</p>
        <p>Street Address<br/>City, Country</p>
        <p><a href="tel:5555555555">(555) 555-5555</a></p>
    <div class="contact-form">
    <br><p>Why not sign up for our exclusive newsletter???</p></br>
        <p class="mandatory">* indicates Manadatory Field</p>
        <div data-role="fieldcontain" class="text-field">
            <label for="firstname">First Name*:</label>
            <input type="text" name="firstname" value="" placeholder="" class="required" id="firstname" />
        </div>
        <div data-role="fieldcontain" class="text-field">
            <label for="surname">Last Name*:</label>
            <input type="text" name="surname" value="" placeholder="" class="required" id="surname" />
        </div>
        <div data-role="fieldcontain" class="text-field">
            <label for="email">Email Address*:</label>
            <input type="email" name="email" value="" placeholder="" class="required" id="email"  />
        </div>
        <div data-role="fieldcontain" class="text-field">
            <label for="mobilephone">Mobile Number:</label>
            <input type="number" name="mobilephone" value="" placeholder="" id="mobilephone" />
        </div>
        <div data-role="fieldcontain">
            <label for="state">Country*:</label>
                <select name="country" class="required" id="country">
                    <option value="" data-placeholder="true">Please select your country</option>
                    <!-- country options -->
                </select>
        </div>
        <div data-role="fieldcontain">
            <label for="message">Any<br>Thing<br>To say?:</br></label>
            <textarea name="message" id="message" placeholder=""></textarea>
        </div>
        <div class="send"><a href="signup.php" data-role="button" data-theme="a" data-iconpos="right" id="send-info">Submit</a></div>
    </div><!-- //.contact-form -->

My php insert form:

<html>
<head>
    <meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1"> 
<link rel="stylesheet" href="includes/themes/manutd.css" />
<link rel="stylesheet" href="includes/themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile.structure-1.4.2.min.css" />
<link rel="stylesheet" href="includes/maincss.css" />
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script src="includes/manunited.js"></script>
</head>

<body>
</body>
</html>

<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("manunited", $con);

$sql="INSERT INTO People (firstname, surname, email, mobilephone, country, message)
VALUES ('$_POST[firstname]','$_POST[surname]','$_POST[email]','$_POST[mobilephone]','$_POST[country]','$_POST[message]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Thank you for signing up!";

//12. Link back to the main page
echo "<a href='index.html'> </a>";

mysql_close($con);
?>

Any help would be very much appreciate. Also, no need to worry about mysql depreciation nor injections, it isn't being hosted or going live. Thanks!

È stato utile?

Soluzione

You need to use a form for posting:

<form action="signup.php" method="post"> The html form you posted here </form> 

And add a submit button instead of a link to signup.php:

<input type="submit" value="Signup"/>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top