ckdoublenecks Posted January 27, 2011 Share Posted January 27, 2011 this code works fine it I take out the checkboxes(repair & replace) in the html & PHP ? <form name="form" action="<?php $_SERVER[php_SELF] ?>" method="post"> <input type="text" size="2" name="apt" id="apt" onkeyup="getResults();if(this.value.length==this.size)document.form.datereceived.focus();" />Apt<br /> <input type="text" size="25" name="name" id="name" />Name<br /> <INPUT TYPE="text" size=10 name="datereceived" onKeyUp="if(this.value.length==this.size)document.form.time.focus();">Date Received<br /> <INPUT TYPE="text" size=7 name="time">Time Received<br /> <br>Kitchen <select name="item"> <option value="kitchen blinds" selected>kitchen blinds</option> <option value="kitchen bifolds">kitchen bifolds</option> <option value="kitchen lights">kitchen light fixtures</option> <option value="kitchen bulbs">kitchen light bulbs</option> <option value="kitchen tile">kitchen tile/linoleum</option> <option value="kitchen countop">kitchen counter top</option> <option value="kitchen cabinets">kitchen cabinets</option> <option value="kitchen drawers">kitchen drawers</option> <option value="fridge">refidgerator</option> <option value="stove">stove</option> <option value="range hood">stove hood</option> <option value="kitchen sink">kitchen sink</option> <option value="under kitchensink">under kitchen sink</option> <option value="kitchen faucet">kitchen faucet</option> <option value="kitchen drain">kitchen drain</option> <option value="kitchen screens">kitchen windows & screens</option> <option value="fire extinguisher">fire extinguisher</option> <option value="kitchen wall plates">kitchen switch plates</option> <option value="kitchen outlets">kitchen electrical outlets</option> <option value="kitchen ceilings">kitchen ceiling paint</option> <option value="kitchen wallpaint">kitchen wall paint</option> </select> <br> repaired <input type=checkbox name="repair" value="Y"> replaced <input type=checkbox name="replace" value="Y"><br> </p> action<INPUT TYPE="text" size=100 name="action"><br /> <INPUT TYPE="text" size=2 name="compday" MAXLENGTH=2 onKeyUp="if(this.value.length==this.size)document.form.compmoyr.focus();"> <INPUT TYPE="text" size=7 name="compmoyr" MAXLENGTH=7 Date Completed - <font color=red>day then mm/yyyy</font <br /><br /> cost<INPUT TYPE="text" size=4 name="cost"> charge<INPUT TYPE="text" size=4 name="charge"> Order#<INPUT TYPE="text" size=4 name="ordno"> - If Insp <p> <INPUT type="submit" value="submit data" /> </p> </form> <?php if (isset( $_POST['apt']) ) { $apt=$_POST['apt']; $name=$_POST['name']; $datereceived=$_POST['datereceived']; $time=$_POST['time']; $item=$_POST['item']; $repair=$_POST['repair']; $replace=$_POST['replace']; $action=$_POST['action']; $compday=$_POST['compday']; $compmoyr=$_POST['compmoyr']; $cost=$_POST['cost']; $charge=$_POST['charge']; $ordno=$_POST['ordno']; $stat = mysql_connect("localhost","root","") or die('Unable to connect to database: ' . mysql_error()); $stat = mysql_select_db("maintdb") or die('Unable to select database: ' . mysql_error()); $query = " INSERT INTO maintdata (apt,name,datereceived,time,item,repair,replace,action,compday,compmoyr,cost,charge,ordno) VALUES('$apt','$name','$datereceived','$time','$item','$repair','$replace','$action','$compday','$compmoyr','$cost','$charge','$ordno')"; echo "apt $apt data inserted</font><br /><br />"; $stat = mysql_query($query) or die('Query failed: ' . mysql_error()); mysql_close(); } ?> Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2011 Share Posted January 27, 2011 Well, it probably would work fine without those, since replace is a MySQL reserved word. Link to comment Share on other sites More sharing options...
Psycho Posted January 27, 2011 Share Posted January 27, 2011 No to mention you should have stated what errors you were getting. If you want free help at least make the effort to provide the relevant information. If the only problem is that you have a column called replace, then you just need to put backquotes around the field name in your query (which isn't a bad idea just as common practice): $query = "INSERT INTO maintdata (`apt`, `name`, `datereceived`, `time`, `item`, `repair`, `replace`, `action` ,`compday`, `compmoyr`, `cost`, `charge`, `ordno`) VALUES ('$apt', '$name', '$datereceived', '$time', '$item', '$repair', '$replace', '$action', '$compday', '$compmoyr', '$cost', '$charge', '$ordno')"; Link to comment Share on other sites More sharing options...
Skylight_lady Posted January 27, 2011 Share Posted January 27, 2011 Add to the submit input in the form: name="submit" Then change "apt" to "submit" in the action file as shown below: if (isset( $_POST['submit']) ) { Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2011 Share Posted January 27, 2011 Add to the submit input in the form: name="submit" Then change "apt" to "submit" in the action file as shown below: if (isset( $_POST['submit']) ) { That's actually a worse way to check for form submission due to the fact that some browsers don't properly send the value of a submit button. Link to comment Share on other sites More sharing options...
Skylight_lady Posted January 27, 2011 Share Posted January 27, 2011 Do you mean web browsers on a MAC? It tests fine on 7 windows web browsers. I've seen nearly everyone using: if (isset($_POST['submit'])) { So i've always done it that way. Whats a better solution? He has the problem with javascript in the "apt" input ... as not everyone has javascript enabled. Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2011 Share Posted January 27, 2011 Either set a hidden field, and check for its value to be present to detect form submission, or check whether $_SERVER['REQUEST_METHOD'] == the request method of your form; either get or post. Link to comment Share on other sites More sharing options...
ckdoublenecks Posted January 28, 2011 Author Share Posted January 28, 2011 thanks for the help guys Link to comment Share on other sites More sharing options...
Omangryn Posted August 28, 2012 Share Posted August 28, 2012 No to mention you should have stated what errors you were getting. If you want free help at least make the effort to provide the relevant information. If the only problem is that you have a column called replace, then you just need to put backquotes around the field name in your query (which isn't a bad idea just as common practice): $query = "INSERT INTO maintdata (`apt`, `name`, `datereceived`, `time`, `item`, `repair`, `replace`, `action` ,`compday`, `compmoyr`, `cost`, `charge`, `ordno`) VALUES ('$apt', '$name', '$datereceived', '$time', '$item', '$repair', '$replace', '$action', '$compday', '$compmoyr', '$cost', '$charge', '$ordno')"; i think the code is having no problem. Can you generate code for switching LED lights? Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 28, 2012 Share Posted August 28, 2012 This thread is over a year and a half old, and already solved. And what are you even talking about? Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 28, 2012 Share Posted August 28, 2012 Given his email address, I smell a test for posting future spam about LED lights. I locked the thread at about the time you were posting, Pika... Link to comment Share on other sites More sharing options...
Recommended Posts