Jump to content

[SOLVED] Interfacing website with a game.


sjheiss

Recommended Posts

I'm having a little trouble with my PHP and MySQL code. What I'm trying to do is send items to players from a website for a World of Warcraft private server. Problem is, I can't figure out how to take information from one cell, and insert it into a cell in a different table.

 

<img src="http://img185.imageshack.us/img185/7535/charskq6.jpg">

 

<img src="http://img185.imageshack.us/img185/5497/mailboxeb7.jpg">

 

I'm trying to take the info in the table in the 1st pic "guid", and put it in the "receiver_guid" in the 2nd pic.

 

<?php

#################
#               #
#               #
#     Enjoy!    #
#               #
#               #
#################

include("config.php");

error_reporting(E_ALL ^ E_NOTICE);

session_start();

$msg = Array();
$error = Array();

function addUser(){
    if (empty($_POST)) return false;
    global $config, $msg, $error;
    if (empty($_POST['char'])) $error[] = 'Please enter the receivers name.';
    if (empty($_POST['item'])) $error[] = 'Please enter an item ID.';
    if (!empty($error)) return false;
    $db = mysql_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_pass']);
    if (!$db) return $error[] = 'Database: '.mysql_error();
    if (!mysql_select_db($config['mysql_dbname'], $db)) return $error[] = 'Database: '.mysql_error();
    $query = "SELECT * FROM `characters` WHERE `name` = '".mysql_real_escape_string($_POST['char'])."'";
    $res = mysql_query($query, $db);
    if (!$res) return $error[] = 'Database: '.mysql_error();
    $guid = mysql_fetch_array($res, MYSQL_NUM);
    $query = "INSERT INTO `mailbox_insert_queue` (`sender_guid`, `receiver_guid`, `subject`, `body`, `stationary`, `money`, `item_id`, `item_stack`) VALUES (1, '$guid[0]', Your Item, NULL, 41, NULL, '".mysql_real_escape_string($_POST['item'])."', 1)";
    $res = mysql_query($query, $db);
    if (!$res) return $error[] = 'Database: '.mysql_error();
    $msg[] = 'The item has been sent to <span style="color:#00FF00"><strong>'.htmlentities($_POST['char']).'</strong></span>';
    mysql_close($db);
    return true;
}
{
addUser();
}

?>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Contact Info Page</title>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <style type="text/css" media="screen">@import url(server_stats.css);</style>
</head>
<body>
    <center>
    <div class="logo"></div>
    <div style="width:300px">
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
        <table width="100%" border="0" cellspacing="1" cellpadding="3">
            <tr class="head"><th colspan="2">Contact Info</th></tr>
            <tr>
                <th>Receiver: </th><td align="center"><input class="button" type="text" name="char" size="30" maxlength="16"/></td>
            </tr>
            <tr>
                <th>Item ID: </th><td align="center"><input class="button" type="text" name="item" size="30" maxlength="16"/></td>
            </tr>
        </table>
        <input type="button" class="button" value="Back" onClick="history.go(-1)" />
        <input type="submit" value="Give" class="button"/>
        </form>

	<?php
        if (!empty($error)){
            echo '<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td class="error" align="center">';
            foreach($error as $text)
                echo $text.'</br>';
            echo '</td></tr></table>';
        };
        if (!empty($msg)){
            echo '<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td align="center">';
            foreach($msg as $text)
                echo $text.'</br>';
            echo '</td></tr></table>';
            exit();
        };
        ?>

    </div>
    
    </center>
</body>
</html>

Link to comment
Share on other sites

Ok, it's too late for editing (don't know why there is a limit) so I'll post what I was going to edit in here.

 

I am getting this 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 'Item, NULL, 41, NULL, '41130', 1)' at line 1

My MySQL Version: 5.0.45

 

Following is the specific part I am having problems with.

$guid = mysql_fetch_array($res, MYSQL_NUM);
    $query = "INSERT INTO `mailbox_insert_queue` (`sender_guid`, `receiver_guid`, `subject`, `body`, `stationary`, `money`, `item_id`, `item_stack`) VALUES (1, '$guid[0]', Your Item, NULL, 41, NULL, '".mysql_real_escape_string($_POST['item'])."', 1)";

 

I've tried everything I can think of (which wasn't much) and I still get that error.

Link to comment
Share on other sites

you need to quote:   'Your Item'

 

Thank you so much! I'm so tired right now, I must not have been paying attention to it :P

There were a few more things I had to fix, but I saw them when you said to do that, and now it works perfectly!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.