Hi, I'm creating a plugin for wordpress for a portfolio and it's nearly done, I'm going through testing right now and during that time of course I came across something that baffles me lol.
An section from the backend is not posting and saving to my database like it should but another section just like it does.
DB table name = wp_smack_types
Here is my code and I'll post all of it just in-case the problem doesn't pertain to only one section.
PHP Code:
<?php global $wpdb; $cat_tbl=$wpdb->prefix.'smack_types'; if(isset($_GET['edit']) && $_GET['edit']!="") { require("edit_type.php"); exit; } if(isset($_GET['del'])) { $del_id=$_GET['del']; if($del_id!="") { $qry="delete from ".$cat_tbl." where id=".$del_id; $wpdb->query($qry); echo "<div class='updated settings-error' id='setting-error-settings_updated'> <p><strong>Project type Deleted.</strong></p></div>"; } } if($_POST){ $title=$_POST['type_name']; $desc=$_POST['item_desc']; $title_=strtolower($title); $slug=str_replace(" ","_",$title_); if($title!="" && $desc!=""){ $qry="insert into ".$cat_tbl."(slug,title,description) values('".$slug."','".$title."','".$desc."')"; $wpdb->query($qry); echo "<div class='updated settings-error' id='setting-error-settings_updated'> <p><strong>Project type saved.</strong></p></div>"; } } ?> <style type="text/css"> label{ display:block; } </style> <h2>Add Project Types</h2>
<form action="?page=smack3_manage_project_types" method="post"> <p><label for="item_type">Project Type: </label><input type="text" name="type" id="item_type" /><i>e.g. web design, logo, php application</i></p> <p><label for="item_desc">Project Type Description: </label><textarea rows="5" cols="25" name="item_desc"></textarea></p> <p><input class="button-primary" type="submit" value="Add Project Type" /></p>
</form> <?php
$qry="SELECT * from ".$cat_tbl; $rows=$wpdb->get_results($qry,ARRAY_A); if(count($rows)<1){ echo "No Project Types Found"; exit; } ?> <table class="form-table widefat" border="1"> <tbody> <tr> <th>Project Type</th> <th>Project Type Description</th> <th>Edit</th> <th>Delete</th> </tr>
<?php foreach ($rows as $row){ ?> <tr> <td><?php echo $row['title']; ?></td> <td><?php echo $row['description']; ?></td> <td><a href="?page=smack3_manage_project_types&edit=<?php echo $row['id'];?>">Edit</a></td> <td><a href="?page=smack3_manage_project_types&del=<?php echo $row['id'];?>">Delete</a></td> </tr> <?php } ?> </tbody> </table>
Here is the code for the section that does post and save.
DB table name = wp_smack_clients
PHP Code:
<?php global $wpdb; $client_tbl=$wpdb->prefix.'smack_clients'; if(isset($_GET['edit'])) { $edit_id=$_GET['edit']; if($edit_id!="") { require("edit_client.php"); exit; } } if(isset($_GET['del'])) { $del_id=$_GET['del']; if($del_id!="") { $qry="delete from ".$client_tbl." where id=".$del_id; $wpdb->query($qry); echo "<div class='updated settings-error' id='setting-error-settings_updated'> <p><strong>Client has been Deleted.</strong></p></div>"; } } if($_POST){ $title=$_POST['client_name']; $title_=strtolower($title); $slug=str_replace(" ","_",$title_); if($title!=""){ $qry="insert into ".$client_tbl."(slug,name) values('".$slug."','".$title."')"; $wpdb->query($qry); echo "<div class='updated settings-error' id='setting-error-settings_updated'> <p><strong>Client Name saved.</strong></p></div>"; } } ?> <style type="text/css"> label{ display:block; } </style> <h2>Manage Your Clients</h2>
<form action="?page=smack3_manage_client" method="post"> <p><label for="item_type">Client Name: </label><input type="text" name="client_name" id="client_name" /></p>
<p><input class="button-primary" type="submit" value="Save Client" /></p>
</form>
<?php
$qry="SELECT * from ".$client_tbl; $rows=$wpdb->get_results($qry,ARRAY_A); if(count($rows)<1){ echo "No Clients Found"; exit; } ?> <table class="form-table widefat" border="1"> <tbody> <tr> <th>Client Name</th> <th>Edit</th> <th>Delete</th> </tr>
<?php foreach ($rows as $row){ ?> <tr> <td><?php echo $row['name']; ?></td> <td><a href="?page=smack3_manage_client&edit=<?php echo $row['id'];?>">Edit</a></td> <td><a href="?page=smack3_manage_client&del=<?php echo $row['id'];?>">Delete</a></td> </tr> <?php } ?> </tbody> </table>
Any help is greatly appreciated.
|