php form on Page, in Page Template, not passing text into db
Hi all, been searching for two days on how to do this. I am building a site using WordPress as the platform. I will need to have a variety of forms (registration forms for a non-profit camp). I am working on creating a very tiny test form first.
I created a table in the wp database named wp_testTable. I only created one field called “name”.
Now I have this code in a page template called “testPage1.php” and a blank page using that page template :
Template Name: TestPage1
<?php # testPage1.php
$link = mysql_connect(“localhost”, “root”, “root”) or die(“Could not connect: “. mysql_error());
mysql_select_db(“chttest”) or die(“could not select database”);
$query = “INSERT INTO wp_testTable (name) VALUES (‘$fn’)”;
$result = @mysql_query($query);
<?php get_header(); ?>
<form action=”<?php echo $PHP_SELF?>” method=”post” name=”name”>
<legend>Test Registration Form</legend>
<input name=”name1″ id=”name1″ tyep=”text” maxlength=”20″ value=”<?php echo $_POST[‘name1’]; ?>” />
<input name=”submit” class=”submit” type=”submit” value=”Register” />
<?php get_sidebar(); ?>
<?php get_footer(); ?>`
Here is my problem. When I click on the page in my sidebar, it comes up fine with a single field, and a submit button.
I am able to type in text, press submit, and it goes immediately to the index page. That is fine, ill work on “success/fail results” page later.
When I view the table in phpMyAdmin, however, there is no text. There is a new record, but no text in the record at all.
Can anyone spot what I may have wrong here? I mean, it is working, it connects, and it writes to the db, but the actual text typed in is not passed.
Appreciate any help!
- The topic ‘php form on Page, in Page Template, not passing text into db’ is closed to new replies.