0

Good Morning:

I'm featuring a hall of fame on my website that will allow visitors to submit nominees via a form. I want the form data to be submitted to another page/MySQL database. Here's what I have so far:

The HTML form page rebootwwehof.html

<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>WWE Hall of Fame</TITLE>
</HEAD>
<BODY BGCOLOR=#000000 LINK=#FFFFFF VLINK=#FFFFFF>
<FONT FACE="Arial" COLOR=#FFFFFF>
<BR>
<BR>
<P>It's been said that no Hall of Fame is perfect and certainly the WWE Hall of Fame has gotten its share of criticisms.
However, with this project, I am rebooting the WWE Hall of Fame and inviting people to 
create the perfect WWE Hall of Fame with nominations and votings. On this page, you can submit
individuals (whether wrestlers, managers, referees, announcers, promoters) worthy of induction. The names 
receiving the most nominations will form the initial ballot. There will be two rounds of voting. Nominees 
must receive at 75% of votes to move on the next round. Anyone receiving at 
least 70% but less than 75% will be included on next year's ballot. The 
nomination period will last from April 15 to June 15.
<BR>
<BR><B>Criteria</B>
<BR>
<UL>
<LI>Work (as wrestler, manager, announcer, staff or promoter) for WWE any period from its beginning as Capitol Wrestling Corporation (CWC) days to modern day WWE</LI>
<LI>Drawing power, merchandise sales, achievement</LI>
<LI>Influence or significance in WWE history</LI>
<LI>Age of at least 50 years</LI>
  <UL>
  <LI><B>Exception:</B> being deceased for at least two and a half years 
  </UL>
</UL>
</P> 
<BR>
<BR>
<P>Make your nominations in the form below</P>
<FORM NAME="input" ACTION="http://mvwres.awardspace.us/almanac/rebootwwenominees.php" METHOD="post">
<P>E-mail:<BR> <?PHP ECHO $_POST['email']; ?><INPUT TYPE="text" NAME="email"></P>
<P>Nominees:<BR> <?PHP ECHO ($_POST['nominee']); ?><TEXTAREA NAME="nominees" ROWS="10" COLS="40">
</TEXTAREA></P>
<INPUT TYPE="submit" VALUE="Submit"><INPUT TYPE="reset" VALUE="Reset">
</FORM> 
</BODY>
</HTML>

Here's the page to process the data rebootwwenominees.php:

    <HTML>
    <BODY>

<HEAD>
<TITLE>WWE Hall of Fame Nominations</TITLE>
</HEAD>

    <? 
     $email = $_POST['email']; 
     $nominee = $_POST['nominee'];
     mysql_connect("fdb2.awardspace.com", "mvwi1_newwwehof", "konc!abr") or die(mysql_error()); 
     mysql_select_db("mvwi1_newwwehof") or die(mysql_error()); 
     mysql_table = 'WWE_HOF_Nominator';
     mysql_query("INSERT INTO `data` VALUES ('$email', 'nominee')"); 
     Print "Your information has been successfully added to the database."; 
     ?> 

    </BODY>
    </HTML>

Am I missing anything?

Okay I've since updated my code and still having issues (albeit long break in between). I keep getting an unexpected T_string error on the $con line.

<?php
$servername = "sql204.byethost9.com";
$username = "b9_18261515";
$password = "brother1";
$dbname = "b9_18261515_mockwwe";
// Create connection
$con = mysqli_connect("sql204.byethost9.com", "b9_18261515", "brother1", "b9_18261515_mockwwe");
// Check connection

if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}

mysqli_select_db($con,"b9_18261515") or die ("no database");
$sql = "INSERT INTO WWE_HOF_Nominator (email, nominees) VALUES ('$email', '$nominees')";

if (mysqli_query($con, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($con);
}

mysqli_close($con);
?>

1 Answers1

0

Not sure what's exactly wrong but on a first glance you might be missing a few things:

  1. Like user3383116 said, there's a typo, nominees vs nominee

  2. Make sure if you're setting short_open_tag=On in your php.ini if you're going to use <? to start your script instead of <?php. See How to enable PHP short tags?

  3. It looks like these lines:

    mysql_table = 'WWE_HOF_Nominator';
    mysql_query("INSERT INTO `data` VALUES ('$email', 'nominee')"); 
    

    should be (assuming "WWE_HOF_Nominator" is the table name and "email" and "nominee" are the column names:

    $mysql_table = 'WWE_HOF_Nominator';
    $query = sprintf("INSERT INTO %s (email, nominee) VALUES (%s, %s)", 
                     mysql_real_escape_string($mysql_table),
                     mysql_real_escape_string($email),
                     mysql_real_escape_string($nominee));
    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    
  4. The last thing you should do in this particular script is close the db connection:

    $link = mysql_connect("fdb2.awardspace.com", "mvwi1_newwwehof", "konc!abr") or die(mysql_error()); 
    
    ...
    
    mysql_close($link);
    ?>
    

http://php.net/manual/en/ has a lot of good reference material and examples.

Hope that helps.

Community
  • 1
  • 1