Jump to content

[SOLVED] database form that is not updating the database


DF7

Recommended Posts

I have a PHP form that should add data to the database, but the database is never updated from the form.  I have another test file that will work just fine using the very same statement to update - just without the actual form, so it's not a problem with connecting to the database.  It seems to be the if (submit) statement, but I cannot for the life of me figure out what the problem is! :-(

 

I have included the php form here. Any help would be greatly appreciated.

******

<html>

<body>

 

<?php

$hostname="p3smysql9.secureserver.net";

$username="DDWD";

$pword="Mydiane";

$dbname="DDWD";

$usertable="QuestionComment";

 

if($submit) {

// process form

echo "This is the top line of process form. Next I connect to database.

";

mysql_connect($hostname,$username,$pword) or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db($dbname) or die ('Unable to select database!');

 

$today = date("m d Y", mktime());

echo $today, "is today's date.";

 

$sql = "INSERT INTO $usertable (source,submit_date,emailaddress,firstname,lastname,phone) VALUES ($source,Now(),$emailaddress,$firstname,$lastname,$phone)" or die ('I cannot insert records to the database because: ' . mysql_error());

$result = mysql_query($sql) or die ('Error in query: $query. ' . mysql_error());

echo "Thank you! Your question/comment was entered.";

} else{

// display form

?>

<form method="post" action="<?php echo $PHP_SELF?>">

<input type="hidden" name="source" value="Contact page">

EmailAddress:<input type="Text" name="emailaddress">*Required<br>

First name:<input type="Text" name="firstname"><br>

Last name:<input type="Text" name="lastname"><br>

Phone:<input type="Text" name="phone"><br>

<input type="submit" name="submit" value="submit">

</form>

<?php

} // end if

?>

</body>

</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.