PHP - My Monster And Players Hitpoints Keep Resetting,
Hi, I have a battle script that has a monster and player fighting. The hit points keep resetting on both characters. I set my session variables in intro.php, and included a session_start(); on the pages leading up to my main battle page. I set the array names of both $monster stats and $player stats to $_SESSION variables and initialized them on a separate page before the main page. My monster and players hitpoints keep resetting so no one dies. Any help GREATLY appreciated. Thanks. Derek
here is the intro page where I initialize the stat session variables. Code: [Select] <?php //include("connect1.php"); session_start(); // include('bouncer_final.php'); //include("bouncer.php"); // kicks the person off if session is not set, its the bouncer, big and fat man. $_SESSION['charname']=''; $_SESSION['player']['stats']['playerHP'] = 100; $_SESSION['player']['stats']['playerMana'] = 100; $_SESSION['player']['stats']['playerDmgLow'] = 1; $_SESSION['player']['stats']['playerDmgHigh'] = 10; $_SESSION['player']['stats']['playerHitRollLow'] = 1; $_SESSION['player']['stats']['playerHitRollHigh'] = 20; $_SESSION['player']['stats']['playerDefense'] = 5; $_SESSION['player']['stats']['Teardrop_Ocean_Protectors'] = 3; $_SESSION['monsters']['Ocean']['octalisk']['exp']=10; $_SESSION['monsters']['Ocean']['octalisk']['mana']=100; $_SESSION['monsters']['Ocean']['octalisk']['hp']=100; /* End */ ?> here is the main battle page where all my battle coding goes on, and I declare the session variables equal to my array names near the top . Code: [Select] <?php session_start(); // include("connect1.php"); //include('bouncer_final.php'); // include('frames/encounters.php'); require_once("shoutbox/dbconnect.php"); // include("bouncer.php"); // kicks the person off if session is not set, its the bouncer, big and fat man. //turned these off while we are developing // ini_set('display_errors',1); //error_reporting(E_ALL|E_STRICT); //or if you only want to see Warning Messages and not Notice Messages: //ini_set('display_errors',1); error_reporting(E_ALL); //and if you just want all Error Reporting off, simply use this: //error_reporting(0); // error_reporting (E_ALL ^ E_NOTICE); //declare vars //$oceanBackground='';//we dont need this because it's bad practice and its already set in the program. $player=''; $monsters=''; $_SESSION['player'] = $player;// set this right after they log in, run this once, eventually in database. $_SESSION['monsters']=$monsters; $currentMonsterLevel='';//get rid of this eventually and put in session variable cuz we use it on other pages. $currentPlayerLevel=''; $error=''; $playerHp='';//get rid and make session var. $monsterHp=''; $echoPlayerMana=''; $echoMonster=''; $echoSpell=''; $player=''; $monsters=''; $playerMessage=''; $monsterMessage=''; $currentPLayerLevel =''; function encounter($monsterSeeInvis,$monsterAggro, $playerFaction) { if($monsterSeeInvis==true && $monsterAggro==true || $playerFaction<5) { return true;//return yes, for attack function } else { return false; } } function monsterAttack($currentMonster,$hitRollLow,$hitRollHigh,$dmgLow,$dmgHigh,$playerDefense, &$playerHp) { $monsterRoll= rand($hitRollLow, $hitRollHigh); if($monsterRoll>=$playerDefense) { $monsterDamage= rand($dmgLow,$dmgHigh); $monsterMessage = "You have been hit by a ". $currentMonster." for "."<strong>". $monsterDamage."</strong> points of damage!"; $playerHp= $playerHp- $monsterDamage; $monsterMessage.=" your hp is now ".$playerHp; } else { $monsterMessage= " the ".$currentMonster." missed you!<br />"; } return $monsterMessage; } function playerAttack($currMonster,$playerHitRollLow,$playerHitRollHigh,$playerDmgLow,$playerDmgHigh,$monsterDefense, &$monsterHp,$playerFaction,$playerMana) { $playerRoll= rand($playerHitRollLow, $playerHitRollHigh); if($playerRoll>=$monsterDefense) { $playerDamage= rand($playerDmgLow,$playerDmgHigh); $playerMessage = "You have hit a ". $currMonster." for "."<strong>". $playerDamage."</strong> points of damage!"; $monsterHp= $monsterHp- $playerDamage; $playerMessage.=" The ".$currMonster."'s hp is now ".$monsterHp; if($monsterHp<=0) { if($playerFaction<=0) { $playerMessage="Your faction standing with ".$playerFaction. "could not possibly get any worse."; } $playerMessage.=" You have killed the ".$currMonster. "Your faction standing with ".$playerFaction." is now ".$playerFaction-1; } } else { $playerMessage; //WTF i dont know what im doing. $playerMessage= " Whoa! You missed the ".$currMonster; } return $playerMessage; } //ini_set('display_errors',1); //error_reporting(E_ALL); $spells = array ( "red" => "red", "green"=>"green", "blue" =>"blue" ); ////////////////////////////////////////////////////////////// $player = array ( 'inventory'=>'', 'spells'=>'', 'stats'=> array ( 'int'=>16, 'playerHp'=>100, 'playerMana'=>100, 'playerDmgLow'=>1, 'playerDmgHigh'=>10, 'playerHitRollLow'=>1, 'playerHitRollHigh'=>20, 'playerDefense'=>5, 'Teardrop_Ocean_Protectors'=>3 ), 'armor'=> array ( 'shield'=>'gold' ), 'weapons' =>array ( 'sword'=>'silver' ) , 'faction'=> array ( 'Teardrop_Ocean_Protectors'=>3 //zero means the worst faction you can have, 10 being best , 5 being indifferent. ) ); /////////////////////////////////////////////////////////////// $monsters = array ( 'Ocean'=>array ( 'octalisk'=>array ( 'name'=>'octalisk', 'hp'=>100, 'exp'=>10, 'mana'=>100, 'dmgLow'=>1, 'dmgHigh'=>10, 'seeInvis'=>true, 'aggro'=>true, 'defense'=>5, 'faction'=>'Teardrop_Ocean_Protectors', 'hitRollLow'=>1, 'hitRollHigh'=>20), 'shark' , 'eel' ), 'Desert'=>array ( 'sand_snake' ), 'Forest'=>array ( 'frog', 'lizard', 'spider' ) ); //*/IF ATTACK BUTTON PRESSED, INCLUDE ENCOUNTERS FILE WHICH HAS THE BATTLE FUNCTION AND RUN IT /*if(!empty($_POST['attack'])) { include('frames/encounters.php'); battle(); }*/ $currentMonster='octalisk'; ///////////////////////////////////////////////////////////battle//////////////////////////// //function monsterEncounter($echoMonster,$monsterImage) if(!empty($_POST['attack'])) { $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; // instead of using globals we make the return of playerAttack == to $playerMessage to be used outside function. $playerMessage = playerAttack($currentMonster,$player['stats']['playerHitRollLow'],$player['stats']['playerHitRollHigh'], $player['stats']['playerDmgLow'],$player['stats']['playerDmgHigh'],$monsters['Ocean']['octalisk']['defense'],$monsters['Ocean']['octalisk']['hp'],$player['faction']['Teardrop_Ocean_Protectors'],$player['stats']['playerMana']); //insert octalisk stats into monsterattack function. if(encounter($monsters['Ocean']['octalisk']['seeInvis'],$monsters['Ocean']['octalisk']['aggro'],$player['faction']['Teardrop_Ocean_Protectors'])) { //BELOWE CODE instead of using globals, we set the output of monsterAttack //to $monsterMessage becasue it can be used outside the function. $monsterMessage = monsterAttack($currentMonster,$monsters['Ocean']['octalisk']['hitRollLow'],$monsters['Ocean']['octalisk']['hitRollHigh'] , $monsters['Ocean']['octalisk']['dmgLow'],$monsters['Ocean']['octalisk']['dmgHigh'], $player['stats']['playerDefense'],$player['stats']['playerHp'],$monsters['Ocean']['octalisk']['hp']); } else { echo "do nothing"; } } ////////////////////////////////////////////////////////////////////////////// //CHANGING BACKGROUND FOR OCEAN GOES HERE, 1 IMAGE FOR EACH LEVEL OF DEEPNESS WHEN further // BUTTON PRESSED if(empty($_POST['further'])) { $oceanBackground=' <img src="sundragon_environments/ocean/ocean1_FRAME.jpg"/>'; } elseif(!empty($_POST['further'])) { $oceanBackground=' <img src="sundragon_environments/ocean/ocean1_FRAME2.jpg"/>'; $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; $monsterMessage='You see an Octalisk, it looks very scary'; } else { $oceanBackground='SHIT where the hell am I?'; $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; $monsterMessage='You see an Octalisk, it looks very scary'; } ////////////////////////////////////////////////////////////////////////////////// if(!empty($_POST['search'])) { //include('frames/search.php'); //I CANT GET THIS BELOW TO RUN IN A FUNCTION INSIDE THE SEARCH.PHP FILE, WTF IS UP WITH THAT //and it returns random ALL monsters instead of ocean monsters. $random = 'Ocean'; $monster = array_rand($monsters[$random]); if(is_array($monsters[$random][$monster])) { $currentMonster = $monsters[$random][$monster]['name']; } else { $currentMonster = $monsters[$random][$monster]; } //instead of echoing out $currentMonster , we set it so we can get random monster images with it output. $monsterImage=$currentMonster; //make the below into a function, note what changes , those will be your parameters. //i dont know how to do it. i tried. //function monsterEncounter($echoMonster,$monsterImage) if($monsterImage=='octalisk') { $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; $monsterMessage='You see an Octalisk, it looks very scary'; } elseif($monsterImage=='eel') { $echoMonster="<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png'/>"; $monsterMessage='You see an electric Eel , look out.'; } elseif($monsterImage=='shark') { $echoMonster="<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>"; $monsterMessage='You see a Hammerhead Shark, it looks powerful.'; } else $echoMonster="no monster here"; }//end elseif ////////////////////////////////////////////////////////////////////////// if(!empty($_POST['spell'])) { $spellColor = array_rand($spells); if(is_array($spells)) { $currentSpell= $spellColor; } else { return 0; } //instead of echoing out $currentMonster , we set it so we can get random monster images with it output. if($currentSpell=='red') { $echoSpell=" <img src='sundragon_interface_template/spells/red.gif' align='center'/> "; $monsterMessage=' You cast <strong> BLOOD OF BEATHULE </strong>'; $player['stats']['playerMana']-=5; $echoPlayerMana=$player['stats']['playerMana']; } elseif ($currentSpell=='green') { $echoSpell=" <img src='sundragon_interface_template/spells/green.gif' align='center'/> "; $monsterMessage='You cast <strong> POISONOUS PLAGUE </strong> spell'; $player['stats']['playerMana']-=5; $echoPlayerMana=$player['stats']['playerMana']; } elseif($currentSpell=='blue') { $echoSpell=" <img src='sundragon_interface_template/spells/blue.gif' align='center'/> "; $monsterMessage='You cast <strong> HEART OF DARKNESS </strong>'; $player['stats']['playerMana']-=5; $echoPlayerMana=$player['stats']['playerMana']; } else { echo "nothing"; } } ?> <!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>Realm of the Sun Dragon</title> <link rel="stylesheet" type="text/css" href="css/gamestyles.css"> <style type="text/css"> body { margin-top:-32px; padding:0; color: gold; } table { color: black; } .style8 {color: #000000} </style> </head> <body> <div id="container"> <div id="monster_message"><?php if(!empty($battleResult)){echo $battleResult;} // if isset battleresult, then echo ?><?php echo $error;?><?php echo "<br />". $playerMessage. "<br />". $monsterMessage."<br />";?></div> <div id="currentWeapon"> <img src="sundragon_interface_template/items/swords/sword_shrunk.png" width="190" height="65" /> </div> <div id="iframe_player_top_lft" > <div id="left_player_stats"><table align="center" width="30" border="0"> <tr> <td><strong>HP</strong></td> <td><strong><font color="red"><?php echo $playerHp;?></font></strong></td> </tr> <tr> <td><strong>MANA</strong></td> <td><strong><font color="green"><?php echo $echoPlayerMana;?></font></td> </tr> <tr> <td><strong>EXP</strong></td> <td><strong><font color="blue">999</font></strong></td> </tr> <tr> <td><strong>PLAT</strong></td> <td><strong><font color="white">999</font></strong></td> </tr> </table></div> <p> </p> <p> </p> <p> </p> <p align="center"><strong><br /> <span class="style8">Octalisk (Level <?php echo $currentMonsterLevel;?>) </span></strong> <br/> <strong><span class="style8">HP</span><font color="red"> <?php echo $monsterHp;?></font></strong> </p> <div id="spelleffectsleft" > <div class="divcenter"> <div align="center"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <!--end divcenter--> </div><!--end spell effects--> <div id="bottomspellsleft" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> <!--end div center--> </div><!--end bottomspells--> </div><!-- end player div--> <div id="iframe_spell_foreground"><?php echo $echoSpell;?></div> <div id="iframe_monster_background"> <?php echo $oceanBackground; ?></div> <div id="iframe_transparent_monster"><?php echo $echoMonster;?></div> <!--not here--> <div id="iframe_player_top_right" > <table width="160" height="64" border="0" align= "center"> <tr> <td width="160"><div align="center"> <p><strong><br /> Silverglade (Level: <?php echo $currentPLayerLevel;?>)<br /> </strong></p> </div></td> </tr> </table> <div class="spelleffects" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <div class="bottomspells" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> </div> <div id="iframe_chat_right"> the data from the chat message box will be output to this div</div> <!--not here--> <div id="iframe_player_center_bottom" align="center" > <div align="center"> <form action='gamestart.php' method='post'><input type='submit' name='attack' value='Attack'/><input type="submit" name="search" value="search" /><input type="submit" value="cast spell" name="spell" /><input type="submit" value="go further" name="further" /> <input type="submit"value="Go back" name="back"/><input type="submit" name="inventory" value="Inventory"/></form> <div id="chat"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <strong>Message:</strong> <textarea name="message"></textarea> <input type="submit" name="submit" value="Chat"> <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>"> </form> </div></div></div> <!--not here--> <div id="log_off"> <a href="logout.php"><strong>LOG OFF</strong></a> </div> <!--not here--> </div> </body> </html> Similar TutorialsI'm having trouble with some foreach statements. I'm pretty sure I've narrowed it down to one foreach statement. Not sure where to go from here. Code: [Select] // output column headers $rows=1; $cols=0; foreach ($colarr as $col){ //echo "<pre>"; print_r($col); echo "</pre>"; $text=str_replace("<br>", "\r\n", $col['desc']); $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $text); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows)->getAlignment()->setWrapText(true); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } $rows++; // output data rows if (isset($apptable['retarr']) && isset($apptable['retarr']['rs']) && count($apptable['retarr']['rs'])>0){ foreach ($apptable['retarr']['rs'] as $row=>$r){ if (is_numeric($row)){ //echo '<pre>'.print_r($apptable).'</pre>';//exit; $cols=0; foreach ($r as $col=>$c){ if (isset($colarr[$col])){ //echo '<pre>'.print_r($colarr[$col]).'</pre>';//exit; //echo "this is xlcols: ".$xlcols[$cols].$rows; echo " "; //echo "This is col: ".$col; echo " "; //echo "This is r[col]: ".$r[$col]; echo "<br>"; $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows, $r[$col])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } } $rows++; } } } The first section (output column headers) prints column names to an excel spreadsheet. The next part (output data rows) puts the data in an excel spreadsheet. The problem I have is that the data rows don't match the header columns. I think this is because the array $colarr is not after the first foreach loop. I've tried to reset, asort, and sort to move it back to the beginning, but none of those worked. And this $reset_array_keys = array_values($numerically_indexed_array); Any suggestions on what I should do? Output of print_r($colarr[$col]). Code: [Select] Array ( [dbcolumn] => tr_ngfg_statement_date [desc] => Ngfg Statement Date [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => y [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_transaction_reconciled_y_or_n [desc] => Reconciled [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_priority_level [desc] => Priority Level [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => y [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_id [desc] => ID [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_decisioned_date [desc] => Decisioned Date [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) That's really the only way i can categorize this particular question. I have a site loading a form into an iframe. probably not the smartest thing to do but I've built a one-page portfolio site that scrolls to each anchor point with the scrollTo script. None the less, my form loads into my frame. I started thinking about usability and how odd it might be to a non-techie, non-webby visitor to go to the form, submit and then maybe want to send another message. Although not very probable, it's the stuff we don't anticipate happening that usually gets us in deep. Really, what I'm looking for is something where after the visitor submits the form and it says "thank you for sending us an email" that it would either automatically reset my index page OR give the visitor the option of manually resetting the page. my form Code: [Select] <form method="POST" action="mailer.php"><br /> Name:<br /> <input type="text" name="name" size="50"><br> <br /> E-Mail:<br> <input type="text" name="email" size="50"><br> <br /> Comments:<br> <textarea wrap="soft" rows="5" name="message" cols="48"></textarea> <br> <br> <input type="submit" value="Submit" name="submit"> </form> php script Code: [Select] <?php if(isset($_POST['submit']) || isset( $_POST['submit_x'] )) { $to = "email@mydomain.com"; $subject = "Contact from a visitor"; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; echo "Your email has been sent to $to!"; mail($to, $subject, $body); } else { echo "blarg!!!"; } ?> Hi, I think this is probably a logical error rather than a syntax one I have a function that displays the first image in a photo album in large and all the photos in it as thumbnails. I have a next and previous button that allows you to scroll through them (in large) and by clicking a specific thumbnail you can load that picture in large. My problem is that the pictures are stored in an array and the one to be shown large is selected by $keyid. My problem is that selecting a thumbnail resets the $keyid so that clicking next doesn't load the next image but the second. i.e. if you press the next arrow then click the 4th thumbnail and then click the next arrow again it loads the 2nd picture rather than the 5th as it should. How can I avoid this happening? This is my code: generateThumbnails(); $act = 0; $keyid = (isset($_GET['keyid']) ? $_GET['keyid']:'0'); $Picturecount = (count(glob("" . $dir . "*.jpg")))/2; $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); $picture_array = glob("$dir*"); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $selected = str_replace('_th.jpg','.jpg',$thumbFile); foreach ($picture_array as $search){ $keyid = array_search($selected,$picture_array); $large = $picture_array[$keyid]; }} else{ if($keyid > (2*$Picturecount-1)){ $keyid = ($keyid - (2*$Picturecount));} if($keyid < 0){ $keyid = (2*$Picturecount+$keyid);} $large = $picture_array[$keyid];} echo " <tr><td><a href='?album=$album&keyid=" . ($_GET['keyid']-2) . "'>Previous</a></td><td></td><td align='right'><a href='?album=$album&keyid=" . ($_GET['keyid']+2) . "'>Next</a></td></tr> <tr><td colspan='3' height='300' width='400' align='center'><img src='$large' alt=''></td></tr><tr><td height='50'></td></tr>"; Any help would be massively appreciated. Thanks very much! Hello, I'm working on a dynamic text form (I guess thats what its called). Basically, I have a html page that echos in some PHP code. What the PHP code does is show different strings of text depending on a variable: Code: [Select] <PHP? $brief1_info = "brief info goes here"; $brief1 = 0; if (isset($_POST['brief1Go'])) { $brief1 = $brief1 + 1; } else if (isset($_POST['brief1Back'])) { $brief1 = $brief1 - 1; } $breif1Controller = " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Back\" id=\"brief1Back\" value=\"BACK\" /> </form> <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Go\" id=\"brief1Go\" value=\"CONTINUE\" /> </form>"; if($brief1 == 0){ $brief1_info = "<b>Welcome Commander,</b> you are currently viewing the Mission Control Brief page, here you can view all your missions that you need to complete in order to advance through your prestiges. You will need to follow your briefs carefully in order to succeed. <br /><br /> "; } else if($brief1 == 1){ $brief1_info = "Okay, let me show you around the place ..."; } else if($brief1 == 2){ $brief1_info = "brief is on 2"; } ?> The problem is, the BACK and CONTINUE buttons don't work. If $brief1 equals 0, and the user presses continue, the is should go to 1, and the brief1_info string is changed (so some different text shows in my html). It actually works when brief1 is on '0', but when its on 1 and the user pressed continue, the brief1 is changed to 1, but because the submit button refreshes the page, the variable is re-read again, and thus is reset back to 0. Is there a way around this? Or is there a better method than what I'm doing? Thanks Hi, I want to create a forgotten password page, where the user enters in their email address, the script queries the database for that email address, creates a unique ID, stores that unique ID in the database, then emails the unique ID and the User ID off to the user in an HTML link e.g. http://somesite.com/reset-password.php?userId=2&uniqueId=132832189312978312. The reset page would then match the unique ID to the one in the database and let them enter in a new password into the form. Ok so I can do most of that so far except from the emailing to the user. I'm running an Ubuntu Server 10 at the moment as my test server which is on my local network. Do I need to set up a mail server on that for php mailing to work, or can I use some external SMTP for sending? I've had a play round with the PHP mail() function but it won't send anything at the moment. I'll also need some code for when the site is running in the hosted live environment as it will likely use their mail servers. What's the best way to go about doing this? Many thanks! Forgive me if I am using the word "globally" incorrectly... I want to reset the content of a particular field in all rows of a table to a specific value, I was thinking of nesting a query inside a query for the same table, but was not sure that this would work: ... $query = "SELECT * FROM music WHERE picked >'0'"; $result = mysql_query($query) or die ("Couldn't execute query."); /* reset the picked field to zero (0) */ while ($row = mysql_fetch_array($result)) { $picked = 0; $query= "UPDATE music SET picked='$picked' WHERE title='$title'"; $selectresult = mysql_query($query) or die ("Problem with the query: $query<br>" . mysql_error()); } ... Is this the correct approach or is there a better way of doing this? |