Jump to content

Script not working properly


andy_b_1502

Recommended Posts

Hi everyone,

 

my contact us form and script isn't working how it should.

 

On send the data is not sent to the db, a () is the ONLY thing shown in the browser too, can somebody help make this work?

 

Heres the form:

 

<form method="get" action="contact-send.php">
					Name:<br />
					<input type="text" name="name" id="name" size="30" /><br />
					Email:<br />
					<input type="email" name="email" id="email" size="30" /><br />
					Your Question:<br />
					<textarea name="question" id="question" rows="10" cols="50"></textarea><br />
					<input type="submit" name="submit" value="send" />
</form

 

And the script to process:

 

<?PHP
session_start();
include ('php only scripts/db.php');


if ($db_found) {

$SQL = "INSERT INTO 'contact_us' (name, email, question) 
VALUES ('" .$name. "', '" .$email. "', '" .$question. "')";
$result = mysql_query($query) or die(mysql_error());



header( 'Location: http://www.removalspace.com/contactconf.php' );


}
?>

 

 

Iv'e messed with it and had database NOT found before but since then, messed some more and before i go in circles i need some help :|

 

Thanks in advance for any help!

Link to comment
Share on other sites

How do i do that exactly? iv'e got this but it's not working, what am i doing wrong

 

<?PHP
session_start();
include ('php only scripts/db.php');


if ($db_found) {

$name = mysql_real_escape_string(trim($_POST['name']));
$email = mysql_real_escape_string(trim($_POST['email']));
$question = mysql_real_escape_string(trim($_POST['question']));

$SQL = "INSERT INTO 'contact_us' (name, email, question) 
VALUES ('" .$name. "', '" .$email. "', '" .$question. "')";
$result = mysql_query($query) or die(mysql_error());



header( 'Location: http://www.removalspace.com/contactconf.php' );


}
?>

Link to comment
Share on other sites

Youre form was submitted using the GET method. So to get your variables that are submitted you would do something like this:

 

if(isset($_GET['submit'])){
$name = $_GET['name'];
$email = $_GET['email'];
$question = $_GET['question'];
//your code to insert variables into db can go here or after the if statement
}

 

hope this helped

Link to comment
Share on other sites

Thanks it's certainly getting there, i'm not sure why i'm getting the error message:

 

"Query was empty"

 

Here is my full coding now:

 

<?PHP
session_start();
include ('php only scripts/db.php');


if(isset($_GET['submit'])){
$name = $_GET['name'];
$email = $_GET['email'];
$question = $_GET['question'];
//your code to insert variables into db can go here or after the if statement
}

$SQL = "INSERT INTO 'contact_us' (name, email, question) 
VALUES ('" .$name. "', '" .$email. "', '" .$question. "')";
$result = mysql_query($query) or die(mysql_error());



header( 'Location: http://www.removalspace.com/contactconf.php' );



?>

Link to comment
Share on other sites

Before you try submitting them into the database just echo or print them out to the page so you can make sure the data is getting assigned to those variables. That error message tells me that the data that is submitted isnt reaching your query. So after the if statement just do something like this:

 

echo $name."<br/>".$email."<br/>".$question;

 

Make sure the data is getting printed. You can also check the URL since you are using GET.

 

thanks

 

algidDes

Link to comment
Share on other sites

Which bit do change:

 

<?PHP
session_start();
include ('php only scripts/db.php');


if(isset($_GET['submit'])){
$name = $_GET['name'];
$email = $_GET['email'];
$question = $_GET['question'];
//your code to insert variables into db can go here or after the if statement
}

$sql = "INSERT INTO 'contact_us' (name, email, question) 
VALUES ('" .$name. "', '" .$email. "', '" .$question. "')";
$result = mysql_query($query) or die(mysql_error());
echo $name."<br/>".$email."<br/>".$question;


header( 'Location: http://www.removalspace.com/contactconf.php' );



?>

 

Even with echo $name."<br/>".$email."<br/>".$question; i'm getting "Query was empty". sorry i don't understand

Link to comment
Share on other sites

If I do

$string = 'Hello World';

echo $mystring;

 

What do you think would happen?

 

That's essentially what you've done. PFM gave you the explanation of where the problem is. This is simple debugging you'll have to learn if you want to be a developer.

Link to comment
Share on other sites

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.