bhaumik_shah Posted January 1, 2014 Share Posted January 1, 2014 The given query is not working, it is echoing "You are doomed". so don't know hwat is the bug. <?php session_start(); $host = 'localhost'; $db = 'cramis_2012'; $user = 'root'; $pass = ''; $conn=mysql_connect($host,$user,$pass); if(!$conn) { echo "Connection problem";} @mysql_select_db($db,$conn) or die(" Unable to select"); //Include database connection details //include("_opener_db.php"); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $department=clean($_POST['department']); $area=clean($_POST['area']); $update=clean($_POST['update']); $query = "INSERT INTO updates (Area,Department,Update) VALUES ('$area','$department','$update')"; $result=mysql_query($query,$conn); if($result){ echo "Query sucessful"; header("location:http://localhost:3333/cramis_2012/lect/app/index.php"); exit(); } else{ die(" You are Doomed"); } mysql_close();?> The database pic too. Quote Link to comment https://forums.phpfreaks.com/topic/285022-insert-query-not-working-pls-respond-as-soon-as-possible/ Share on other sites More sharing options...
Barand Posted January 1, 2014 Share Posted January 1, 2014 Your column name "Update" is a MySQL reserved word. Change the name or put it in backticks ie `update` http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/285022-insert-query-not-working-pls-respond-as-soon-as-possible/#findComment-1463525 Share on other sites More sharing options...
bhaumik_shah Posted January 1, 2014 Author Share Posted January 1, 2014 Ya it works thank you! Quote Link to comment https://forums.phpfreaks.com/topic/285022-insert-query-not-working-pls-respond-as-soon-as-possible/#findComment-1463526 Share on other sites More sharing options...
adam_bray Posted January 1, 2014 Share Posted January 1, 2014 I know this is now solved but ... for better error reporting you should do something like this - $result = mysql_query($query,$conn) or die( '<h1>You are doomed!</h1><p>'.mysql_error().'</p>' ); Then you'll actually know what's going wrong instead of seeing your generic error message. Quote Link to comment https://forums.phpfreaks.com/topic/285022-insert-query-not-working-pls-respond-as-soon-as-possible/#findComment-1463530 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.