Page 5 of 7

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:45 pm
by Goofan
sending code is:

Code: Select all

 
<a href="sidor/Infanteries.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Infanteries</a><br>        <!-- link to go to page Infanteries -->
 

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:47 pm
by iankent
Goofan wrote:ok, now i get:
NO saved_id!
so i guess it still aint passing the saved id...
nope. on the page where you output the URL you need to append the saved_id. your bit of code shows that you're adding $row['saved_id'], so it looks as though $row['saved_id'] hasn't been set.

actually that *might* be a problem, you're saying $row[saved_id] not $row['saved_id'], should still work but it could be that. other question stands though, does it even exist?

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:51 pm
by Goofan
im telling it to collect the saved_id here am i not?

and i changed the message from where u got the:
NO saved_id!

Code: Select all

 
  $id =(isset($_GET['saved_id'])) ? (int)$_GET['saved_id'] : false;
    if($id !== false) 
 {
    $sql="SELECT * FROM konto WHERE saved_id=$id";      //selecting all from DB "Konto" where saved_id is the same as in the array $id
    echo "<p>$sql</p>";
 } 
    else 
 {
    echo "NO saved_id!";
 }
 exit();  
 

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:53 pm
by Goofan
the change u thought "might work" didnt sorry :(

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:55 pm
by iankent
Yes but what I'm saying is that saved_id isn't getting as far as $_GET. In your page that outputs the menu (the <a> tag you posted a few posts ago) you need to make sure that $row['saved_id'] has actually been set. If that variable doesn't exist in your menu page then the <a> tag you're outputting will not have a saved_id at the end, so nothing gets passed to $_GET

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:57 pm
by Goofan
ok yes it is proberbly not set...
when i "show the text as running it shows this:

Code: Select all

 
 <a href="sidor/Infanteries.php?saved_id=" target="main">Infanteries</a><br>        <!-- link to go to page Infanteries -->
 
this is when i am running it it got no saved_id

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:58 pm
by Goofan
hmm code for that page is:
code:

Code: Select all

 
<?php
include "login/database.php";       //page to where the database setting is, including this file into the php script of wichh is below it
$id =(isset($_GET['saved_id'])) ? $_GET['saved_id'] : false;        //putting the information within saved_id of witch i got from the previous page and putted it into $id
 
     $sql="SELECT * FROM konto WHERE saved_id=$id";     //selecting all from DB "Konto" where saved_id is the same as in the array $id
    echo "<p>$sql</p>";
$result = mysql_query($sql) or die(mysql_error());      //choose all from table //fetch all info in the table
 
                 
while($row = mysql_fetch_array( $result ))      //fetching info from file and putting it in $row
{
    $user=$row['user'];     //fetching the "user" information in the tabledata
}
?>
 

Code: Select all

 
<html>      <!--creating html scripting below-->
<title>Menu</title>     <!--selecting the title of the page-->
<head>      <!--starting head  "all typed here will not be able to show for the public"-->
 
<center><img src="sidor/pictures/medieval_flag1.jpg" width="150" height="110"><br><br>      <!-- choosing a picture to show the public and desiding it´s width and height-->
    <style type="text/css">     <!--selecting the style type-->
        <!--
        a:link {text-decoration: none; color: blue}
        a:visited {text-decoration: none; color: blue}
        a:active {text-decoration: none; color: blue} 
        a:visited {text-decoration: none; color: blue}
        -->
    </style>        <!--ending the style type-->
</head>     <!--ending the head-->
<BODY bgcolor="#A4A8B0" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">     <!--Selecting the background colour for the body-->
<table align="left" valign="top" cellspacing=0 cellpadding=0 width="100%">      <!--telling the table that all its content will be aligned left (be as far from left as possible) and that the text should be valign top (starting at the top of the tabledata)-->
                 <tr>       <!-- New Table row created -->
             <td>       <!-- New Table Data created -->
         <font color="#0000CC"><b>Username:  <font color="black">[ <?php echo $user; ?> ]</b><br>
             </td>      <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table row created -->
             <td>       <!-- New Table Data created -->
 <font color="black"><b>MENU</b>        <!-- Telling the "user" what the links below will contain /more or less/-->
 
            </td>           <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table Row created -->
             <td>           <!-- New Table Data created -->
 
 <a href="sidor/overview.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Overview</a><br>     <!-- link to go to page overview -->
 
 <a href="sidor/scoreboard.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Scoreboard</a>     <!-- link to go to page Scoreboard -->
            </td>           <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table Row created -->
             <td>           <!-- New Table Data created -->
             
 <font color="black"><b>BUILDINGS</b>       <!-- Telling the "user" what the links below will contain /more or less/-->
 
            </td>           <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table Row created -->
             <td>           <!-- New Table Data created -->
 <a href="sidor/Civilian Houses.php?saved_id=<?php echo $row[saved_id]; ?>" target="main"><u>Civilian Houses</u></a><br>        <!-- link to go to page Civilian Houses -->
 
 <a href="sidor/Military Houses.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Military houses</a><br>       <!-- link to go to page Military houses -->
 
 <a href="sidor/Research.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Research</a>     <!-- link to go to page Research -->
            </td>           <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table Row created -->
             <td>           <!-- New Table Data created -->
             
 <font color="black"><b>UNITS</b>       <!-- Telling the "user" what the links below will contain /more or less/-->
 
            </td>           <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table Row created -->
             <td>           <!-- New Table Data created -->
 <a href="sidor/Infanteries.php?saved_id=<?php echo $row['saved_id']; ?>" target="main">Infanteries</a><br>     <!-- link to go to page Infanteries -->
 
 <a href="sidor/Military Vehicles.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Cavalry</a><br>     <!-- link to go to page Vehicles -->
 
 <a href="sidor/Military Boats.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Navy</a>       <!-- link to go to page Military Boats -->
            </td>           <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table Row created -->
             <td>           <!-- New Table Data created -->
             
 <font color="black"><b>FOR YOU</b>     <!-- Telling the "user" what the links below will contain /more or less/-->
            </td>           <!--  Table Data ended -->
                 </tr>      <!-- Table Row ended-->
                 <tr>       <!-- New Table Row created -->
            <td>            <!-- New Table Data created -->
 <a href="sidor/News.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">News</a><br>     <!-- link to go to page News -->
 
 <a href="sidor/Mission.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Missions</a><br>      <!-- link to go to page Missions -->
 
 <a href="sidor/Mission.php?saved_id=<?php echo $row[saved_id]; ?>" target="main">Contact Us</a><br>        <!-- link to go to page Contact Us -->
 
 <a href="logout/logout_member.php" target="menu">logout</a><br>        <!-- link to go to page logout -->
             </td>          <!--  Table Data ended -->
                 </tr>      <!-- New Table Row created -->
 
</body>     <!--body ending-->
</html>     <!--html scripting ending-->
 
 

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 2:59 pm
by iankent
Then that's your problem. Copy and paste the contents of your menu file and we'll see whats wrong.

This is why it'd be easier to use a session. Start off by checking whether the session has a saved_id, if not then ask the user to choose a saved_id (or look it up using their userid), and store it in $_SESSION so its always available without having to append it to every link. Is there any reason not to use a session?

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 3:01 pm
by iankent
In your menu file your also getting saved_id from the URL, and you're putting it in $id, so when you output the <a> links at the end you need to use <?=$id?> or <?php echo $id ?> to output the saved_id, not $row['saved_id'] as you currently are.

it also means when you first access the page you'll need to manually add ?saved_id=1 or whatever to set it

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 3:03 pm
by Goofan
well i have learned by "speaking to co-workers" that $_session got alot of faults...
for exampel if i remember correct:
If u close by (go by Vtrl + Alt + Delete) and close the webbpage it will keep u loged in and u might never get back into ure login...

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 3:06 pm
by Goofan
iankent wrote:In your menu file your also getting saved_id from the URL, and you're putting it in $id, so when you output the <a> links at the end you need to use <?=$id?> or <?php echo $id ?> to output the saved_id, not $row['saved_id'] as you currently are.

it also means when you first access the page you'll need to manually add ?saved_id=1 or whatever to set it

well i dont really understand
first thing:
do you mean i need to input it to be:

Code: Select all

 
<a href="sidor/Infanteries.php?$id=<?php echo $row['saved_id']; ?>" target="main">Infanteries</a><br>       <!-- link to go to page Infanteries -->
 
Or

Code: Select all

 
<a href="sidor/Infanteries.php?saved_id=<?php echo $id; ?>" target="main">Infanteries</a><br>       <!-- link to go to page Infanteries -->
 
then second thing u mean i need to put what theire saved id is at the beginning?
If so then i can tell u that when a person logs in he gets hes saved_id as is set when he register.

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 3:09 pm
by Goofan
ok it worked with second! :D
but am i now needed to Get $id instead of get $row[saved_id]?

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 3:10 pm
by Goofan
nvm it works kind of now however all its outputting is:

SELECT * FROM konto WHERE saved_id=2
nothing else is shown

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 3:11 pm
by iankent
Goofan wrote:well i have learned by "speaking to co-workers" that $_session got alot of faults...
for exampel if i remember correct:
If u close by (go by Vtrl + Alt + Delete) and close the webbpage it will keep u loged in and u might never get back into ure login...
it shouldn't. if you just use a normal session it will end when the browser window closes (note window, not tab in most browsers). if you use ctrl+alt+del or restart the computer or shut down the browser the session should end. if it doesn't thats a browser fault and not a PHP session fault. as far as I know this works perfectly in almost all browsers (certainly does in IE5/6/7/8, Opera, Safari, Chrome and Firefox).

The exception to this is if you manually change the session expiry date to something in the future. If you do, the session becomes persistent even when the browser window is closed/computer crashes etc. but thats only if you tell it to, otherwise it shouldn't.

lots of websites use sessions to store data, its pretty much the only straightforward way to manage data during a users time on a website. without sessions it's much more difficult and can get very messy

when a user logs in you retrieve the saved_id from the database? if so, what do you do with it? it needs to be passed to the menu file as a $_GET variable, i.e. yourfile.php?saved_id=x - that way the menu file can output the saved_id in the link, which will then pass it to the other script for the SQL query. a bit of a messy way of doing it I must say.

Yes, you need to change it to <?php echo $id ?> - at the top of the menu file you get the saved_id from the URL and put it in $id NOT $row['saved_id']. Also, please read my posts carefully, I've said most of the last two paragraphs before!

Re: Getting buttons and textboxes within loop

Posted: Thu Nov 19, 2009 3:15 pm
by Goofan
ohh right i had a Exit :d can see now however its still not uppdating if i enter a value in one of the textboxes and press the button next to it (nothing happens)