Revcms Faction Maker (FalloutRP) (NonHabbo)

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
So basically I am shit with PHP.... but I need something to insert into the database the values
owner which would be the user who made it (Not On Form)
name which would be the name of the faction (On Form)
Also if possible when you make a faction it takes 500 credits away.

Heres a look at my database
4fa8799db8314231b12f187.png
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '1')");
This is all I can give you with the information you gave me.
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
PHP:
mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '1')");
This is all I can give you with the information you gave me.
could you possibly however add more of it. As in make the owner take from the form "f_owner" and and then if possible add something where it takes 500c from the create or who "name" is.
Thanks though ^_^
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
Then I need the script it needs to be build in. I can't just make it up if you want to intergrate it.
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
Then I need the script it needs to be build in. I can't just make it up if you want to intergrate it.
kk so heres the form
I cant code php so yea...
Code:
<form method='post'>
// dk
        <table style="width: 100%;">
             
            <tr>
                <td>Faction Name</td></td>
                <td><input type="text" name="Name" value="<?php echo $_POST['f_name']; ?>" style="width: 95%" /></td>
            </tr>
         
        </table>
        <input type="submit" value="Create" name="create"/>
// Add Code To Take away 1000 credits here
// Add Code To Submit The Owner as the user who pushed submit?
</form>
 

Khalil

IDK
Dec 6, 2011
1,642
786
kk so heres the form
I cant code php so yea...
Code:
<form method='post'>
    <input type="hidden" name="username_current" value="<?php echo $_POST['l_username']; ?>" />
 
        <table style="width: 100%;">
             
            <tr>
                <td>Faction Name</td></td>
                <td><input type="text" name="Name" value="<?php echo $_POST['f_name']; ?>" style="width: 95%" /></td>
            </tr>
         
        </table>
        <input type="submit" value="Create" name="create"/>
// Add Code To Take away 1000 credits here
// Add Code To Submit The Owner as the user who pushed submit?
</form>

You do know that the "// add code" part is going to show up on the page, unless you do <?php //what ever here ?> or <!-- What ever here -->.
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
You do know that the "// add code" part is going to show up on the page, unless you do <?php //what ever here ?> or <!-- What ever here -->.
I know it will LOL...It for Holmes mainly
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
I'm sure you did, oh sorry i thought anyone could help out a noob, sorry, please continue your help.
Well if you want to make it then fine by me, but holmes was helping me at the time. Your just pointing our fuckups
Edit NVD Holmes I got most of it done with your original code
just need to add
Post Name
any help?
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
<?php
if ($_POST['create'])
{
    mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '1')");
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 1);
    $newCreditAmount = $creditAmount - 500;
    mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
   
    echo 'Faction has been created!';
}
?>
<form method='post' action=''>
        <table style="width: 100%;">
            <tr>
                <td>Faction Name</td></td>
                <td><input type="text" id="name" name="name" value="Enter faction name" style="width: 95%" /></td>
            </tr>
        </table>
        <input type="submit" value="Create" id="create" name="create"/>
</form>
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
PHP:
<?php
if ($_POST['create'])
{
    mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '1')");
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 1);
    $newCreditAmount = $creditAmount - 500;
    mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
 
    echo 'Faction has been created!';
}
?>
<form method='post' action=''>
        <table style="width: 100%;">
            <tr>
                <td>Faction Name</td></td>
                <td><input type="text" id="name" name="name" value="Enter faction name" style="width: 95%" /></td>
            </tr>
        </table>
        <input type="submit" value="Create" id="create" name="create"/>
</form>
thanks
 

Khalil

IDK
Dec 6, 2011
1,642
786
PHP:
<?php
if ($_POST['create'])
{
    mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '1')");
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 1);
    $newCreditAmount = $creditAmount - 500;
    mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
 
    echo 'Faction has been created!';
}
?>
<form method='post' action=''>
        <table style="width: 100%;">
            <tr>
                <td>Faction Name</td></td>
                <td><input type="text" id="name" name="name" value="Enter faction name" style="width: 95%" /></td>
            </tr>
        </table>
        <input type="submit" value="Create" id="create" name="create"/>
</form>

