/    Sign up×
Community /Pin to ProfileBookmark

Im looking for help with PHP

Hello,

I really need a professional that knows PHP to get some of my script working properly. I have been in the process of getting a Rock, Paper, Scissors game together and would love to share the whole thing once finished but am stuck on the final process script if anyone could help please post a reply and I will repost the script for you to look at,

Thanx in advance

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 23.2008 — you should have posted code right away. use the forums [noparse][code=php] and [/code][/noparse] tags.[code=php]switch($_GET['pick']){// get choice:
case 'rock':
$user = 1;
break;
case 'paper':
$user = 2;
break;
case 'sissors':
$user = 3;
break;
default:
$user = 0;
break;
};
if($user){// if playing:
$comp = rand(1, 3);// generate random pick
$choices = array(1=>'rock', 2=>'paper', 3=>'sissors');
echo "<p>You picked {$choices[$user]}.</p>
<p>computer picked {$choices[$comp]}.</p>";
// work out who's won:
if($user == $comp)
echo "<p>DRAW</p>";
if($user+1 == $comp || ($user == 3 && $comp == 1))
echo "<p>COMPUTER VICTORY</p>";
if($user == $comp+1 || ($user == 1 && $comp == 3))
echo "<p>USER VICTORY</p>";
};
echo "<p>pick a choice:</p>
<p><a href='?pick=rock'>rock</a>
<a href='?pick=paper'>paper</a>
<a href='?pick=sissors'>sissors</a></p>";[/code]
Copy linkTweet thisAlerts:
@blue-eye-labsFeb 23.2008 — yeah... always just post the script, as scragar said, and then everyone will take a look and try to help.
Copy linkTweet thisAlerts:
@airforcefcauthorFeb 24.2008 — Here is the script Im having trouble with. I didn't post the script because i posted it in another thread but no1 could help. The way I have it working if that a member on my site submits a challenge to another member then the member that received the challenge will submit their pick, then this process needs to be done but cannot get it to work as I do not understand how to make it work,

[code=php]
<?php
//Connect to server and select database.
mysql_connect("$host", "$username1", "$password1")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$id=$_POST['id'];
$defender=$_POST['pkVal0'];
$from_member=$_POST['from_member'];
$to_member=$_POST['to_member'];
$attacker=$_POST['challenger_pick'];

//Need help here

if($attacker selected "1" && $defender selected "2") then
defender wins
elseif(attacker selected "1" && defender selected "3") then
attacker wins

if($attacker selected "2" && $defender selected "1") then
attacker wins
elseif(attacker selected "2" && defender selected "3") then
defender wins

if($attacker selected "3" && $defender selected "1") then
defender wins
elseif(attacker selected "3" && defender selected "2") then
attacker wins

If attacker = defender selection both = "DRAW"

//Add points up
from_memberladder= 1 point for $WIN,$Draw,$Loss
to_memberladder= 1 point for $WIN,$Draw,$Loss

// Insert data from Attacker into database
$sql="INSERT INTO gameladder(member,win,draw,loss)VALUES('$from_memberladder','$win','$draw','$loss')";
$result=mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());


// Insert data from Defender into database
$sql="INSERT INTO gameladder(member,win,draw,loss)VALUES('$to_memberladder','$win','$draw','$loss')";
$result=mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());

// Insert HISTORY data into database
$sql="INSERT INTO gamehistory(from_member,from_selected,to_member,to_selected,winner)VALUES('$from_member','$from_selected','$to_member','$to_selected','$winner')";
$result=mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());

if($result){
header("location:rpschallenge.php");
}

else {
echo "ERROR";
}

// close connection
mysql_close();

?>
[/code]
Copy linkTweet thisAlerts:
@airforcefcauthorFeb 24.2008 — This was the extra info that might help also:

I have a selection system where from the FORM where the member selects their pick I have made it so value - rock=1 , paper=2 , scissors=3.

Now once the member selects their opponent, they click submit.

The information goes into a Table:

Table = "game".

id / from_member / to_member / selected

When the member that has received the challenge selects play and picked their selection I have this file that needs to process it all but I am stuck with limited PHP knowledge on this one so roughly did it out how I think it might go.

I also have a Ladder that displays all members with their win,draw,loss totals.

And I have a history for both the attacker and the defender so that each can see who they have played and which people they have won and lost again and also each players moves.
×

Success!

Help @airforcefc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...