Jump to content

Newbiephper

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Newbiephper's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. ok thx for that i made the chagne like u said but nothing happened. still nothing appears. Total land: 200Free land: 200Number of Farms: Number of Homes: Number of Mines: is what it looks like as u can see no values appear for number of farms e.t.c. also total land is defined in script so maybe it is the table. im using the phpfreaks user script, just like at registration script it does this: [code] $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error()); [/code] do i also need to add insert records for the other tables i.e. so when the user gets created it also creates 1st records for buildings table, research table.  i think then this will make use of the user id i have added to other tables like buildings e.t.c. as the user id then in all should be same??  am i right here.  only been doing php 2-3 days so its all new terrain.
  2. ahh good thx i fixed that error that came up a spelling mistake in my database, many thx. new problem now is that using code seen above. the number of buildings constructed should refresh so when user says build 30 farms (nfarms) it will say Number of Farms 30, but nothing is showing up. i know this is php help part but since i dont know if the problem is this or my databse ill post both. script above table used to create below [code] CREATE TABLE buildings (   userid int(25) NOT NULL auto_increment,   nfarms int(10) NOT NULL default '',   nmines int(10) NOT NULL default '',   nhomes int(10) NOT NULL default '',   PRIMARY KEY  (userid) ) TYPE=MyISAM COMMENT='buildings'; [/code] userid i was intending this to be same userid as in my users table.  otherwise how does my database store data for each individual user.  this is made primary key.  others are just number of farms, mines, e.t.c. for that user.  any help with data not showing appreciated.
  3. can any1 tell me why this comes up for my code Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in XXX/buildings.php on line 23. [code] <?php session_start(); //buildings.php //open database connections require_once('db.php'); if ($_POST['farm'] || $_POST['house'] || $_POST['mine']) { $farm = $_POST['farm'] > 0 ? $_POST['farm'] : 0; $house = $_POST['house'] > 0 ? $_POST['house'] : 0; $mine = $_POST['mine'] > 0 ? $_POST['mine'] : 0; $qry = "update buildings set nfarms = nfarms + " . $farm . " where userid='$userid', nhouse = nhouse + " . $house . " where userid='$userid', nfarm  = nfarm +  " . $farm . " where userid='$userid'"; $qry = mysql_query($qry); } //define planet size define("TLAND", 200); //get current number of buildings $qry="select nfarms,nhomes,nmines from buildings where userid='$userid'"; $qry = mysql_query($qry); $row = mysql_fetch_assoc($qry);  //line23 $nf = $row[nfarms]; $nh = $row[nhomes]; $nm = $row[nmines]; //check for free land sapce $fland = ((TLAND) - ($nf+$nh+$nm)); //output current data echo "Total land: " . TLAND; echo "Free land: " . $fland; echo "Number of Farms: " . $nf; echo "Number of Homes: " . $nh; echo "Number of Mines: " . $nm; //allow building form if ($fland>0) { ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input size="4" type="text" name="farm"> <input size="4" type="text" name="house"> <input size="4" type="text" name='mine'> <input type="submit" name="submit" value="Build"> <?php } else { echo "No free land to build upon"; } ?> [/code]
  4. ok i read the page 2x over and say cautions talk of globals but wasnt understanding it just as i havent understood any of that manual.  i read that since php 4 globals are off by default and will be completely removed  in php 6. so maybe im missing something but what do i replace register session with/how do i solve my problem? wow im more confused now than before :( [quote] If your script uses session_register(), it will not work in environments where the PHP directive register_globals  is disabled. [/quote] [quote] If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. [/quote] does this mean its automatic? i.e. i dont need to do anything other than delete the waste code (i.e. register session)? i origianlly though the problem was with my code, particuarly bits like this [code] where userid='$userid' [/code]
  5. ok ill show the process first is Check User; [code] <? /* Check User Script */ session_start();  // Start Session include 'db.php'; // Conver to simple variables $username = $_POST['username']; $password = $_POST['password']; if((!$username) || (!$password)){ echo "Please enter ALL of the information! <br />"; include 'login_form.html'; exit(); } // Convert password to md5 hash $password = md5($password); // check if the user info validates the db $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ foreach( $row AS $key => $val ){ $$key = stripslashes( $val ); } // Register some session variables! session_register('first_name'); $_SESSION['first_name'] = $first_name; session_register('last_name'); $_SESSION['last_name'] = $last_name; session_register('email_address'); $_SESSION['email_address'] = $email_address; session_register('special_user'); $_SESSION['user_level'] = $user_level; session_register('userid'); $_SESSION['userid'] = $userid; session_register('username'); $_SESSION['username'] = $username; mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'"); header("Location: header.php"); } } else { echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br /> Please try again!<br />"; include 'login_form.html'; } ?> [/code] this is from phpfreaks i added two additional register session handles userid and username. this takes u to header.php : simple menu selection [code] <?php session_start(); echo "Welcome Commander". $_SESSION['username'] ." to you empire."; echo "Manage your kingdom:"; echo"<a href='buildings.php>Buildings</a>"; echo"<a href='research.php>Research</a>"; echo"<a href='shipyard.php>Shipyard</a>"; ?> [/code] so to the main part of site: the session should follow and maintain userid and username right? [code] <?php session_start(); //buildings.php //open database connections require_once('db.php'); if ($_POST['farm'] || $_POST['house'] || $_POST['mine']) { $farm = $_POST['farm'] > 0 ? $_POST['farm'] : 0; $house = $_POST['house'] > 0 ? $_POST['house'] : 0; $mine = $_POST['mine'] > 0 ? $_POST['mine'] : 0; $qry = "update buildings set nfarms = nfarms + " . $farm . " where userid='$userid', nhouse = nhouse + " . $house . " where userid='$userid', nfarm  = nfarm +  " . $farm . " where userid='$userid'"; $qry = mysql_query($qry); } //define planet size define("TLAND", 200); //get current number of buildings $qry="select nfarms,nhomes,nmines from buildings where userid='$userid'"; $qry = mysql_query($qry); $row = mysql_fetch_assoc($qry); $nf = $row[nfarms]; $nh = $row[nhomes]; $nm = $row[nmines]; //check for free land sapce $fland = ((TLAND) - ($nf+$nh+$nm)); //output current data echo "Total land: " . TLAND; echo "Free land: " . $fland; echo "Number of Farms: " . $nf; echo "Number of Homes: " . $nh; echo "Number of Mines: " . $nm; //allow building form if ($fland>0) { ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input size="4" type="text" name="farm"> <input size="4" type="text" name="house"> <input size="4" type="text" name='mine'> <input type="submit" name="submit" value="Build"> <?php } else { echo "No free land to build upon"; } ?> [/code] until finally they can logout (this again from php freaks) [code] <? session_start(); if(!isset($_REQUEST['logmeout'])){ echo "<center>Are you sure you want to logout?</center><br />"; echo "<center><a href=logout.php?logmeout>Yes</a> | <a href=javascript:history.back()>No</a>"; } else { session_destroy(); if(!session_is_registered('first_name')){ echo "<center><font color=red><strong>You are now logged out!</strong></font></center><br />"; echo "<center><strong>Login:</strong></center><br />"; include 'login_form.html'; } } ?> [/code] so why do my sessions not work for keeping userid and username for main section of site i.e. buildings.php.  is there some clash or am i going wrong somewhere.
  6. sry to use this post but it will get my point across $query = "UPDATE photos SET comments='$comment_tmp' WHERE id='91'; what would happen if you wanted to use the 'id' from one table to update data in tanother table. i.e. u have 2 tables user data (this contains id) table x ( you want to update data in this table for that particular user) thx any help
  7. thx toonmariner for the script changes and explanations ^^  off i go to code more now, hopefully ill manage a little longer before getting stuck :)
  8. reply thx ill try that with the little fix that GR made too.  just a few things: why is that if statement relating to the form at the top? the '?' is shorthand for an if statement? what does teh colon mean (:)? [quote] $farm = $_POST['farm'] > 0 ? $_POST['farm'] : 0; $qry = "update buildings set nfarms = nfarms + " . $farm . " [/quote] so in english what happens here is that if user submits a value posted to variable $farm then $qry transfers this value to databse.  im guessing " . $variable . " is standard convention for posted variables. thx for help, and it would be grate if you could answer my questions as whilst the script is great and im sure works, im trying to learn as i make so need to try and understand stuff as well.  everything else i understand, a little rusty on arrays but understand basic principle.  thx a lot again.
  9. hello again i was trying to write my first code with no aids and hit a dead end. the code basically consists of a display feature to display values (total land, free land and the 3 building types); then the form action(build new buildings), then when build submit it should send data to server for storage and also update page. my code at the moment looks like: [code] <?php //buildings.php //open database connections include 'db.php' //define planet size define("TLAND, 200") //get current number of buildings $nfarms="select nfarms from buildings"; $nhomes="select nhomes from buildings"; $nmines="select nmines from buildings"; $nf = mysql_query($nfarms) $nh = mysql_query($nhomes) $nm = mysql_query($nmines) //check for free land sapce $fland = ((TLAND) - ($nfarms+$nhomes+$nmines)) //output current data echo "Total land: " . TLAND; echo "Free land: " . $fland; echo "Number of Farms: " . $nf; echo "Number of Homes: " . $nh; echo "Number of Mines: " . $nm; //allow building form if ($fland>0) { <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> echo "<input size=4 type=text name='farm'>" echo "<input size=4 type=text name='house'>" echo "<input size=4 type=text name='mine'>" <input type="submit" name="submit" value="Build"> } else { "echo "No free land to build upon"; } if ($_POST['farm'] || $_POST['house'] || $_POST['mine']) { if ($_POST['farm']) { $update1 = "update buildings set nfarms = nfarms + 1 "; [/code] my problem is how to proceed because i dont wanna just add a fixed value [quote] $update1 = "update buildings set nfarms = nfarms + 1 "; [/quote] where that 1 is i need the value that was submitted by the user.  this is why im stuck at moment.  any help greatly appreciated.  also if ur good u might just wanna check rest of code since its first try and probably has a zillion errors. thx a lot
  10. thx a million Crayon Violent.  this has provided me with tonnes of information and topics to read over.  eternally grateful.  the comments are a great help.  its an amazing thing to see it working.  next few days ill experiment with it and read over some things that came up in topic discussiona nd hopefully i'll be that little wiser for it. thx again to you and redarrow.
  11. my code is what u see above.  so yeah i think so. i tried it ur way, btw thx for your pm (im sorry about that if u like i will copy ur work over to forum for other people to view and learn as it was very informative). anyways based on a 1 page idea with submit button have a look at this and see how many problems i got :) [code] <html> <head> <title>Research Test</title> </head> <body> <h1>Carry out More Research</h1> <?php $db=mysql_connect("hostname","username","password"); mysql_select_db("dbname",$db);   if ($_POST['submit']) { $query="UPDATE research SET points='$points+1'"; $result=mysql_query($query);   } ?> <form action = '<?php $_SERVER['PHP_SELF']; ?>' method = 'post'>   <input type = 'submit' value='research' name='research'> </form> <p></p> <h2>Current Research level</h2> $query2="SELECT * from research"; $result=mysql_query($query2); while($record=mysql_fetch_assoc($result)) { while(list($key,$value)=each($record)) { echo "<br> $key : $value <br>"; } } ?> </body> </html> [/code] thx to any1 thats helped out on this problem.  i feel if i can get one workable example i can learn and modify it to fulfil many ideas i have.
  12. well page loads with no errors now and when i click to research it says database updated but still doesnt show current value on main page.
  13. Parse error: parse error, unexpected '{' for while($record=mysql_fetch_assoc($result) { wish i understood this last bit i might be able to work out problem myself.  cant wait for my php book to get here lol.  i wonder if ill get this example working before it does =). who said php was easy ^^
  14. thx for update.. new error comes up Warning: Variable passed to each() is not an array or object in XXX on line 23 while(list($key,$value)=each($result)) { maybe this is to do with my not having a key in the research table i only have 1 field which is points.  also i dont have userid since i dont have members area.  im just testing basic so i always delete [code] where userid='$userid [/code] thx for help so far.  if only it will display then that will be great.
  15. k ive tested them out and have 2 problems first being mysql_select_db("whatever",$db); -- what is whatever relating to the name of the table/field?? second is on page 1 i get Parse error: parse error, unexpected '{' for [code] { echo "<br> $key : $val <br>"; } [/code] and also what is that last bit trying to do?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.