Sometimes it fucks up and throw an error on the page and some noobs don't know how to fix it, it's the if($_POST['']) statement, could of done an if(isset($_POST[''])), would reduce any errors he might face.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
Sometimes it fucks up and throw an error on the page and some noobs don't know how to fix it, it's the if($_POST['']) statement, could of done an if(isset($_POST[''])), would reduce any errors he might face.
The if only happens when the variable has been set. It will not turn any errors. Adding an isset() is completely your own choice, however for the simplicity I didn't add it.
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
OMG Homes u no add the name
I changed the think to make the user id changed to owner.
Now I need to be able to post name
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
OMG Homes u no add the name
I changed the think to make the user id changed to owner.
Now I need to be able to post name
Maybe because you gave the preview as name '1', which lets me think you need a user id. Like I said, be more clear.
However, use this then:

PHP:
<?php
if ($_POST['create'])
{
$username = $users->getInfo($_SESSION['user']['id'], 'username');
    mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$username."', '1')");
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 1);
    $newCreditAmount = $creditAmount - 500;
    mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
 
    echo 'Faction has been created!';
}
?>
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
Maybe because you gave the preview as name '1', which lets me think you need a user id. Like I said, be more clear.
However, use this then:

PHP:
<?php
if ($_POST['create'])
{
$username = $users->getInfo($_SESSION['user']['id'], 'username');
    mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$username."', '1')");
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 1);
    $newCreditAmount = $creditAmount - 500;
    mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
 
    echo 'Faction has been created!';
}
?>
8508cfa4ab884d95b51a3fd.png

And Doesnt Update Database at all
Basically let me give you re run
The Faction Name Form = Name
Owner = the user id
Official = 0 by default
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
<?php
if ($_POST['create'])
{
    mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '0')");
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 0);
    $newCreditAmount = $creditAmount - 500;
    mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
$success = true;
}
 
if (isset($success) && $success === true)
{
    echo 'Faction has been created!';
}
?>

Try that.

EDIT:
RevCMS OOP special (optional):
PHP:
<?php
if ($_POST['create'])
{
    $engine->query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '0')");
    $creditAmount = $engine->result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ");
    $newCreditAmount = $creditAmount - 500;
    $engine->query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
$success = true;
}
 
if (isset($success) && $success === true)
{
    echo 'Faction has been created!';
}
?>
 

IntactDev

Member
Nov 22, 2012
399
71
Here is a little edit of what put... I cleaned the code a little, and I added a little function to check if the user even hass 500+ credits, so they don't end up in the negatives.

PHP:
<?php
if (isset($_POST['create']) && !empty($_POST['create'])) {
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 0);
 
    if($creditAmount >= 500) { # Check if user has 500 credits or more #
 
        mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '0')");
        $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 0);
        $newCreditAmount = $creditAmount - 500;
        mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
    } else {
        echo "You do not have enough credits!";
    }
}
?>
 

Leader

github.com/habbo-hotel
Aug 24, 2012
1,006
267
Creates factions but returns error
Here is a little edit of what put... I cleaned the code a little, and I added a little function to check if the user even hass 500+ credits, so they don't end up in the negatives.

PHP:
<?php
if (isset($_POST['create']) && !empty($_POST['create'])) {
    $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 0);
 
    if($creditAmount >= 500) { # Check if user has 500 credits or more #
 
        mysql_query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '0')");
        $creditAmount = mysql_result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ", 0);
        $newCreditAmount = $creditAmount - 500;
        mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
    } else {
        echo "You do not have enough credits!";
    }
}
?>
Thanks, works fine but
Like Khalil said Im a newb with php and it returns an error I cant fix. Plus with yours I have 5000 credits (Just updated/logged out/logged in) and it says I dont have enough :p
arning: mysql_result() expects parameter 1 to be resource, string given in/home/leader/public_html/Fallout/app/tpl/skins/Fallout/fmake.phpon line 14
You do not have enough credits!
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
Creates factions but returns error
Thanks, works fine but
Like Khalil said Im a newb with php and it returns an error I cant fix. Plus with yours I have 5000 credits (Just updated/logged out/logged in) and it says I dont have enough :p

PHP:
<?php
if (isset($_POST['create']))
{
    $creditAmount = $engine->result("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."' ");
    $newCreditAmount = $creditAmount - 500;
 
    if ($newCreditAmount >= 0)
    {
        $engine->query("INSERT INTO factions(name,owner,official) VALUES('".$_POST['name']."', '".$_SESSION['user']['id']."', '0')");
        $engine->query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
        echo 'Faction has been created!';
    }
    else
    {
        echo 'You don\'t have enough credits!';
    }
}
?>
Also, which error does it return?
 

Users who are viewing this thread

Top