i installed phpmyadmin, mysql and activated the apache web server on my mac and can view my web pages fine as a localhost. What i am struggling with here is whenever i enter in details from my contact form, it doesn't update in the database.
contact form:
<Form Name="EnquiryForm" Method = "Post" Action = "contactprocess.php">
For further information please fill in the form below:
<p>
Name: <Input Type = "Text" Size="40" Name="Name">
<p>
Email Address: <Input Type = "Text" Size="40" Name="Emailaddress">
<p>
Contact Number: <Input Type = "Text" Size="40" Name="Contactnumber">
<p>
Description:<TextArea Rows="5" Cols="60" Name="Description">
</TextArea>
<p>
<Input Type = "Submit" name = "Submit" Value = "Submit">
<Input Type = "Reset" name = "Reset"Value = "Reset">
</Form>
php script to enter into database, contact process.php:
<?
session_start();
include('database.php');
//Define variables from form to put into table
$Name = $_POST['Name'];
$Emailaddress= $_POST['Emailaddress'];
$Contactnumber = $_POST['Contactnumber'];
$Description = $_POST['Description'];
$strEnquiryadd = "INSERT INTO enquiries VALUES
('','$Name','$Emailaddress','$Contactnumber','$Description');";
mysql_query($strEnquiryadd);
mysql_close();
$_SESSION['login'] = "1";
$_SESSION['userid'] = $userid;
header ("Location: contact us.php");
session_destroy();
?>
Your query should be
$strEnquiryadd = "INSERT INTO enquiries (id,name,email,number,description) VALUES ('','$Name','$Emailaddress','$Contactnumber','$Description');";
Obviously change the column names to the ones used in your table.
try using
echo "<pre>";
print_r($_POST); // check what data returns
then
if(isset($_POST['Submit'] {
// Run here your code
}
then tell us what it goes on.
Also you should learn how to setup an error reporting in php and use xdebug it will help you a lot on the way.
Example from the manual
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
i se like this not sure if it's ok maybe someone will correct me
error_reporting(-1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
it helps when you are in dev mode.
Another thing that's wrong with your code is that you don't provide any security. With that code you could get a really nice sql injection.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.