Jump to content

Recommended Posts

here is the code Im working on.

 

<?php
session_start();
$username = $_SESSION['username'];

// php shorthand from the PhPFreaks forum
$buy = (!isset($_GET['buy'])) ? 'main' : $_GET['buy'];

switch($buy){
	case 'firethunder':
	$skillbonus = mt_rand(1,5);

// db config
include('includes/db_config.php');

// Select data from database
$sql = "SELECT * FROM $tbl_name WHERE username='$username'";
$result = mysql_query($sql);

// Put info into array Hopefully
while($row = mysql_fetch_assoc($result)) 
{
// player config
include('includes/player_config.php');

	// check for money if they dont have it let them know else go with transaction
	if($row['onhand'] < '350000'){
		header("Location: mainview.php?show=warnmoney");
		exit();
	}
	else{
	// Update database
	$sql="UPDATE $tbl_name SET
    	onhand = onhand - 350000, 
	skill1_name = replace(skill1_name, '$skill1_name', 'Fire Thunder'),
	skill1_bonus = $skillbonus
	WHERE username='$username'";
	mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
	//header("Location: mainview.php?show=d3buyskills");
	echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=mainview.php?show=d3buyskills\">";
	exit();
	}
	break;
}

	case 'lightpush':
	$skillbonus = mt_rand(1,5);

// db config
include('includes/db_config.php');

// Select data from database
$sql = "SELECT * FROM $tbl_name WHERE username='$username'";
$result = mysql_query($sql);

// Put info into array Hopefully
while($row = mysql_fetch_assoc($result)) 
{
// player config
include('includes/player_config.php');	

	// check for money if they dont have it let them know else go with transaction
	if($row['onhand'] < '350000'){
		header("Location: mainview.php?show=warnmoney");
		exit();
	}
	else{
	// Update database
	$sql="UPDATE $tbl_name SET
    	onhand = onhand - 350000, 
	skill1_name = replace(skill1_name,'$skill1_name','Light Push'),
	skill1_bonus = $skillbonus
	WHERE username='$username'";
	mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
	//header("Location: mainview.php?show=d3buyskills");
	echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=mainview.php?show=d3buyskills\">";
	//exit();
	}
	break;
}

	case 'cleave':
	$skillbonus = mt_rand(1,5);

// db config
include('includes/db_config.php');

// Select data from database
$sql = "SELECT * FROM $tbl_name WHERE username='$username'";
$result = mysql_query($sql);

// Put info into array Hopefully
while($row = mysql_fetch_assoc($result)) 
{
// player config
include('includes/player_config.php');


	// check for money if they dont have it let them know else go with transaction
	if($row['onhand'] < '475000'){
		header("Location: mainview.php?show=warnmoney");
		exit();
	}
	else{
	// Update database
	$sql="UPDATE $tbl_name SET
    	onhand = onhand - 475000, 
	skill2_name = replace(skill2_name,'$skill2_name','Cleave'),
	skill2_bonus = $skillbonus
	WHERE username='$username'";
	mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
	header("Location: mainview.php?show=d3buyskills");
	echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=mainview.php?show=d3buyskills\">";
	exit();
	}
	break;
}

	case 'bash':
	$skillbonus = mt_rand(1,5);

// db config
include('includes/db_config.php');

// Select data from database
$sql = "SELECT * FROM $tbl_name WHERE username='$username'";
$result = mysql_query($sql);

// Put info into array Hopefully
while($row = mysql_fetch_assoc($result)) 
{
// player config
include('includes/player_config.php');

	// check for money if they dont have it let them know else go with transaction
	if($row['onhand'] < '475000'){
		header("Location: mainview.php?show=warnmoney");
		exit();
	}
	else{
	// Update database
	$sql="UPDATE $tbl_name SET
    	onhand = onhand - 475000, 
	skill2_name = replace(skill2_name,'skill2_name','Bash'),
	skill2_bonus = $skillbonus
	WHERE username='$username'";
	mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
	//header("Location: mainview.php?show=d3buyskills");
	echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=mainview.php?show=d3buyskills\">";
	exit();
	}
	break;
}

	case 'coldstun':
	$skillbonus = mt_rand(1,5);

// db config
include('includes/db_config.php');

// Select data from database
$sql = "SELECT * FROM $tbl_name WHERE username='$username'";
$result = mysql_query($sql);

// Put info into array Hopefully
while($row = mysql_fetch_assoc($result)) 
{	
// player config
include('includes/player_config.php');

	// check for money if they dont have it let them know else go with transaction
	if($row['onhand'] < '800000'){
		header("Location: mainview.php?show=warnmoney");
		exit();
	}
	else{
	// Update database
	$sql="UPDATE $tbl_name SET
    	onhand = onhand - 800000, 
	skill3_name = replace(skill3_name,'$skill3_name','Cold Stun'),
	skill3_bonus = $skillbonus
	WHERE username='$username'";
	mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
	//header("Location: mainview.php?show=d3buyskills");
	echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=mainview.php?show=d3buyskills\">";
	exit();
	}
	break;
}

	case 'criticalstrike':
	$skillbonus = mt_rand(1,5);

// db config
include('includes/db_config.php');

// Select data from database
$sql = "SELECT * FROM $tbl_name WHERE username='$username'";
$result = mysql_query($sql);

// Put info into array Hopefully
while($row = mysql_fetch_assoc($result)) 
{
// player config
include('includes/player_config.php');

	// check for money if they dont have it let them know else go with transaction
	if($row['onhand'] < '900000'){
		header("Location: mainview.php?show=warnmoney");
		exit();
	}
	else{
	// Update database
	$sql="UPDATE $tbl_name SET
    	onhand = onhand - 900000, 
	skill3_name = replace(skill3_name,'$skill3_name','Critical Strike'),
	skill3_bonus = $specialbonus
	WHERE username='$username'";
	mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
	//header("Location: mainview.php?show=d3buyskills");
	echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=mainview.php?show=d3buyskills\">";
	exit();
	}
	break;
}
// while and switch delimiters do not add anything else below		

}
?>

 

not sure what the problems is I am trying to get the skill bnames written to the db. so not sure if its a php question or a mysql question. Any help will be appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/139794-solved-not-sure-about-this/
Share on other sites

not sure what the problems is I am trying to get the skill bnames written to the db. so not sure if its a php question or a mysql question.

If you don't know, than neither do we... start debugging your script to identify the problematic section of code.

Sorry for the lack of information. For 1 I am using wamp2.0f and mysql version 5.1.30. I have 6 fields in my database skill1_name, skill1_bonus, skill2_name, skill2_bonus, skill3_name, skill3_bonus.

 

I use this command to execute the script from a form.

 

d3learnskills.php?buy=firethunder

 

what it does do is this, it will change the data for the money and the skill bonus but will not change the skill name in the appropriate location ie it puts a skill3_name in the skill1_name slot and sometimes it will not do that. Now if I write 6 separate scripts to do this it will work I'm just trying to consolidate. I dont get any errors at all it just runs the script but it just seems kinna buggy. 1 more thing I get this warning in phpmyadmin:

Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.1.30. This may cause unpredictable behavior.

 

could this be the culprit?? I hope that makes it a little easier to help??

 

Thanks

Thanks for your reply I read that and also your signature and well it had me thinking and of course I took a break from it for a while and I found out why it was not working.

 

Solution = instead of a form

<form action="d3learnskills.php?buy=lightpush" metod="post">
<br>
<input type="radio" name="skill" value="Light Push">
<br>
<input type=submit value="Learn This Skill">

 

That will not work with the script that way. However this will:

<a href="d3learnskills.php?buy=lightpush">Learn this Skill</a>

 

I could write different code to set it up in the way of a form but the one that works is fine for me. I learned 2 things 1 if something frustrates you sleep on it and come back to it. 2 How to accomplish what your wanting to do specifically.

 

Thanks again.

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.