totalphpnoob517 Posted August 27, 2012 Share Posted August 27, 2012 Hey guys, I have a total noob question here...the project this is from is my first PHP application and I'm basically learning php/html on the fly. Now what I want this to do is add the record, show that 1 record was added, and redirect to the homepage but I have an error on line 34, which is die('Error: ' . mysql_error()); <?php /* Declare connection variable */ $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } /* Connect to db */ mysql_select_db("test_db", $con); /* select db to query */ /* SQL to talk to the database ....need to add date function and date column... */ $sql="INSERT INTO open_cases (its_rep, case_id, call_type, ret_num, trk_num, rs1, ord_num, gm_num, pk_num, gm_num2, pk_num2, gm_num3, pk_num3, gm_num4, pk_num4, gm_num5, pk_num5, gm_num6, pk_num6, valret_num, dmgd, contact, notes, status) VALUES ('$_POST[its_rep]','$_POST[case_id]','$_POST[call_type]','$_POST[ret_num]','$_POST[trk_num]','$_POST[rs1] ','$_POST[ord_num]','$_POST[gm_num]','$_POST[pk_num]','$_POST[gm_num2]','$_POST[pk_num2]','$_POST[gm_num3]','$_POST[pk_num3]','$_POST[gm_num4]','$_POST[pk_num4] ','$_POST[gm_num5]','$_POST[pk_num5]','$_POST[gm_num6]','$_POST[pk_num6]','$_POST[valret_num]','$_POST[dmgd]','$_POST[contact]','$_POST[notes]','$_POST[status]')"; /* If query is successfully run, show user 1 record was added...or else show error message. */ if (!mysql_query($sql) die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> <!--- ... Wait 3 seconds, redirect to homepage ---> <HTML> <HEAD> ? <META HTTP-EQUIV="refresh" CONTENT="3;URL=loginsuccess.php"> ? </HEAD> <BODY> ? </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/267656-unexpected-t_exit/ Share on other sites More sharing options...
Jessica Posted August 27, 2012 Share Posted August 27, 2012 You're missing two things. Check how many parens and {} you have. if (!mysql_query($sql) die('Error: ' . mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/267656-unexpected-t_exit/#findComment-1372901 Share on other sites More sharing options...
Maq Posted August 27, 2012 Share Posted August 27, 2012 You should also properly handle your errors, read: http://www.phpfreaks.com/blog/or-die-must-die Quote Link to comment https://forums.phpfreaks.com/topic/267656-unexpected-t_exit/#findComment-1372957 Share on other sites More sharing options...
totalphpnoob517 Posted August 28, 2012 Author Share Posted August 28, 2012 if (mysql_query($sql,$con)) { echo "1 record successfully added.."; } else { echo "Error performing update: " . mysql_error(); } Pardon my noob status, I see by your guys' join dates you are veterans at this, also I appreciate the guidance. Does this look more on track? (I'm not at work where my database is but when I get there I will run this query and post results. Quote Link to comment https://forums.phpfreaks.com/topic/267656-unexpected-t_exit/#findComment-1373139 Share on other sites More sharing options...
totalphpnoob517 Posted August 28, 2012 Author Share Posted August 28, 2012 It worked, thank you and again I apologize for the silly question I have zero real programming experience...I am familiar with SQL so somehow I got volunteered to build a database and a PHP/HTML/Javascript front end so I'm learning as I go! Quote Link to comment https://forums.phpfreaks.com/topic/267656-unexpected-t_exit/#findComment-1373157 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.