Jump to content

Plz Help - Process Script for Rock Paper Scissors


affc

Recommended Posts

Hello,

 

I am slowly getting through my PHP script for Rock Paper Scissors but hit a road block with this part of the script - process.php.

 

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.

<?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 Continue from above script.

<?php

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(); 

?>

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.