0

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();
?>
3
  • no don't seem to get any errors. I've only installed it 2 days ago on my mac so i can work on my site from home. at my university they have the exact same setup and the database takes in the data when i enter in info using the above scripts. Commented May 18, 2014 at 20:48
  • Your query is vulnerable and a single quote in any of the fields would easily break it Commented May 18, 2014 at 20:48
  • 1
    Two questions -- have you set up the table to autoincremnt the id correctly? Have you looked in the apache log files for error messages? Often error messages will be sent to you web page as invalid HTML -- you can try using the "Tools->Page Source" option in your browser to see if there are any hidden messages, Commented May 21, 2014 at 3:54

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

5 Comments

This doesn't provide an answer to the question. Request for clarifications should be made as comments
indeed but at least if he came with a question here we could help him out how to debug code how find problems and others. he get's the data from the form but he doesn't know if the form was submited.
No one's objecting that. Still, this isn't an answer to OP's problem.
no thats of no help mate. thanks for trying though. the form does send but i guess its something to do with the way the database is setup.
i know the form sends the data :-) but you need to check if it was submited before taking data maybe .. you don't get the data.. some day and you don't know why. same as for the database.php you need to check if connection was made if database was selected and so on. another good practice would be to use pdo extension from php. better security and will help you write better code and easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.