Jump to content

Trying to get a form to submit an email address to mysql database


LuciBKen

Recommended Posts

I was wondering if someone could help me with this problem. I have some code that just simply won't work.

 

I need the form called testemailscript.php to take the entered email address and when the submit button is clicked, it should send the entered addresss to my test database. If anyone could take a look and maybe point me towards the problem, I would greatly appreciate it. All scripts are posted below.

 

testemailscript.php:

 

<html>

<head>

<title>Email Submission Page</title>

</head>

<body>

      <form method = "post">

            Please enter a valid email address

      <input type = "text"

            name = "email"

            value = "">

      <input type = "submit"

            name = "submit"

            value = "$_post"

      </form>

<?

include  insert.php

?>

</body>

</html>

 

config.php:

 

<?php

$dbhost = '###.###.###.###';

$dbuser = '####';

$dbpass = '#####';

$dbname = '#######';

?>

 

insert.php

 

<?php

include 'config.php';

include 'opendb.php';

 

mysql_select_db($######);

$query = "INSERT INTO email (email_address) VALUES ($_post)";

 

mysql_query($query) or die('Error, insert query failed');

 

$query = "FLUSH PRIVILEGES";

mysql_query($query) or die('Error, insert query failed');

 

include 'closedb.php';

?>

 

opendb.php:

 

<?php

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die

                              (Error connecting to mysql');

mysql_select_db($dbname);

?>

 

closedb.php:

 

<?php

mysql_close($conn);

?>

 

 

This is kinda urgent, so if anyone can help, I would be greatly appreciative.

 

Link to comment
Share on other sites

You didn't specify where the form should send the data to.

<html>
<head>
<title>Email Submission Page</title>
</head>
<body>
      <form method="post" action="config.php">
            Please enter a valid email address
      <input type = "text"
             name = "email"
             value = "">
      <input type = "submit"
             name = "submit"
             value = "$_post"
      </form>
<?
include  insert.php
?>
</body>
</html>

Link to comment
Share on other sites

So, shold this work?

 

testemailscript.php

 

<html>

<head>

<title>Email Submission Page</title>

</head>

<body>

      <form method = "post"

            action = "insert.php">

            Please enter a valid email address

      <input type = "text"

            name = "email"

            value = "">

      <input type = "submit"

            name = "submit"

            value = "$_post"

      </form>

<?

include  insert.php

?>

</body>

</html>

 

Link to comment
Share on other sites

I guess my question is this: It doesn't seem like all of the scripts are working together, what would be easier for me is if I can just put them all together in one file and maybe set some globals. But, I have no idea if that is going to make a difference. Which is the best method, or does it matter?

 

Really, this is a learning experience for me because it is my first real php script attempt.

 

I can describe exactly what it is suposed to do.

 

When the person enters the email address, it should save it to the database, then send a reply to that email address. As you can see, this is only the first part of the whole picture, I had the replier working yesterday, but still had the same result with the database INSERT. For some reason, certain parts work, but when I throw it all together, it just dies. It makes no sense to me. I think I'm narrowing it down, as far as what the real problem is, it just lies within the database script crap.

 

Any suggestions?

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.