Jump to content


Photo

no entries to my database?


  • Please log in to reply
3 replies to this topic

#1 wright67uk

wright67uk

    Advanced Member

  • Members
  • PipPipPip
  • 438 posts

Posted 16 January 2013 - 04:55 PM

I'm using the file below, however nothing gets added to my database.

I've tested my database connection, and i've echoed $email and $name, can I put this down to incorrect syntax?


<div id="form">
<form name="form1" method="post" action="form-email.php">
<input type="text" onclick="this.value=''" name="name" class="round" value="name" size="20" />
<input type="text" onclick="this.value=''" name="email" class="round" value="email" size="20"/>
<input type="submit" class="round" name="Submit" value="Register Your interest"/>
</form>
</div>



<?php
if (isset($_POST['Submit'])) {


if ($_POST['name'] != "") {
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
if (!filter_var($name, FILTER_SANITIZE_STRING)) {
$errors .= '* Please enter a valid name.<br/><br/>';
}
} else {
$errors .= '* Please enter your name.<br/>';
}

if ($_POST['email'] != "") {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= "* $email is <strong>NOT</strong> a valid email address ";
}
} else {
$errors .= '* Please enter your email address.<br/>';
}

if (!$errors) {

$hostname = "###";
$username = "###";
$dbname = "###";
$password = "###";
$con = mysql_connect ("$hostname", "$username", "$password");

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

mysql_select_db ("###", $con);
$sql = "INSERT INTO NLCUP (name, email) VALUES ('$name', '$email')";

echo '<p style="color: white; margin-left:105px; font-size:22px; padding-top:15px">* Thankyou, we will be in touch soon!<br></p>';
}

else {
echo '<p style="color: white; margin-left:105px; padding-top:15px">' . $errors . 'please try again.</p></div>';
}
}
?>
</div>


#2 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 16 January 2013 - 04:59 PM

Where exactly is your mysql_query statement in your code?
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#3 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 16 January 2013 - 04:59 PM

Well you never try to run the query. 
mysql_query

Awwww.

Edited by Jessica, 16 January 2013 - 04:59 PM.

My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#4 wright67uk

wright67uk

    Advanced Member

  • Members
  • PipPipPip
  • 438 posts

Posted 16 January 2013 - 05:49 PM

I feel very silly :-(


...and thank you for the replies.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com