twilitegxa
-
Posts
1,020 -
Joined
-
Last visited
Posts posted by twilitegxa
-
-
But these tables and fields are already being accessed on other pages, so I could create a new one, if needed, but not turn these into one.
`scouts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` datetime NOT NULL,
`username` varchar(150) NOT NULL,
`identity` varchar(150) NOT NULL,
`name` varchar(150) NOT NULL,
`element_of_influence` varchar(150) NOT NULL,
`age` int(2) NOT NULL,
`birth_month` int(2) NOT NULL,
`birth_date` int(2) NOT NULL,
`birth_year` int(4) NOT NULL,
`blood_type` varchar(3) NOT NULL,
`hobbies` varchar(150) NOT NULL,
`favorite_color` varchar(150) NOT NULL,
`favorite_gemstone` varchar(150) NOT NULL,
`favorite_food` varchar(150) NOT NULL,
`least_favorite_food` varchar(150) NOT NULL,
`favorite_school_subject` varchar(150) NOT NULL,
`least_favorite_school_subject` varchar(150) NOT NULL,
`strengths` varchar(150) NOT NULL,
`weaknesses` varchar(150) NOT NULL,
`goal` longtext NOT NULL,
`mission` longtext NOT NULL,
`biography` longtext NOT NULL,
`height_feet` int(2) NOT NULL,
`height_inches` int(2) NOT NULL,
`available` tinyint(1) NOT NULL,
`attack_level` int(11) NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
`knights` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` datetime NOT NULL,
`username` varchar(150) NOT NULL,
`identity` varchar(150) NOT NULL,
`name` varchar(150) NOT NULL,
`emotion_of_influence` varchar(150) NOT NULL,
`age` int(2) NOT NULL,
`birth_month` int(2) NOT NULL,
`birth_date` int(2) NOT NULL,
`birth_year` int(4) NOT NULL,
`blood_type` varchar(3) NOT NULL,
`hobbies` varchar(150) NOT NULL,
`favorite_color` varchar(150) NOT NULL,
`favorite_gemstone` varchar(150) NOT NULL,
`favorite_food` varchar(150) NOT NULL,
`least_favorite_food` varchar(150) NOT NULL,
`favorite_school_subject` varchar(150) NOT NULL,
`least_favorite_school_subject` varchar(150) NOT NULL,
`strengths` varchar(150) NOT NULL,
`weaknesses` varchar(150) NOT NULL,
`goal` longtext NOT NULL,
`mission` longtext NOT NULL,
`biography` longtext NOT NULL,
`height_feet` int(2) NOT NULL,
`height_inches` int(2) NOT NULL,
`available` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
`fdark_warrior` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` datetime NOT NULL,
`username` varchar(150) NOT NULL,
`identity` varchar(150) NOT NULL,
`name` varchar(150) NOT NULL,
`element_of_influence` varchar(150) NOT NULL,
`age` int(2) NOT NULL,
`birth_month` int(2) NOT NULL,
`birth_date` int(2) NOT NULL,
`birth_year` int(4) NOT NULL,
`blood_type` varchar(3) NOT NULL,
`hobbies` varchar(150) NOT NULL,
`favorite_color` varchar(150) NOT NULL,
`favorite_gemstone` varchar(150) NOT NULL,
`favorite_food` varchar(150) NOT NULL,
`least_favorite_food` varchar(150) NOT NULL,
`strengths` varchar(150) NOT NULL,
`weaknesses` varchar(150) NOT NULL,
`goal` longtext NOT NULL,
`mission` longtext NOT NULL,
`biography` longtext NOT NULL,
`height_feet` int(2) NOT NULL,
`height_inches` int(2) NOT NULL,
`available` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
`mdark_warrior` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`create_time` datetime NOT NULL,
`username` varchar(150) NOT NULL,
`identity` varchar(150) NOT NULL,
`name` varchar(150) NOT NULL,
`element_of_influence` varchar(150) NOT NULL,
`age` int(2) NOT NULL,
`birth_month` int(2) NOT NULL,
`birth_date` int(2) NOT NULL,
`birth_year` int(4) NOT NULL,
`blood_type` varchar(3) NOT NULL,
`hobbies` varchar(150) NOT NULL,
`favorite_color` varchar(150) NOT NULL,
`favorite_gemstone` varchar(150) NOT NULL,
`favorite_food` varchar(150) NOT NULL,
`least_favorite_food` varchar(150) NOT NULL,
`favorite_school_subject` varchar(150) NOT NULL,
`least_favorite_school_subject` varchar(150) NOT NULL,
`strengths` varchar(150) NOT NULL,
`weaknesses` varchar(150) NOT NULL,
`goal` longtext NOT NULL,
`mission` longtext NOT NULL,
`biography` longtext NOT NULL,
`height_feet` int(2) NOT NULL,
`height_inches` int(2) NOT NULL,
`available` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
-
Nevermind, I added single quotes around the $_GET[id] and now it updates. But can you tell me how I'd update the active field when the user logs out? Or when they close the browser? Or both?
-
I don't understand what you mean?
-
zanus,
I have added this to my chosen.phppage:
<?php $get_scout = "select * from scouts where id = $_GET[id]"; $get_scout_res = mysql_query($get_scout, $conn) or die(mysql_error()); while ($scout_info = mysql_fetch_array($get_scout_res)) { $scout_id = $scout_info['id']; $identity = ucwords($scout_info['identity']); $make_active = mysql_query("UPDATE scouts SET active='1' WHERE id = '$scout_id'"); } ?>
And this to my button:
<a href=chosen.php?id=$q><input type=button value=Choose></a>
But it's not updating. What am I doing wrong?
-
Also, thanks for the help, zanus :-)
-
I think I understand the active idea. The reason I have four different tables is because a few of the fields are different in each table. I chose to do it this way because on some pages, it displays something like: You don't have any Knights created. etc... Thanks for the active idea. How would I set a script disable the active character when the user logs off?
-
I don't understand how you mean to use it. But look at my script. How would I store the session with the username the person chooses from the table?
<?php $verify_category = "select id, identity, username from scouts where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo "<i>You have no Scouts created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Scouts:</b><br> <select name=users onchange=showUser(this.value)> <option>select character</option>"; while ($list_scouts = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_scouts['identity']); $scout_id = $list_scouts['id']; echo "<option value=$scout_id>$identity</option>"; } } echo "</select>";
-
LOL Yes, I know the difference.
-
Nevermind, that's not what I meant. I already have a table with the characters it in. There is no need to make another one. What I need to do is store the chosen character I guess in a session, like a login username. Would I use a login type script, or can I just store the value in a session? What would work best is what I would like to know?
-
What I want to do is let them choose the character they want to use. There is a choose button. They choose the character and they use it later on the site. I want to know how I would store this for use on the site?
-
I did show the file, at the end. The choose_character.php file, that uses JavaScript and PHP to display the character's stats so they can see which character they want to choose.
-
I have the following file that allows the user to choose a character to play or train from a list of characters that they have registered with their username. I would like to create a way to store the character they have chosen to display once they have chosen one. How can I do this? I guess I need it to be similar to a log in script, where it checks if the character is logged in and displays the character name on the page after they choose one. How would I do this? Here is the page they choose the character on:
choose_character.php
<?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } ?> <html> <head> <title>Choose Character</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> <script type="text/javascript" src="selectuser.js"></script> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Choose Character <h3>Which character would you like to play?</h3> <form> <?php include("connect_db.php"); ?> <?php $verify_category = "select id, identity, username from scouts where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo "<i>You have no Scouts created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Scouts:</b><br> <select name=users onchange=showUser(this.value)> <option>select character</option>"; while ($list_scouts = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_scouts['identity']); $scout_id = $list_scouts['id']; echo "<option value=$scout_id>$identity</option>"; } } echo "</select>"; echo "<br><br>"; //verify Knights exist in category and list if applicable $verify_category = "select id, identity, username from knights where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo " "; } else { echo "<b>Knights:</b><br> <select name=users onchange=showUser(this.value)> <option>select character</option>"; while ($list_knights = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_knights['identity']); $scout_id = $list_knights['id']; echo "<option value=$scout_id>$identity</option>"; } } echo "</select>"; echo "<br>"; //verify Female Dark Warriors exist in category and list if applicable $verify_category = "select id, identity, username from fdark_warrior where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo " "; } else { echo "<b>Female Dark Warriors:</b><br> <select name=users onchange=showUser(this.value)> <option>select character</option>"; while ($list_fdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_fdark_warriors['identity']); $scout_id = $list_fdark_warriors['id']; echo "<option value=$scout_id>$identity</option>"; } } echo "</select>"; echo "<br>"; //verify Male Dark Warriors exist in category and list if applicable $verify_category = "select id, identity, username from mdark_warrior where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo " "; } else { echo "<b>Male Dark Warriors:</b><br> <select name=users onchange=showUser(this.value)> <option>select character</option>"; while ($list_mdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_mdark_warriors['identity']); $scout_id = $list_mdark_warriors['id']; echo "<option value=$scout_id>$identity</option>"; } } echo "</select>"; ?> </form> <br /> <div id="txtHint" class="choose_character"> </div> </div> <?php include("bottomnav.php"); ?> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"><!-- <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> --></div> </div> </div> <!-- /FOOTER --> </body> </html> </body> </html>
selectuser.js:
var xmlhttp; function showUser(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="getuser.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; }
getuser.php:
<?php $q=$_GET["q"]; $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("smrpg", $con); $get_identity = "select * from scouts where id = '".$q."'"; $get_identity_res = mysql_query($get_identity); while ($scout_identity = mysql_fetch_array($get_identity_res)) { $identity = $scout_identity['identity']; echo "<h2>$identity</h2>"; } $sql="SELECT * FROM stats WHERE id = '".$q."'"; $result = mysql_query($sql); echo "<table border='0' width=34%>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><b>Body:</b></td> <td>" . $row['body'] . "</td></tr>"; echo "<tr><td><b>Mind:</b></td> <td>" . $row['mind'] . "</td></tr>"; echo "<tr><td><b>Soul:</b></td> <td>" . $row['soul'] . "</td>"; echo "</tr> <tr><td> </td> <td> </td></tr>"; } //derived values $sql="SELECT * FROM derived_values WHERE id = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><b>Health Points:</b></td> <td>" . $row['health'] . "</td></tr>"; echo "<tr><td><b>Energy Points:</b></td> <td>" . $row['energy'] . "</td></tr>"; echo "<tr><td><b>Attack Combat Value:</b></td> <td>" . $row['acv1'] . "</td></tr>"; echo "<tr><td><b>Defense Combat Value:</b></td> <td>" . $row['dcv1'] . "</td>"; echo "</tr>"; } echo "</table><br> <p class=choose> <input type=button value=Choose> </p>"; mysql_close($con); ?>
-
I need to add a Page_Load event handler that sets the contents of the Name text box to "name" if you are not posting back to the page. I have this:
[
protected void Page_Load(object sender, EventArgs e) { name.Text = "Name"; }
But it is still showing when posting back to the page after validation. Can anyone help?
-
I would like to create a set of values that would represent levels such as to get to:
Level 2 - You must have 500 Experience Points
Level 3 - You must have 1500 Experience Points
etc...
Can someone help me get started on how I could accomplish this? Would I use an array? I want to use this to figure out how much experience the character needs to get to the next level and then to update the level when they reach enough experience. How would I get started? Here is what I have so far:
<?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); if ($energy < 2) { $display_block .= "You do not have enough energy. Rest or train in something else."; } if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; }//end while }//end if elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } } else { $display_block .= "Your character did not train."; } $display_block .= "</table>"; ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html>
-
I'm trying to make an error message print if the user tries to submit a select option of "test1" and their $energy is less than "2", but it's not working right for some reason. It is printing the message, but for some reason the while statement is subtracting 4 instead of 2 points each time the query is run:
$get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); if ($energy < 2) { $display_block .= "You do not have enough energy. Rest or train in something else."; } if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); }
Can anyone tell me what I'm doing wrong? I want the code to not run the query if the $energy is 0 and also not run the query if the $energy is less than 2 (this is only for option "test1"; "test2" will be different). What am I doing wrong? Here is the entire page:
<?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); if ($energy < 2) { $display_block .= "You do not have enough energy. Rest or train in something else."; } if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; }//end while }//end if elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } } else { $display_block .= "Your character did not train."; } $display_block .= "</table>"; ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html>
-
I guess I figured it out. I moved the closing table tag to the very end of the php code and it's fine. Thanks guys!
-
This is train.php:
<?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; }//end while }//end if elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } $display_block .= "</table>"; } else { $display_block .= "Your character did not train."; } ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html>
Here is what's supposed to look like:
And what is does look like:
-
Can anyone tell why my $display_block variable is not showing up properly when I choose the test1 choice from the select list and press submit? It displays correctly (which is above the footer) when I choose the test2 choice from the select list or when the page is initially loaded. What have I done wrong? Can anyone see? Here is my page:
<?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; }//end while }//end if elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } $display_block .= "</table>"; } else { $display_block .= "Your character did not train."; } ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html>
-
Thank you! That did the trick!
-
Well, I guess I want the query not to run if the condition is met. How can I do that?
-
How can I set an error to display if my $energy variable is less than or equal to 0 so that the user cannot submit the form? Here is what I have. I have it display a message if the $energy is less than or equal to 0, but I don't know how to set it to where they cannot submit it this condition is met:
if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } else { $display_block .= "You have enough energy to train."; }
Here's the whole page:
<?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; }//end while }//end if elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } $display_block .= "</table>"; if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } else { $display_block .= "You have enough energy to train."; } } else { $display_block .= "Your character did not train."; } ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html>
-
In the body.
<html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html>
I must have done something wrong in the display_block code in the php because the other one is in the right spot.
-
That works now, but now when I try to choose the test1 choice from the select menu, the display block for shows up below the footer on train.php. What did I do wrong now?
-
I have the following code, and the first if statement worked until I tried to add the second if statement. What did I do wrong on the second statement?
<?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } $display_block .= "</table>"; } else { print "Your character did not train."; } ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html>
Secondary Log In Possibly?
in PHP Coding Help
Posted
What do you mean, red? I have different tables because there are some different fields. I will probably still edit the tables, but currently they already have some different fields. I originally was going to have just one table and list a type and gender, but changed my mind and did it this way instead.