twilitegxa
-
Posts
1,020 -
Joined
-
Last visited
Posts posted by twilitegxa
-
-
That's the problem I'm having. I can't figure out how I need to set $identity on the train.php page to grab the identity from the previous pages. Can you help?
-
I am working on the where clause now. But for some reason, I am doing the last page wrong. I have a page where they choose which identity to train, then the page that displays the identity with appropriate info, then the third page should update the values, but I have a flaw in my where clause. Could I not use $_GET? Here are the pages I have:
choose_train.php:
<?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } include ("connect_db.php"); //show scouts characters $get_scouts = "select * from scouts where username = '".$_SESSION['userName']."'"; $get_scouts_res = mysql_query($get_scouts, $conn) or die(mysql_error()); while ($list_scouts = mysql_fetch_array($get_scouts_res)) { $identity = ucwords($list_scouts['identity']); $scout_id = $list_scouts['id']; echo "<ul class=\"character_list\"><li><a href=\"training_board.php?identity=$identity\">$identity</li></ul> "; } //show knights characters $get_knights = "select * from knights where username = '".$_SESSION['userName']."'"; $get_knights_res = mysql_query($get_knights, $conn) or die(mysql_error()); while ($list_knights = mysql_fetch_array($get_knights_res)) { $identity = ucwords($list_knights['identity']); $knight_id = $list_knights['id']; echo "<ul class=\"character_list\"><li><a href=\"showprofile_knights.php?id=$knight_id\">$identity</li></ul> "; } //show fdark_warriors characters $get_fdark_warriors = "select * from fdark_warrior where username = '".$_SESSION['userName']."'"; $get_fdark_warriors_res = mysql_query($get_fdark_warriors, $conn) or die(mysql_error()); while ($list_fdark_warriors = mysql_fetch_array($get_fdark_warriors_res)) { $identity = ucwords($list_fdark_warriors['identity']); $topic_id = $list_fdark_warriors['id']; echo "<ul class=\"character_list\"><li><a href=\"showprofile_fdark_warrior.php?id=$topic_id\">$identity</li></ul> "; } //show mdark_warriors characters $get_mdark_warriors = "select * from mdark_warrior where username = '".$_SESSION['userName']."'"; $get_mdark_warriors_res = mysql_query($get_mdark_warriors, $conn) or die(mysql_error()); while ($list_mdark_warriors = mysql_fetch_array($get_mdark_warriors_res)) { $identity = ucwords($list_mdark_warriors['identity']); $topic_id = $list_mdark_warriors['id']; echo "<ul class=\"character_list\"><li><a href=\"showprofile_mdark_warrior.php?id=$topic_id\">$identity</li></ul> "; } $display_block = ""; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> </body> </html>
<?php include("connect_db.php"); $display_block = "<h3>Train Your Character To Level Up</h3> <table> <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']; $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> </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>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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>
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> <table> <tr>"; $get_player_info = "select * from training WHERE identity = '$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> </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 "didn't work :-("; } ?> <html> <head> <title></title> </head> <body> <?php print $display_block; ?> </body> </html>
-
Okay, that did the trick! I didn't realize I was using the wrong method. Thank you for letting me know!
-
Well, I choose test1 from the select list named train. Is this the right coding? Here's the code from the form:
<form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> </form>
Am I writing something wrong?
-
The script you sent didn't work either :-(
-
If I take out the if statement, the script is working, so the if statement seems to be the problem. What am I doing wrong?
-
I don't understand what you mean. i tried putting the update statement inside of the whole loop, but that didn't work either. How would the statement:
UPDATE training SET energy =energy+2 WHERE 1;
take two away from the energy field? And how would I change my code? I don't quite understand what you mean. Sorry. Can you help explain it better?
-
Thank you, that eliminated the error, but my update is not working. Can you tell me why?
-
Okay, well if I run it on a second page instead, how do I write the if statement? I tried this:
training_board.php:
<?php include("connect_db.php"); $get_player_info = "select * from training"; $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']; } $display_block = " <h3>Train Your Character To Level Up</h3> <table> <tr> <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> </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> </table>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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>
train.php:
<?php include("connect_db.php"); $get_player_info = "select * from training"; $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']; } if ($_POST['train'] == 'test1') { $get_player_info = "select * from training"; $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 = ($player_info['energy'] - 2); } $accept_scout_username = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); } ?>
But I am getting this error:
Notice: Undefined index: train in C:\wamp\www\train.php on line 18
What am I doing wrong?
-
Can this not be done with PHP?
-
Can anyone help me? I'm wanting to have a page where people could train their characters (this is the beginning of an RPG game). What I want to do is if they press the train button, a query is run for whatever option they have selected. Say they chose test1 as the option and pressed train. I want to update the table:
energy - 2
experience + 50
The first thing I need to know how to do is have this script run on the same page only when they press the train button (it's a submit button actually; does that matter? or does it need to be a regular button?). The second thing is how to write the script to where it runs the script I want when the button is pressed. Here is the page I have so far:
<?php include("connect_db.php"); $get_player_info = "select * from training"; $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']; } $display_block = " <h3>Train Your Character To Level Up</h3> <table> <tr> <td valign=top> <form> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> </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> </table>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <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 so much! That seems to work perfectly!
-
How can I add the total price for my shopping cart items? I am not sure how to write the statement. Can anyone help? Here is my shopping cart page:
showcart.php:
<?php session_start(); include("connect_db.php"); $PHPSESSID = session_id(); $display_block = "<h1>Your Shopping Cart</h1>"; //check for cart items based on user id $PHPSESSID = session_id(); $get_cart = "select st.id, si.item_title, si.item_price, st.sel_item_qty, st.sel_item_size, st.sel_item_color from store_shoppertrack as st left join store_items as si on si.id = st.sel_item_id where session_id = '$PHPSESSID'"; $get_cart_res = mysql_query($get_cart) or die(mysql_error()); if (mysql_num_rows($get_cart_res) < 1) { //print message $display_block .= "<p>You have no items in your cart. Please <a href=\"seestore.php\">continue to shop</a>!</p>"; } else { //get info and build cart display $display_block .= " <table cellpadding=3 cellspacing=2 border=1 width=98%> <tr> <th>Title</th> <th>Price</th> <th>Qty</th> <th>Total Price</th> <th>Action</th> </tr>"; while ($cart = mysql_fetch_array($get_cart_res)) { $id = $cart['id']; $item_title = stripslashes($cart['item_title']); $item_price = $cart['item_price']; $item_qty = $cart['sel_item_qty']; $item_color = $cart['sel_item_color']; $item_size = $cart['sel_item_size']; $total = 'total price'; $total_price = sprintf($item_price * $item_qty); $display_block .= "<tr> <td align=center>$item_title <br></td> <td align=center>$item_price <br></td> <td align=center>$item_qty <br></td> <td align=center>$total_price S</td> <td align=center><a href=\"removefromcart.php?id=$id\">remove</a></td> </tr>"; } $display_block .= "<tr> <td colspan=4 align=right><b>Total:</b></td> <td>$total</td></table>"; } ?> <html> <head> <title>My Store</title> </head> <body> <?php print $display_block; ?> </body> </html>
-
Nevermind, I figured it out! Thanks anyway guys!
$PHPSESSID = session_id();
-
How can I get and store the user's session id? I was working with a tutorial from a book where it uses the user's session id to save the contents fo their shopping cart and then display that shoppign cart based on the session id, but it just states to use "$PHPSESSID" to save and use their session id, but that is not working. How do i set the $PHPSESSID to the user's session id? Here are the pages I'm using it in:
addtocart.php:
<?php session_start(); include ("connect_db.php"); if ($_POST[sel_item_id] != "") { //validate item and get tite and price $get_iteminfo = "select item_title from store_items where id = $_POST[sel_item_id]"; $get_iteminfo_res = mysql_query($get_iteminfo) or die(mysql_error()); if (mysql_num_rows($get_iteminfo_res) < 1) { //invalid id, send away header("Location: seestore.php"); exit; } else { //get info $item_title = mysql_result($get_iteminfo_res,0,'item_title'); //add info to cart $addtocart = "insert into store_shoppertrack values ('', '$PHPSESSID', '$_POST[sel_item_id]', '$_POST[sel_item_qty]', '$_POST[sel_item_size]', '$_POST[sel_item_color]', now())"; mysql_query($addtocart); //redirect to showcart page header("Location: showcart.php"); exit; } } else { //send somewhere else header("Location: seestore.php"); exit; } ?>
showcart.php:
<?php session_start(); //connect to database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); $display_block = "<h1>Your Shopping Cart</h1>"; //check for cart items based on user id $PHPSESSID = session_id(); $get_cart = "select st.id, si.item_title, si.item_price, st.sel_item_qty, st.sel_item_size, st.sel_item_color from store_shoppertrack as st left join store_items as si on si.id = st.sel_item_id where session_id = '$PHPSESSID'"; $get_cart_res = mysql_query($get_cart) or die(mysql_error()); if (mysql_num_rows($get_cart_res) < 1) { //print message $display_block .= "<p>You have no items in your cart. Please <a href=\"seestore.php\">continue to shop</a>!</p>"; } else { //get info and build cart display $display_block .= " <table cellpadding=3 cellspacing=2 border=1 width=98%> <tr> <th>Title</th> <th>Size</th> <th>Color</th> <th>Price</th> <th>Qty</th> <th>Total Price</th> <th>Action</th> </tr>"; while ($cart = mysql_fetch_array($get_cart_res)) { $id = $cart['id']; $item_title = stripslashes($cart['item_title']); $item_price = $cart['item_price']; $item_qty = $cart['item_qty']; $item_color = $cart['sel_item_color']; $item_size = $cart['sel_item_size']; $total_price = sprintf("%.02f", $item_price * $item_qty); $display_block .= "<tr> <td align=center>$item_title <br></td> <td align=center>$item_size <br></td> <td align=center>$item_color <br></td> <td align=center>$item_price <br></td> <td align=center>$item_qty <br></td> <td align=center>\$ $total_price</td> <td align=center><a href=\"removefromcart.php?id=$id\">remove</a></td> </tr>"; } $display_block .= "</table>"; } ?> <html> <head> <title>My Store</title> </head> <body> <?php print $display_block; ?> </body> </html>
Can anyone help?
-
How can I create a unique id for each div in the way the loop is being run? I will give each ul a unique id while await your response.
-
I have the following script and I would like to write a script that prints "Hit!" if the roll3 is less than or equal to $acv1 or "Miss!" if it is higher than the $acv1. How can I do this? Here is my page so far:
<?php include "connect_db.php"; $get_identity = "select id, identity from scouts where id = '$_GET[id]'"; $get_identity_res = mysql_query($get_identity, $conn) or die(mysql_error()); while ($get_scouts = mysql_fetch_array($get_identity_res)) { $id = $get_scouts['id']; $identity = $get_scouts['identity']; } //stats $get_stats = "select * from stats where identity = '$identity'"; $get_stats_res = mysql_query($get_stats, $conn) or die(mysql_error()); while ($stats_info = mysql_fetch_array($get_stats_res)) { $body = $stats_info['body']; $mind = $stats_info['mind']; $soul = $stats_info['soul']; } //gather derived values $get_derived = "select * from derived_values where identity = '$identity'"; $get_derived_res = mysql_query($get_derived, $conn) or die(mysql_error()); while ($derived_info = mysql_fetch_array($get_derived_res)) { $health = $derived_info['health']; $energy = $derived_info['energy']; $acv1 = $derived_info['acv1']; $acv2 = $derived_info['acv2'] . ' (for Sailor Scout Attack)'; $dcv1 = $derived_info['dcv1']; $dcv2 = $derived_info['dcv2'] . ' (for Sailor Scout Attack)'; } ?> <html> <head> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> var die = 6; // 6 sided dice var dice = 2; // number of dice to roll function dice_roll(die, dice) { var roll = 0; for (loop=0; loop < dice; loop++) { roll = roll + Math.round(Math.random() * die) % die + 1; } document.form.text.value = roll; } </script> <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"); ?> <center> <form name=form> <table border="1" cellpadding="3" cellspacing="3"> <tr> <td align=middle>Roll the dice to take your turn</td> <td><?php print $identity; ?></td> </tr> <tr> <td> <b>Total:</b> <input type=text size=1 name=text class="dice_total"> <input type=button value="Roll" name=button onclick="dice_roll(die, dice)"></td> <td>Body: <?php print $body;?><br> Mind: <?php print $mind; ?><br> Soul: <?php print $soul; ?><br> Health: <?php print $health; ?><br> Energy: <?php print $energy; ?><br> ACV: <?php print $acv1; ?> [<?php print $acv2; ?>]<br> DCV: <?php print $dcv1; ?> [<?php print $dcv2; ?>]<br></td> <td valign="top"> <script type="text/javascript"> min=2; max=7; var roll1=Math.floor(Math.random()*(max-min))+min; var roll2=Math.floor(Math.random()*(max-min))+min; var roll3 = roll1+roll2; var roll1 = roll1+<?php print $acv1 ?>; var roll2 = roll1+<?php print $acv1 ?>; //this will be enemy's acv </script> Initiative:<br> <?php print $identity ?> - <script>document.write(roll1)</script><br> Enemy - <script>document.write(roll2)</script><br><br> Attack: <script>document.write(roll3)</script> <script>document.write(hit)</script> </td> </tr> </table> </form> </center> </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>
-
How can I alter my chat script to show the selected character's name in the message window instead of the username? I have the following pages:
chatframe.php:
<?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } ?> <html> <head> <title>Sailor Moon RPG - Battle Chat</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 - Battle Chat</h1> <?php print "<table width=80%><tr><td><iframe src='chatlog.php' name='chatlogframe' width='80%' height='400'></iframe></td></tr>"; print "<tr><td><iframe src='submit.php' width='80%' height='250' frameborder='0' class='message'></iframe></td></tr></table>"; ?> </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>
chatlog.php
<?php session_start(); ?> <html> <head> <title></title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <?php include "connect.php"; $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die(mysql_error()); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>10000000) { $startrow=$getmessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime DESC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); while($getmsg3=mysql_fetch_array($getmsg2)) { $message=' '; $message=Smiley($message); //Smiley faces $getmsg3['message'] = nl2br($getmsg3['message']); //includes line breaks in messages $getmsg3['message'] = wordwrap($getmsg3['message'],170,'<br />',true); print "<font color='teal'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } function Smiley($texttoreplace) { $smilies=array( '' => "<img src='images/smile.gif'>", ':blush' =>"<img src='images/blush.gif'>", ':angry' =>"<img src='images/angry.gif'>", ''=> "<img src='images/shocked.gif'>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); return $texttoreplace; } ?> <script> setTimeout("window.location.replace('chatlog.php')",1000); </script> </body> </html>
submit.php:
<?php session_start(); ?> <html> <head> <title></title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <?php include "connect.php"; if(isset($_POST['submit'])) //if submit button push has been detected { $message= nl2br($_POST['message']); $name=$_SESSION['userName']; if(strlen($message)<1) { print "You did not input a message"; } else if(strlen($name)<1) { print "You are not logged in. Please log in."; } else { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "Your IP is banned from posting. Please contact administration."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$name','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } print "<form action='submit.php' method='post' name='form'>"; //print "<strong>Your name:</strong><br>"; not needed //print "<input type='text' name='name' size='20'><br>"; not needed print "<strong>Your message:</strong><br>"; print "<textarea name='message' cols='40' rows='4'></textarea><br>"; print "<a onClick=\"addSmiley('')\"><img src='images/smile.gif'></a> "; //replace images/smile.gif with the relative path of your smiley print "<a onClick=\"addSmiley('')\"><img src='images/sad.gif'></a> "; print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> "; print "<input type='submit' name='submit' value='submit'></form>"; print "<script language=\"Java Script\" type=\"text/javascript\">\n"; print "function addSmiley(textToAdd)\n"; print "{\n"; print "document.form.message.value += textToAdd;"; print "document.form.message.focus();\n"; print "}\n"; print "</script>\n"; print "<br><br>"; ?> </body> </html>
I know I need to use this statement to get the identity of the character to display it, bu I don't know how to replace the username in the chat window with the character's identity:
include "connect_db.php"; $get_identity = "select id, identity from scouts where id = '$_GET[id]'"; $get_identity_res = mysql_query($get_identity, $conn) or die(mysql_error()); while ($get_scouts = mysql_fetch_array($get_identity_res)) { $id = $get_scouts['id']; $identity = $get_scouts['identity']; }
How can I do this? What page do I need to put the code on in order for it to display properly? I have this page where they choose their character and it points the user to the chatframe.php with the selected character id:
choose_character.php:
<?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } ?> <?php include("connect_db.php"); ?> <html> <head> <title>Choose Character</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"); ?> <h3>Which character would you like to play?</h3> <?php echo "<table><tr><td valign=top>"; //verify Scouts exist in category and list if applicable $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>"; while ($list_scouts = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_scouts['identity']); $scout_id = $list_scouts['id']; echo "<ul class=choose> <li><a href=chatframe.php?id=$scout_id>$identity</a></li> </ul>"; } } echo "<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 "<i>You have no Knights created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Knights:</b>"; while ($list_knights = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_knights['identity']); $scout_id = $list_knights['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } 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 "<i>You have no Female Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Female Dark Warriors:</b>"; while ($list_fdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_fdark_warriors['identity']); $scout_id = $list_fdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } 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 "<i>You have no Male Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Male Dark Warriors:</b>"; while ($list_mdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_mdark_warriors['identity']); $scout_id = $list_mdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "</td>"; $get_stats = "select * from stats where identity = '$identity'"; $get_stats_res = mysql_query($get_stats, $conn) or die(mysql_error()); while ($stats_info = mysql_fetch_array($get_stats_res)) { $body = $stats_info['body']; $mind = $stats_info['mind']; $soul = $stats_info['soul']; echo "<td valign=top> <div id=chosen> <h1>$identity</h1> Body: $body<br> Mind: $mind<br> Soul: $soul<br><br>"; //gather derived values $get_derived = "select * from derived_values where identity = '$identity'"; $get_derived_res = mysql_query($get_derived, $conn) or die(mysql_error()); while ($derived_info = mysql_fetch_array($get_derived_res)) { $health = $derived_info['health']; $energy = $derived_info['energy']; $acv1 = $derived_info['acv1']; $acv2 = $derived_info['acv2'] . ' (for Sailor Scout Attack)'; $dcv1 = $derived_info['dcv1']; $dcv2 = $derived_info['dcv2'] . ' (for Sailor Scout Attack)'; $total_cp = $derived_info['total_cp']; if($health == 0 || $health == '0' || $health == null){$GLOBALS['health'] = "";} if($energy == 0 || $energy== '0' || $energy == null){$GLOBALS['energy'] = "";} if($acv1 == 0 || $acv1 == '0' || $acv1 == null){$GLOBALS['acv1'] = "";} if($acv2 == 0 || $acv2 == '0' || $acv2 == null){$GLOBALS['acv2'] = "";} if($dcv1 == 0 || $dcv1 == '0' || $dcv1 == null){$GLOBALS['dcv1'] = "";} if($dcv2 == 0 || $dcv2 == '0' || $dcv2 == null){$GLOBALS['dcv2'] = "";} if($total_cp == 0 || $total_cp == '0' || $total_cp== null){$GLOBALS['total_cp'] = "";} echo " Health Points: $health<br> Energy Points: $energy<br> Attack Combat Value: $acv1 $acv2<br> Defense Combat Value: $dcv1 $dcv2<br>"; } } echo "<br> <input type=button value=Choose></div></td></tr></table>"; ?> </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>
I need to have the page that submits the message to insert the character identity instead of the userName.
-
The hidden part works, but when I click the links, the div doesn't display. Also, how would I get the chosen character's information to display in the div? I don't know how to do that part either :-(
-
I am posting this in the JavaScript section. I think it is more a JavaScript question. Sorry for posting in the wrong place!
-
I have the following page, and I want to make it to where, if the user clicks a character from the list, that it will display their stats in the div tag on the right. I want the div tag to be hidden until a user clicks one of the characters, and then when they click it, it then displays the stats. Right now, I don't have it initially hidden. How can I make it hidden until they click the character? How can I make a link that will display the stats when the user clicks the character? I need to base the results on which identity the user chooses. Here is my page so far:
<?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } ?> <?php include("connect_db.php"); ?> <html> <head> <title>Choose Character</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"); ?> <h3>Which character would you like to play?</h3> <?php echo "<table><tr><td valign=top>"; //verify Scouts exist in category and list if applicable $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>"; while ($list_scouts = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_scouts['identity']); $scout_id = $list_scouts['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "<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 "<i>You have no Knights created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Knights:</b>"; while ($list_knights = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_knights['identity']); $scout_id = $list_knights['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } 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 "<i>You have no Female Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Female Dark Warriors:</b>"; while ($list_fdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_fdark_warriors['identity']); $scout_id = $list_fdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } 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 "<i>You have no Male Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Male Dark Warriors:</b>"; while ($list_mdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_mdark_warriors['identity']); $scout_id = $list_mdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "<br></td>"; $get_stats = "select * from stats where identity = '$identity'"; $get_stats_res = mysql_query($get_stats, $conn) or die(mysql_error()); while ($stats_info = mysql_fetch_array($get_stats_res)) { $body = $stats_info['body']; $mind = $stats_info['mind']; $soul = $stats_info['soul']; echo "<td valign=top> <div id=chosen> Body: $body<br> Mind: $mind<br> Soul: $soul<br><br>"; //insert derived values statement echo " Health Points:<br> Energy Points:<br> Attack Combat Value:<br> Defense Combat Value:<br>"; } echo "</div><br> <input type=button value=Choose></td></tr></table>"; ?> </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>
Is this a JavaScript thing? Or would I need to use JQuery? Can someone help?
-
I have the following page, and I want to make it to where, if the user clicks a character from the list, that it will display their stats in the div tag on the right. I want the div tag to be hidden until a user clicks one of the characters, and then when they click it, it then displays the stats. Right now, I don't have it initially hidden. How can I make it hidden until they click the character? How can I make a link that will display the stats when the user clicks the character? I need to base the results on which identity the user chooses. Here is my page so far:
<?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } ?> <?php include("connect_db.php"); ?> <html> <head> <title>Choose Character</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"); ?> <h3>Which character would you like to play?</h3> <?php echo "<table><tr><td valign=top>"; //verify Scouts exist in category and list if applicable $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>"; while ($list_scouts = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_scouts['identity']); $scout_id = $list_scouts['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "<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 "<i>You have no Knights created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Knights:</b>"; while ($list_knights = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_knights['identity']); $scout_id = $list_knights['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } 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 "<i>You have no Female Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Female Dark Warriors:</b>"; while ($list_fdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_fdark_warriors['identity']); $scout_id = $list_fdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } 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 "<i>You have no Male Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Male Dark Warriors:</b>"; while ($list_mdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_mdark_warriors['identity']); $scout_id = $list_mdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "<br></td>"; $get_stats = "select * from stats where identity = '$identity'"; $get_stats_res = mysql_query($get_stats, $conn) or die(mysql_error()); while ($stats_info = mysql_fetch_array($get_stats_res)) { $body = $stats_info['body']; $mind = $stats_info['mind']; $soul = $stats_info['soul']; echo "<td valign=top> <div id=chosen> Body: $body<br> Mind: $mind<br> Soul: $soul<br><br>"; //insert derived values statement echo " Health Points:<br> Energy Points:<br> Attack Combat Value:<br> Defense Combat Value:<br> </div></td></tr></table>"; } ?> </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>
-
That didn't really change anything. Still getting:
Unknown column '$scout_id' in 'where clause'
-
No, the query on the page that I want to refresh on should contain the id:
//verify the scout exists $verify_scout = "select identity from scouts where id = $_GET[id]"; $verify_scout_res = mysql_query($verify_scout, $conn) or die(mysql_error()); if (mysql_num_rows($verify_scout_res) < 1) { //this character does not exist $display_block = "<p><em>You have selected an invalid character. Please <a href=\"existing.php\">try again</a></em></p>"; } else { //gather rest of profile fields $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']); $accept_scout_username = mysql_query("UPDATE scouts SET username='$_SESSION[userName]' WHERE id = '$scout_id'"); $accept_scout_available = mysql_query("UPDATE scouts SET available='0' WHERE id = '$scout_id'"); } }
See, $scout_id contains the id of the character. I tried:
<META http-equiv="refresh" content="5;URL=showprofile_scouts.php?id=$scout_id">
In my head tag, but it is saying:
Unknown column '$scout_id' in 'where clause'
Shouldn't this be working? It's on the same page.
<?php session_start(); //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("smrpg", $conn) or die(mysql_error()); //verify the scout exists $verify_scout = "select identity from scouts where id = $_GET[id]"; $verify_scout_res = mysql_query($verify_scout, $conn) or die(mysql_error()); if (mysql_num_rows($verify_scout_res) < 1) { //this character does not exist $display_block = "<p><em>You have selected an invalid character. Please <a href=\"existing.php\">try again</a></em></p>"; } else { //gather rest of profile fields $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']); $accept_scout_username = mysql_query("UPDATE scouts SET username='$_SESSION[userName]' WHERE id = '$scout_id'"); $accept_scout_available = mysql_query("UPDATE scouts SET available='0' WHERE id = '$scout_id'"); } } ?> <html> <head> <title>You Have Accepted Character: <?php print $identity; ?></title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> <META http-equiv="refresh" content="5;URL=showprofile_scouts.php?id=$scout_id"> </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 align="center"><?php print $identity; ?>: Accepted</h1> <h3>You have accepted the existing character, <strong><?php print $identity; ?></strong>.</h3> </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>
[SOLVED] Update Run On Same Page When Form Submited?
in PHP Coding Help
Posted
Thank you so much! That did it! Thanks for pointing out the hidden idea! I wasn't thinking! :-)