简体   繁体   中英

Trying to get form to submit to database. Errors: Undefined index and Unedified Variable

Notice: Undefined index: confirmed in Notice: Undefined variable: fromplot1 in

 mysql_connect("$host", "$username", "$password")or die("cannot connect"); 

 mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['submit']));
{
  $confirmed=$_POST['confirmed'];

  $fromPlot1=$_POST['fromplot1']; 

  $toPlot1=$_POST['toplot1']; 

 $fromPlot2=$_POST['fromPlot2']; 

 $toPlot2=$_POST['toplot2']; 

 $trench=$_POST['trench']; 

 $installDate=$_POST['installdate']; 

 $pipe=$_POST['pipe']; 

 $sql ="INSERT INTO $tbl_name (confirmed, fromplot1, toplot1, fromplot2, toplot2, 
 trench, installdate, pipe ) 
 VALUES ('$confirmed','$fromplot1','$toplot1','$fromplot2','$toplot2','$trench','$installDate','$pipe)";
}
  ?>    

Would be very grateful for someone to find the problem with this. New to php coding!!

Here is the form! Hope this can help. Thanks for the replies also!

<input type="checkbox" name="confirmed:" value="Confirmed"> CSEP/Mains Work Confirmed As<br>

    </li><br/>
     <div  class="mainForm" id="onsite">
    <label class="formFieldQuestion" >Onsite Mains (Public highway)  - <Br>  <label for="company">

<span>From Plot:</span>
 <input type="text"  name="fromplot1" />
 </label>

<label for="company">
 <span>To Plot:</span>
 <input type="text" name="toplot1" />
 </label><br>
<br/>

  </li>
     <div  class="mainForm" id="offsite">
<label class="formFieldQuestion">Offsite Mains  - <Br> <label for="company">
 <span>From Plot:</span>
 <input type="text"  name="fromplot2"  />
 </label>
<label for="company">
 <span>To Plot:</span>
    <input type="text"  name="toplot2" />
</label> <br>

</br>

 </li>
     <div  class="mainForm" id="trench">
<label class="formFieldQuestion" name="trench">Is the water in the same trench? <select> <option value="Yes">Yes</option> <option value="No">No</option> </select><br>
<br/>

                <div class="mainForm">
                    <label class="formFieldQuestion">If so, when was the water main installed? &nbsp;  <input type="date" name="installdate"><br>
<br/>

<br/>

                    <label class="formFieldQuestion">Is there sufficient pipe on site to complete the job?&nbsp;*</label><span><input class=mainForm type=radio name="pipe"  value="Yes" /><label class=formFieldOption for="field_7_option_1">Yes</label><input class=mainForm type=radio name=pipe value="No" /><label class=formFieldOption for="pipe">No</label></span><br>

                </div><br/><div class="mainForm" >

use this

<?php

    mysql_connect("$host", "$username", "$password")or die("cannot connect");//   mysql_connect('localhost', 'user', '')or die("cannot connect");

    mysql_select_db("$db_name")or die("cannot select DB");

    if(isset($_POST['submit']))
    {
        $confirmed=$_POST['confirmed'];
        $fromPlot1=$_POST['fromplot1'];
        $toPlot1=$_POST['toplot1'];
        $fromPlot2=$_POST['fromPlot2'];
        $toPlot2=$_POST['toplot2'];
        $trench=$_POST['trench'];
        $installDate=$_POST['installdate'];
        $pipe=$_POST['pipe'];

        $sql ="INSERT INTO $tbl_name (confirmed, fromplot1, toplot1, fromplot2, toplot2,
 trench, installdate, pipe ) VALUES ('$confirmed','$fromplot1','$toplot1','$fromplot2','$toplot2','$trench','$installDate','$pipe')";

        mysql_query($sql);
    }
?>

And <input type="checkbox" name="confirmed:" value="Confirmed"> should be <input type="checkbox" name="confirmed" value="Confirmed">

Note Make sure $host , $username , $password , $tbl_name and $db_name is define.

And check form method <form method="post"..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM