Darkside Posted December 23, 2012 Share Posted December 23, 2012 (edited) Shortened everything up to try find the prob. Started with a lot of info to INSERT into MYSQL table but found I had a bitten off more than I could chew. Still got the same problem, hoping someone out there can help me sort out the problem. Can anyone see errors in script. Not getting any error messages tho. $rig = $_POST['rig']; $medication = $_POST['medication']; mysql_query("INSERT INTO tabletest (rig,medication) VALUES ('".$rig."','".$medication."')"); $result = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } ?> PS. Merry Christmas to you all Edited December 24, 2012 by Zane Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 23, 2012 Share Posted December 23, 2012 You have no variables named $query so the call of mysql_query($query) would give an error if you had error reporting on. I suggest adding this to the top of your php. It will display everything wrong with the page it's currently on error_reporting(E_ALL); ini_set('display_errors', '1'); As it stands there appears to be nothing wrong with your first call of just mysql_query("stuff"); Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 OK...? Now Im getting message: Query was empty Whole query: Quote Link to comment Share on other sites More sharing options...
Barand Posted December 24, 2012 Share Posted December 24, 2012 Read SC's reply then read your own code carefully Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 Thanks SC will do. Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 My head hurts... :-\ made a couple of changes that I thought would suffice... but apparently Im still off target. Still getting errors but (cant see how or where im going wrong???) <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (isset($_POST['rig'], $_POST['medication'])) $rig = $_POST['rig']; $medication = $_POST['medication']; mysql_query("INSERT INTO tabletest (rig,medication) VALUES ('".$rig."','".$medication."')"); ?> Thought I had defined the index with the... if (isset($_POST['rig'], $_POST['medication'])) and thought the variables were already defined with $rig = $_POST['rig']; $medication = $_POST['medication']; My head hurts. Any suggestions greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 (edited) My head hurts... :-\ made a couple of changes that I thought would suffice... but apparently Im still off target. Still getting errors but (cant see how or where im going wrong???) <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (isset($_POST['rig'], $_POST['medication'])) $rig = $_POST['rig']; $medication = $_POST['medication']; mysql_query("INSERT INTO tabletest (rig,medication) VALUES ('".$rig."','".$medication."')"); ?> Thought I had defined the index with the... if (isset($_POST['rig'], $_POST['medication'])) and thought the variables were already defined with $rig = $_POST['rig']; $medication = $_POST['medication']; My head hurts. Any suggestions greatly appreciated. oops forgot these are the errors im still getting. you've got the connection to this database Notice: Undefined index: medication in/home/hbcpl/public_html/australian.com/shorttest.php on line 30 Notice: Undefined variable: rig in/home/hbcpl/public_html/australian.com/shorttest.php on line 34 Edited December 24, 2012 by Darkside Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 24, 2012 Share Posted December 24, 2012 Try <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (isset($_POST['rig'], $_POST['medication'])) { $rig = $_POST['rig']; $medication = $_POST['medication']; mysql_query("INSERT INTO tabletest (rig,medication) VALUES ('".$rig."','".$medication."')"); } ?> Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 Try <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (isset($_POST['rig'], $_POST['medication'])) { $rig = $_POST['rig']; $medication = $_POST['medication']; mysql_query("INSERT INTO tabletest (rig,medication) VALUES ('".$rig."','".$medication."')"); } ?> Thanks again SC That fixed all the errors, but for some reason its still not INSERTING into DATABASE table Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 24, 2012 Share Posted December 24, 2012 mysql_query("INSERT INTO tabletest (rig,medication) VALUES ('".$rig."','".$medication."')") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 24, 2012 Share Posted December 24, 2012 A lot easier to read like this: mysql_query("INSERT INTO tabletest (rig,medication) VALUES ('{$rig}','{$medication}')") or die(mysql_error()); OP, you need to check for errors. Read the link in my signature about debugging SQL. Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 Thanks Jessica and SC... unfortunately nothing seems to want to INSERT???? Very frustrating. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 24, 2012 Share Posted December 24, 2012 Either the query works, or you get an error. What is the error? What makes you think it's NOT working? Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 24, 2012 Share Posted December 24, 2012 (edited) <?php error_reporting(E_ALL); ini_set('display_errors', '1'); print '<pre>'; print_r($_POST); if (isset($_POST['rig'], $_POST['medication'])) { $rig = $_POST['rig']; $medication = $_POST['medication']; $sql = "INSERT INTO tabletest (rig,medication) VALUES ('{$rig}','{$medication}')"); $result = mysql_query($sql) or trigger_error("Query Failed! SQL: {$sql} - Error: ".mysql_error(), E_USER_ERROR); } ?> What do you get when running this? Edited December 24, 2012 by Jessica Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 K... running that script gives error Parse error: syntax error, unexpected ')' in/home/hbcpl/public_html/australian.com/shorttest.php on line 34 Line 34 = $sql = "INSERT INTO tabletest (rig,medication) VALUES ('{$rig}','{$medication}')"); Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 K... I sorted that error... hang on 2 ticks Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 Still no INSERT message but not error message you've got the connection to this database Array ( ) Ummmm? Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 Still no INSERT message but not error message you've got the connection to this database Array ( ) Ummmm? The connection message is from connect.php file.. should have left that bit out. Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 Not sure if this matters? $rig is textfield VARCHAR $medication is a Yes No radio button Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 24, 2012 Author Share Posted December 24, 2012 The connection message is from connect.php file.. should have left that bit out. OK I C the Array ( ) message is to do with print_r but Im not sure what its telling me? Quote Link to comment Share on other sites More sharing options...
Christian F. Posted December 24, 2012 Share Posted December 24, 2012 (edited) It tells you that nothing have been posted the PHP script, via a form or otherwise, and thus it has nothing to add to the database. Edited December 24, 2012 by Christian F. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 24, 2012 Share Posted December 24, 2012 It tells you that nothing have been posted the PHP script, via a form or otherwise, and thus it has nothing to add to the database. Exactly, the print_r($_POST); is showing you that $_POST is empty. Where do you expect the posted data to be coming from? Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 26, 2012 Author Share Posted December 26, 2012 Is the Array message telling me the form html is not right? Quote Link to comment Share on other sites More sharing options...
Christian F. Posted December 26, 2012 Share Posted December 26, 2012 (edited) That message is telling you that nothing has been sent from the client to the server, via the POST method. Why that is, is something you have to figure out. PS: Note that this will always be empty the first time you visit a page, that's normal and expected. Seeing as all browsers use the GET method when requesting a page, unless told otherwise. Edited December 26, 2012 by Christian F. Quote Link to comment Share on other sites More sharing options...
Darkside Posted December 26, 2012 Author Share Posted December 26, 2012 Exactly, the print_r($_POST); is showing you that $_POST is empty. Where do you expect the posted data to be coming from? Hmmmm? I was expecting it to be coming from the form? Clearly Im overlooking something.... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>shorttest</title> </head> <?php include 'shorttest.php'; ?> <body> <form action="inserted.php" method="post" enctype="multipart/form-data" name="workfitnessform" id="workfitnessform"><H1> </H1> <h3> </h3> <table width="380" border="1"> <tr> <th colspan="3" scope="col"></th> </tr> <tr> <th colspan="3" scope="row"> </th> </tr> <tr> <th width="287" scope="row"><div align="left"> </div></th> <td colspan="2" rowspan="2"><h1 align="center">RIG</h1> <label for="textfield"></label> <input type="text" name="rig" id="col2" /></td> </tr> <tr> <th scope="row"><div align="left"> </div></th> </tr> <tr> <th scope="row"> </th> <td width="72"><div align="center"><strong>YES</strong></div></td> <td width="73"><div align="center"><strong>NO</strong></div></td> </tr> <tr> <th scope="row"><p align="left">Are you presently taking any medication of any kind?</p> </th> <td><input type="radio" name="medication" id="col3" /></td> <td><input type="radio" name="medication" id="col3" /></td> </tr> <tr> </tr> <tr> <th colspan="3" scope="row"> <input type="submit" name="submit" id="submit" /></th> </tr> </table> </form> </body> </html> PS. I know its messy, my excuse at this point is that I have just pulled 36 straight hrs of travel and work and Im just too shattered to tidy it up right now. Quote Link to comment 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.