andy_b_1502 Posted May 1, 2012 Share Posted May 1, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/ Share on other sites More sharing options...
trq Posted May 1, 2012 Share Posted May 1, 2012 The variables $name, $email and $question are not defined anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341919 Share on other sites More sharing options...
andy_b_1502 Posted May 1, 2012 Author Share Posted May 1, 2012 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' ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341968 Share on other sites More sharing options...
algidDes702 Posted May 1, 2012 Share Posted May 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341971 Share on other sites More sharing options...
andy_b_1502 Posted May 1, 2012 Author Share Posted May 1, 2012 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' ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341973 Share on other sites More sharing options...
algidDes702 Posted May 1, 2012 Share Posted May 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341975 Share on other sites More sharing options...
PFMaBiSmAd Posted May 1, 2012 Share Posted May 1, 2012 You are getting a query was empty error because the variable you are putting into the mysql_query() statement doesn't exist. It isn't the variable name you are forming the query statement in. Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341976 Share on other sites More sharing options...
andy_b_1502 Posted May 1, 2012 Author Share Posted May 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341988 Share on other sites More sharing options...
Jessica Posted May 1, 2012 Share Posted May 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1341990 Share on other sites More sharing options...
algidDes702 Posted May 1, 2012 Share Posted May 1, 2012 good luck its a super small issue, step away from your code and come back. You're going to slam your head against your desk when you discover the issue here haha Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1342002 Share on other sites More sharing options...
andy_b_1502 Posted May 1, 2012 Author Share Posted May 1, 2012 :-[ done... Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1342009 Share on other sites More sharing options...
Drummin Posted May 1, 2012 Share Posted May 1, 2012 You are getting a query was empty error because the variable you are putting into the mysql_query() statement doesn't exist. It isn't the variable name you are forming the query statement in. Hint Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1342014 Share on other sites More sharing options...
andy_b_1502 Posted May 1, 2012 Author Share Posted May 1, 2012 i flagged this as topic solved drummin. Quote Link to comment https://forums.phpfreaks.com/topic/261893-script-not-working-properly/#findComment-1342018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.