homepage Welcome to WebmasterWorld Guest from 54.161.192.130
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Form Processing and Mysql
tonynoriega

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3331030 posted 5:46 pm on May 4, 2007 (gmt 0)

So my form seems to validate, gives confirmation, creates a record in the database, but does not seem to be storing the field data...can someone take alook and see why..
Server has:
PHP Version 5.1.6
MySql Version 5.0.27

Code
*********************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
echo "<head><title>NHM</title></head>";

//Connect to database

$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mydbase"); $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mydbase");

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['fname'] ¦!$_POST['email'] )
{
die('<table>
<tr>
<td>You must complete all fields</td>
</tr>
</table>');
}

// now we insert it into the database
$query = "INSERT INTO MY_Table (id, fname, email)
VALUES ('$id','$fname','$email')";

mysql_query($query);

mysql_close();

// mail user their information

$yoursite = "mysite.com";
$youremail = "admin@email.com";
$subject = "You have successfully enterd data";
$message = "A lead has been entered into the database.";

mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

?>
<!-- Now we let them know if their entry was successful -->
<table>
<tr>
<td><h1>Successful Lead Entry</h1></td>
</tr>
</table>
<?php
}
else
{
?>
<body>
<table>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<tr>
<td >First Name: </td>
<td >
<input name="fname" type="text" id="fname" size="20"></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="email" type="text" id="email" size="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Register" ></td>
</tr>
</form>
</table>
</body>
<?php
}
?>
</html>

 

capulet_x

5+ Year Member



 
Msg#: 3331030 posted 5:55 pm on May 4, 2007 (gmt 0)

Your form variables are post variables.
I don't think you can input simply $fname...
try using this format for your form varibles in your query:

$_POST['fname'];
or define $fname like this:

$fname = $_POST['fname'];

and add it above your query.

Hope this helps.

tonynoriega

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3331030 posted 6:22 pm on May 4, 2007 (gmt 0)

well poke my hamhole....

problem solved.

i added the statement above the query.
thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved