View Full Version : +Rep Coding Help
Naythi.
28-05-2007, 11:48 AM
Hi
I want a code that when i type in a word
Example :
Credits = 9981
So when i type in CREDITS it gives me a Voucher Code / a code
It dosent have to say credits thats just an example !
+rep for all helpers !
:Edzy
28-05-2007, 12:44 PM
what so a random string generator?
Matt.
28-05-2007, 12:52 PM
what so a random string generator?
Think so?
Be something like this I think
<?php
echo rand() . "\n";
?>
Edit: Sorry, thats not really going to help. I should have read all the first post, sorry.
Naythi.
28-05-2007, 01:24 PM
Yeah a random text thingy !
So when i type a code it says a reaction
Like with a bot , When you say coke , They say coke yeas rite away or sumtin !
:Edzy
28-05-2007, 01:51 PM
what so you say
CREDITS 100
-845845
next lot of credits
CREDITS 100
-845845
that might be a problem :P
Naythi.
29-05-2007, 12:08 PM
Anybody know a Random Text Genorator ??
So it reacts with the Word
LIKE A BOT !
Naruto!
29-05-2007, 12:19 PM
i dont get you
Drompo
29-05-2007, 01:04 PM
<?php
if($_GET["action"] == "send") {
$text = $_POST["text"];
if($text == "credits") { // The Word that it responds too
echo rand() . "\n"; // What it says if the word you selected is the input
} else {
echo "You didn't not type credits correctly"; // The Output when the word you specify isn't the input
}
}
?>
<form name="credits" method="post" action="?action=send">
<input type="text" name="text">
<input type="submit" value="submit">
</form>
:Edzy
29-05-2007, 01:06 PM
<?php
if($_GET["action"] == "send") {
$text = $_POST["text"];
if($text = "credits") {
echo rand() . "\n";
} else {
echo "You didn't not type credits correctly";
}
}
?>
<form name="credits" method="post" action="?action=send">
<input type="text" name="text">
<input type="submit" value="submit">
</form>
nice, wd :D
Drompo
29-05-2007, 01:09 PM
Thanks.
It works but is VERY Basic. I just made it up as i went along
Use this
<?php
$hostname = ("localhost");
$database = ("database");
$username = ("username");
$password = ("password");
mysql_connect($hostname, $username, $password);
mysql_selectdb($database);
function clean($string)
{
// This is from KP2 - Thanks!
$string = str_replace("\"", "", $string);
$string = nl2br($string);
$string = htmlentities($string);
$words = array("UNION",
"SELECT FROM",
"ORDER BY",
"INSERT INTO",
"TRUNCATE",
"DROP TABLE",
"CREATE TABLE",
"DROP DATABASE"); // All the queries we want to stop
$string = preg_replace("/$words/i", "", $string);
return $string;
}
switch($_GET["act"])
{
default:
if(isset($_POST["credits"]))
{
if(is_numeric($_POST["credits"]))
{
for($i=0; $i<"8"; $i++)
{
$randnum = mt_rand(0,61);
if($randnum < 10)
{
$randstr .= chr($randnum+48);
}
else if($randnum < 36)
{
$randstr .= chr($randnum+55);
}
else
{
$randstr .= chr($randnum+61);
}
}
$string = strtolower($randstr);
$value = clean($_POST["credits"]);
mysql_query("INSERT INTO `credits` (`value`, `string`) VALUES ('$value', '$string')");
echo 'You have created ' . $_POST["credits"] . ' Credits! - Your code is ' . $string . ' Have fun!';
} else {
echo 'Your amount of credits is not a number';
}
}
else {
?>
Add credits (ammount)
<br />
<form action="check.php" method="POST">
<input name="credits" type="text" />
<input type="submit" value="Submit!" />
</form>
<?php
}
break;
case submit:
{
if(isset($_POST["credit"]))
{
$credits = clean($_POST["credit"]);
$sql = mysql_query("SELECT * FROM `credits` WHERE `string` = '$credits'");
if(mysql_num_rows($sql) == "1")
{
$fetch = mysql_fetch_array($sql);
$value = $fetch["value"];
echo "Correct voucher code! Also, if you wanted it to add the the users credits, add a mysql insert for the user to earn some credits, with the credit value as $value";
mysql_query("DELETE FROM `credits` WHERE `credits`.`value` = '$value' AND CONVERT(`credits`.`string` USING utf8) = '$credits'");
} else {
echo "Invalid code";
}
} else
{
echo 'Redeem credits<br />
<form action="check.php?act=submit" method="POST">
<input name="credit" type="text" />
<input type="submit" value="Submit!" />
</form>';
}
}
break;
}
?>
Call it create.php
And for the database:
CREATE TABLE `credits` (
`value` VARCHAR( 225 ) NOT NULL ,
`string` VARCHAR( 225 ) NOT NULL
) ENGINE = MYISAM ;
It creates a credit code, then a user types in the code at create.php?act=submit then you need to add a thing which updates their credits by the ammount, then it deletes it.
Have fun (edit mysql details aswell!)
Edit: ignore my crap coding
Mr Macro
29-05-2007, 03:17 PM
<?php
$answerto = 'Hello';
if ($_GET['action'] == 'send'){
$text = $_POST['text']
if ($text == $answerto){
echo('Hello too you too.');
}else{
echo('What?');
}
}
?>
You mean a chat bot basically ?
<?php
$answerto = 'Hello';
if ($_GET['action'] == 'send'){
$text = $_POST['text']
if ($text == $answerto){
echo('Hello too you too.');
}else{
echo('What?');
}
}
?>
You mean a chat bot basically ?
No..??
Mr Macro
29-05-2007, 06:02 PM
oh :P I also forgot too put the form in :P
Naythi.
29-05-2007, 10:23 PM
Hummm that code didnt work ?
When i type in credits
It didnt come up with the text what its suppose to !
PLEASE HELP ! I NEED BADLY !
(TO THE FIRST CODE)
Second Code :
Worked but was not what need
I NEED IT SO
If i Type in a Numba it will react
DOESNT HAVE TO BE MYSQL
So i type in like cola , Then it will recognise that i want a cola and type back heres your cola or A Message popup sayin heres your cola
OR HERES YA CREDITS !
ANYWAYS THANSK FOR HELPING +REP !
Reina to use IFs you need "==", "=" is for declaring variables.
You could use a switch function:
<?
$credits = ?? GET DATA FROM FILE, TABLE, GET, POST ETC?
$x = $_POST['drink']; // Gets drink value
switch($x) {
case 'cola':
echo "You have chosen cola?<br />";
$credits = $credits+1;
echo "You now have:" . $credits . " credits ";
break;
case 'blood':
echo "You have chosen Blood?";
$credits = $credits+1;
echo "You now have:" . $credits . " credits ";
break;
default:
echo "You chosen an unknown drink";
break;
}
?>
Hummm that code didnt work ?
When i type in credits
It didnt come up with the text what its suppose to !
PLEASE HELP ! I NEED BADLY !
(TO THE FIRST CODE)
Second Code :
Worked but was not what need
I NEED IT SO
If i Type in a Numba it will react
DOESNT HAVE TO BE MYSQL
So i type in like cola , Then it will recognise that i want a cola and type back heres your cola or A Message popup sayin heres your cola
OR HERES YA CREDITS !
ANYWAYS THANSK FOR HELPING +REP !
On my one, you type in how many credits and it makes a code for it, and puts it in mysql. Then you go to create.php?act=submit and type in that code, and then it says if you got it right, and then you need to add a mysql insert to add the credits to the user
Drompo
30-05-2007, 10:21 AM
Reina to use IFs you need "==", "=" is for declaring variables.
You could use a switch function:
I ain't stupid. Don't tel me how to code when the code was correct
:Edzy
30-05-2007, 04:44 PM
I ain't stupid. Don't tel me how to code when the code was correct
lol ur :)
Jokzzz
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.