curvdaryn Posted March 17, 2009 Share Posted March 17, 2009 Hey guys, I have this PHP contact form with 3 fields that imports it a mySQL into a database as well as emailing the data. I have everything setup but I think my code is a little off, I know its not a mySQL issue since it seems to connect alright. If someone could please help me I would greatly appreciate it. If I was more experienced with PHP the problem would probably scream out at me.... The code is below and a zip is attached. Thanks in Advance, Daryn [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/149758-simple-php-mysql-contact-form/ Share on other sites More sharing options...
curvdaryn Posted March 17, 2009 Author Share Posted March 17, 2009 oops.. code <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Promotional Download"; $name_field = $_POST['name']; $email_field = $_POST['email']; $date_book_was_bought = $_POST['date_book_was_bought']; $headers = "FROM: $email_field"; $ip = gethostbyname($_SERVER['REMOTE_ADDR']); mysql_select_db($database, $connection); $insert_query = sprintf("INSERT INTO contacts (name, email, date_book_was_bought, date, ip) VALUES (%s, %s, %s, %s, NOW(), %s)", sanitize($name, "text"), sanitize($email, "text"), sanitize($date_book_was_bought, "text"), sanitize($ip, "text")); $result = mysql_query($insert_query, $connection) or die(mysql_error()); if($result) { //headers and subject $headers = "MIME-Version: 1.0rn"; $headers .= "Content-type: text/html; charset=iso-8859-1rn"; $body = "Name: $name_field\nE-Mail: $email_field \nDate Book was Purchased: $date_book_was_bought"; echo "Data has been submitted to $to!"; mail($to, $subject, $body, $headers); } else { echo "blarg!"; } function sanitize($value, $type) { $value = (!get_magic_quotes_gpc()) ? addslashes($value) : $value; switch ($type) { case "text": $value = ($value != "") ? "'" . $value . "'" : "NULL"; break; case "long": case "int": $value = ($value != "") ? intval($value) : "NULL"; break; case "double": $value = ($value != "") ? "'" . doubleval($value) . "'" : "NULL"; break; case "date": $value = ($value != "") ? "'" . $value . "'" : "NULL"; break; } return $value; } ?> Link to comment https://forums.phpfreaks.com/topic/149758-simple-php-mysql-contact-form/#findComment-786407 Share on other sites More sharing options...
curvdaryn Posted March 17, 2009 Author Share Posted March 17, 2009 got a little farther with the code and I am at this point: <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Promotional Download"; $name_field = $_POST['name_field']; $email_field = $_POST['email_field']; $date_book_was_bought = $_POST['date_book_was_bought']; $headers = "FROM: $email_field"; $ip = gethostbyname($_SERVER['REMOTE_ADDR']); mysql_select_db($database, $connection); $insert_query = sprintf("INSERT INTO contacts (name_field, email_field, date_book_was_bought, date, ip) VALUES (%s, %s, %s, %s, NOW(), %s)", sanitize($name_field, "text"), sanitize($email_field, "text"), sanitize($date_book_was_bought, "text"), sanitize($ip, "text")); $result = mysql_query($insert_query, $connection) or die(mysql_error()); if($result) { //headers and subject $headers = "MIME-Version: 1.0rn"; $headers .= "Content-type: text/html; charset=iso-8859-1rn"; $body = "Name: $name_field\nE-Mail: $email_field \nDate Book was Purchased: $date_book_was_bought"; echo "Data has been submitted to $to!"; mail($to, $subject, $body, $headers); } else { echo "blarg!"; } function sanitize($value, $type) { $value = (!get_magic_quotes_gpc()) ? addslashes($value) : $value; switch ($type) { case "text": $value = ($value != "") ? "'" . $value . "'" : "NULL"; break; case "long": case "int": $value = ($value != "") ? intval($value) : "NULL"; break; case "double": $value = ($value != "") ? "'" . doubleval($value) . "'" : "NULL"; break; case "date": $value = ($value != "") ? "'" . $value . "'" : "NULL"; break; } return $value; } } ?> with this error in return: Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/profits/public_html/mailer/mailer3.php on line 13 Fatal error: Call to undefined function sanitize() in /home/profits/public_html/mailer/mailer3.php on line 16 Link to comment https://forums.phpfreaks.com/topic/149758-simple-php-mysql-contact-form/#findComment-786443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.