Jump to content
MakeWebGames

[V2] Staff Items


Magictallguy

Recommended Posts

Hey people. I'm trying to create a kill itemtype function in the staff_items.php script. I've got most of it right..Up until the SELECT query..

function kill_itemtype_form()

{

global $db,$ir,$c,$h,$userid;

if($ir['user_level'] > 2)

{

die("403");

}

 

print "<h3>Deleting Item Type</h3>
The item type will be permanently removed from the game.

<form action='staff_items.php?action=killitemtypesub' method='post'>
Item Type: ".itemtype_dropdown($c,'itmtype',$itemi['itmtype'])."

<input type='submit' value='Kill Item Type' /></form>";
}
function kill_itemtype_submit()
{
global $db,$ir,$c,$h,$userid;
if($ir['user_level'] > 2)
{
die("403");
}

$d=$db->query("SELECT * FROM itemtypes WHERE itmtypeid={$_POST['itemtype']}");
$itemi=$db->fetch_row($d);
$db->query("DELETE FROM itemtypes WHERE itmtypeid={$_POST['itmtypeid']}");

print "The item type {$itemi['itmtypename']} was removed from the game.";
stafflog_add("Deleted item type {$itemi['itmtypename']}");
}

 

Can anyone enlighten me as to why it doesn't like that please?

QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Query was SELECT * FROM itemtypes WHERE itmtypeid=

Link to comment
Share on other sites

Re: [V2] Staff Items

There's a couple things that are off here.

Item Type: ".itemtype_dropdown($c,'itmtype',$itemi['itmtype'])."

 

$itemi['itmtype'] << which would be the "selected" field, that determines what item type is selected by default in the drop down.

However, that variable appears to be undefined. That should be an optional deal, I suggest you leave it out as such --

Item Type: ".itemtype_dropdown($c,'itmtype')."

 

And then, you are naming the variable itmtype, but your variable in the sub portion, and in the select is named: $_POST['itemtype']

and in the delete it's named: $_POST['itmtypeid']

Both do not match what you named it ealier. so, you're submitting an empty field in your query.

If you had echoed your query, you would have seen this:

SELECT * FROM itemtypes WHERE itmtypeid=

[edit = I realize now that the query was echoed out for you lol. I forget that mc vs2 does that for you.]

with no number after the =

which is EXACTLY why your query failed. the delete query will fail as well, if the script where to make it past the select query.

Link to comment
Share on other sites

Re: [V2] Staff Items

I've updated it to what you said..Still isn't having it.. :(

function kill_itemtype_form()
{
global $db,$ir,$c,$h,$userid;
if($ir['user_level'] > 2)
{
die("403");
}


print "<h3>Deleting Item Type</h3>
The item type will be permanently removed from the game.

<form action='staff_items.php?action=killitemtypesub' method='post'>
Item Type: ".itemtype_dropdown($c,'itmtype')."

<input type='submit' value='Kill Item Type' /></form>";
}
function kill_itemtype_submit()
{
global $db,$ir,$c,$h,$userid;
if($ir['user_level'] > 2)
{
die("403");
}

$d=$db->query("SELECT * FROM itemtypes WHERE itmtypeid={$_POST['itmtypeid']}");
$itemi=$db->fetch_row($d);
$db->query("DELETE FROM itemtypes WHERE itmtypeid={$_POST['itmtypeid']}");

print "The item type {$itemi['itmtypename']} was removed from the game.";
stafflog_add("Deleted item type {$itemi['itmtypename']}");
}
Link to comment
Share on other sites

Re: [V2] Staff Items

Lemme explain this a bit more thoroughly.

When you use the itemtype_dropdown() function, there are three arguments you can pass to it. The function is defined like this:

function itemtype_dropdown($connection,$ddname="item_type",$selected=-1)

$connection being the database connection. You have that one in fine.

$ddname is the "drop down name" which is akin to doing <select name="itmid">. So, if you pass "itmid" in the second argument, that will be the name of your drop down.

$selected determines which item is selected. Since this function uses the itmid from the items database table, you'd have to pass a valid item id in order to have an item selected by default.

$ddname and $selected both have defaults, which mean they do not need to be passed as arguments, however for the sake of readability, I do suggest that you pass at least the second argument which names your select form element because if you didn't do that, you'd need to know what the default name is.

Now, is you pass "itmid" as the $ddname, the second argument in the function, you will be naming that select field "itmid". Later on, when you've submitted that as a post, you will need to use this variable {$_POST['itmid']} in order to access the value that was submitted by the select field named "itmid".

With that ground work laid, let's examine your code again.

itemtype_dropdown($c,'itmtype') <<< this is your function that creates a select form field and names it "itmtype".

$d=$db->query("SELECT * FROM itemtypes WHERE itmtypeid={$_POST['itmtypeid']}"); <<<<<< This is your query that uses the variable: $_POST['itmtypeid'] which has not been defined in your script. Your select form field name is "itmtype" not "itmtypeid".

Therefore, I suspect you are still getting the same mysql error, with the same query showing up. You did not post your error, or even say what the error was this time, which could have been helpful in debugging this for you.

Anyways, I hope I've been thorough enough :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...