Blip Posted September 27, 2006 Share Posted September 27, 2006 Hi folks, I'm new to PHP and have been doing ASP so please bear with me I'm getting an empty query error, but I'm not trying to query the database, I'm trying to add records. Can someone tell me what Im doing wrong? It is indeed getting the info from the form and therefore getting the variable values it needs. I know this because I have a "Hello World!" print statement inside of the first "If" and it does print out, so this condidtional woks. so what's wrong? Thanks in advanceAlso, not that this script lives in a folder named admin, and the database lives in a folder called database. Both are in the same level under the root folder. Is my path for the database wrong?Here's the code<html><head></head><body><?php$dayname=$_POST['dayname'];$day=intval($_POST['day']);$month=intval($_POST['month']);$year=intval($_POST['year']);$title=$_POST['title'];$description=$_POST['description'];$cost=$_POST['cost'];$location=$_POST['location'];$contact=$_POST['contact'];$type=$_REQUEST["type"];$con = mysql_connect("mysql","username","password");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("Classes", $con);if ($type == "enter"){print "Hello, World!"; $result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");if (!mysql_query($SQL,$con)) { die('Error: ' . mysql_error()); }header ('location: enter.php');}if ($type == "edit"){}if ($type == "delete"){}?></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/22243-error-query-was-empty/ Share on other sites More sharing options...
wildteen88 Posted September 27, 2006 Share Posted September 27, 2006 Where does $SQL get set to here:[code]$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");if (!mysql_query($SQL,$con)) { die('Error: ' . mysql_error()); }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22243-error-query-was-empty/#findComment-99610 Share on other sites More sharing options...
Blip Posted September 27, 2006 Author Share Posted September 27, 2006 It doesn't get set. I'm lifting this code from the net but I don't really understand itWhat is the first argument of this (SQL) supposed to be?if (!mysql_query($SQL,$con))Do i use $result instead?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/22243-error-query-was-empty/#findComment-99613 Share on other sites More sharing options...
acdx Posted September 27, 2006 Share Posted September 27, 2006 Instead of[code]<?php$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");if (!mysql_query($SQL,$con)){die('Error: ' . mysql_error());}?>[/code]... make it[code]<?php$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')") or die(mysql_error());?>[/code]Also check out these links[url=http://php.net/manual/en/function.mysql-query.php]http://php.net/manual/en/function.mysql-query.php[/url][url=http://php.net/manual/en/function.exit.php]http://php.net/manual/en/function.exit.php[/url] (aka die()) Quote Link to comment https://forums.phpfreaks.com/topic/22243-error-query-was-empty/#findComment-99616 Share on other sites More sharing options...
wildteen88 Posted September 27, 2006 Share Posted September 27, 2006 [code]Chnage this:[coce]$result = mysql_query("INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')");if (!mysql_query($SQL,$con)) { die('Error: ' . mysql_error()); }[/code]to this:[code]$sql = "INSERT INTO classes (dayname, day, month, year, title, description, cost, location, contact) VALUES ('$dayname', '$day', '$month', '$year', '$title', '$description', '$cost', '$location', '$contact')";mysql_query($sql, $con) or die('Error: ' . mysql_error());[/code]DOnt just lift the code of the net. Learn and understand the code first before using it. Also code your scripts yourself. Dont do any of the copy 'n' paste malarky you dont learn as much. Just learning how to efficiently copy 'n' paste stuff. Quote Link to comment https://forums.phpfreaks.com/topic/22243-error-query-was-empty/#findComment-99617 Share on other sites More sharing options...
Blip Posted September 27, 2006 Author Share Posted September 27, 2006 Hey thanks guys, that last change worked. Yeah, I'd like to have time to read a book, butn I don't have that luxury at the moment. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/22243-error-query-was-empty/#findComment-99623 Share on other sites More sharing options...
wildteen88 Posted September 27, 2006 Share Posted September 27, 2006 If you dont understand a function/keyword in PHP or whatever is in the code. Imediatly go to php.net. You'll leave the site know how to use the function/keyword and when to use it etc. php.nts documentation is on of the best you'll ever come across. Quote Link to comment https://forums.phpfreaks.com/topic/22243-error-query-was-empty/#findComment-99624 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.