Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

data not being taken from forms?

Featured Replies

Hello, im trying to make a simple write to database form.

 

I have made the database and the table.

 

Here is the form:

 

<form name="input" action="write.php" method="post">
<input class="textbox" type="text" name="email" value="Enter Your Email" onfocus="this.value=''">
<input class="button" type="submit" value="Enter Competition">
</form>

 

this is write.php:

 

<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }
mysql_select_db("win2012", $con);
if (empty($Email)) {
	  echo '<div id="errormessage">', "Email box cannot be empty. Please fill in.", '</div>';
}
// This checks the email is valid
if (!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
	  echo '<div id="errormessage">', "$Email is not a valid email, please correct any errors.", '</div>';
}

//Now insert the clean data
if (!empty($Email) && (filter_var($Email, FILTER_VALIDATE_EMAIL))) {
		    $sql="INSERT INTO win2012 (email) VALUES ('$Email')";

		    if (!mysql_query($sql,$con))
		    {
		    die('Error: ' . mysql_error());
		    }

		    echo '<div id="successmessage">', "Success! Suggestion Sent.", '</div>';
		    mysql_close($con);

		    }

		    ?>

 

But i keep getting the error messages... and nothing is writing to db etc.

 

I used some of old cold i had but cant get it working...

Yes you need to take the value from the email textbox $Email = $_POST['email'];.I think you didn't take that value

Your code won't work for a number of reasons. Firstly the above 2 replies are correct - to access form data use the $_POST global variable using the name of the field. If you've named it email, use $_POST['email'].

 

You need to check for its existence before you can access it. Try something like

if (isset($_POST['email']) && (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))) {
 $em = $_POST['email'];
 $sql="INSERT INTO win2012 (email) VALUES ($em)";
 if (!mysql_query($sql,$con)) {
 die('Error: ' . mysql_error());
 }
else {
 echo '<div id="successmessage">', "Success! Suggestion Sent.", '</div>';
 }
mysql_close($con);
}
else {
 echo "<div id=\"errormessage\">Please enter a valid email address</div>";
}

 

Also you should switch to the mysqli extension as mysql is now deprecated.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.