Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need help with my custom wordpress plugin.
Old 01-10-2011, 01:17 AM Need help with my custom wordpress plugin.
Whathadiv's Avatar
Super Talker

Posts: 99
Name: Justin Paul
Trades: 0
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.
Whathadiv is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-10-2011, 10:38 AM Re: Need help with my custom wordpress plugin.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Are you getting any error messages? Try displaying sql errors:
http://codex.wordpress.org/Function_...ide_SQL_Errors
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-15-2011, 05:53 PM Re: Need help with my custom wordpress plugin.
Whathadiv's Avatar
Super Talker

Posts: 99
Name: Justin Paul
Trades: 0
I didn't find any errors so I'm still stuck on this. It's kind of weird because the code is the same for both files that use the same type of query.
Whathadiv is offline
Reply With Quote
View Public Profile
 
Old 01-17-2011, 02:09 AM Re: Need help with my custom wordpress plugin.
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
If you're sure you're not getting db-related errors then it would seem that the branch of code to perform the query isn't being executed. Bung in a few echo statements and a few else branches to see where it's going.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-17-2011, 02:35 AM Re: Need help with my custom wordpress plugin.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by PaulW View Post
If you're sure you're not getting db-related errors
Just to build on this: If you want to be sure that the problem isn't with your query you should output the query and try executing it directly from console or phpmyadmin or something similar.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Need help with my custom wordpress plugin.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.68614 seconds with 12 queries