Jump to content

[SOLVED] database form that is not updating the database


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>

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.