php - Inserting data into SQL database not working but said it has -


so website have @ minute isn't inserting data correctly. have id , sub_date (date got submitted) these automatic of thought don't need create variables , stuff? correct me if im wrong?

php code:

<?php if (isset($_post['addbtn'])) {     $m_titleadd = $_post['m_titleadd'];     $authoradd = $_post['authoradd'];     $statusadd = $_post['statusadd'];     $tutorialadd = $_post['tutorialadd'];     if (empty($errors))     {         $sqlinsert = $odb -> prepare("insert `methods` values(null, :id, :m_title, :sub_date, :status, :author, :tutorial)");         $sqlinsert -> execute(array(':id' => null, ':m_title' => $m_titleadd, ':sub_date' => null, ':status' => $statusadd, ':author' => $authoradd, ':tutorial' => $tutorialadd));         echo '<div class="nnote nsuccess hideit"><p><strong>success: </strong>method has been added</p></div>';     }     else     {         echo '<div class="nnote nfailure hideit"><p><strong>error:</strong><br />';         foreach($errors $error)         {             echo '-'.$error.'<br />';         }         echo '</div>';     } } ?> 

html code:

<form action="" method="post">         <fieldset>                 <div class="formrow">                     <label>method title:</label>                     <div class="formright"><input type="text" name="m_titleadd" class="form-control round" style="width:300px;" /></div>                     <div class="clear"></div>                 </div>                 <div class="formrow">                     <label>tutorial:</label>                     <div class="formright"><textarea style="resize:none;" rows="3" cols="15" name="tutorialadd" class="autogrow form-control round"></textarea></div>                     <div class="clear"></div>                 </div>                 <div class="formrow">                     <label>author:</label>                     <div class="formright"><input type="text" name="authoradd" class="form-control round" style="width:300px;" /></div>                     <div class="clear"></div>                 </div>                 <div class="control-group">                 <label class="control-label">type:</label>                 <div class="controls">                 <select class="btn btn-default dropdown-toggle" name="status" tabindex="1">                 <option value="working" />working                 <option value="plausible" />plausible                 <option value="not working" />not working                 </select>                 </div>                 </div><br>                 <div class="formrow">                     <div style="width:100px;"><input type="submit" value="add" name="addbtn" class="btn btn-primary btn-block btn-round" /></div>                      <div class="clear"></div>                 </div><br>         </fieldset>     </form> 

$_post['statusadd'] undefined , in form named status. change following.

change this:

$statusadd = $_post['statusadd']; 

to this:

$statusadd = $_post['status']; 

then insert query make sure change this, don't need specify null id in case:

values(null, :id, etc 

to this:

values(:id, etc 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -