Jump to content

can't find error


ckdoublenecks

Recommended Posts

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

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

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

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

  • 1 year later...

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.