SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27

Thread: $_Get

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_Get

    I have an adminform which makes a list by name of all addresses in the table. Behind each line I use a link to go to the editform.

    PHP Code:
    <?php
    include("connect.php");

    $query"SELECT id, ordernummer, naam FROM zadres ORDER BY naam";
    $resultmysql_db_query($database$query) or die("Cannot query the database.<br>" mysql_error());
    ?>
    <table width="100%" border="1" cellspacing="2" cellpadding="2">
    <?php
    while ($row mysql_fetch_assoc($result)) { 
        
    $ordernummer $row['ordernummer']; 
        
    $naam $row['naam']; 
    ?>
    <tr>
        <td width="40%"><?php echo "$ordernummer ($naam)";?></td>
        <td width="5%"><a href=formeditadres.php?id=<?echo $row['id'];?>>edit</a></td>
        <td width="5%"><a href=formdeleteadres.php?id=<?echo $row['id'];?>>delete</a></td>
        </tr>
    <?php
    }
    ?>
    In formeditadres.php I have to use $_GET ['id'] somewhere. I just don't know how en where.

    PHP Code:
    <?php
    include("connect.php");
    if(
    $_POST['verstuurd'] == "1") {
    $plaatdataddslashes($_POST['plaatdat']);
    $einddataddslashes($_POST['einddat']);
    $ordnraddslashes($_POST['ordnr']);
    $afkomaddslashes($_POST['afkom']);
    $rubraddslashes($_POST['rubr']);
    $naamaddslashes($_POST['naam']);
    $omschaddslashes($_POST['omsch']);
    $straataddslashes($_POST['straat']);
    $postcaddslashes($_POST['postc']);
    $woonpaddslashes($_POST['woonp']);
    $provaddslashes($_POST['prov']);
    $landaddslashes($_POST['land']);
    $contpaddslashes($_POST['contp']);
    $telnraddslashes($_POST['telnr']);
    $mobnraddslashes($_POST['mobnr']);
    $faxnraddslashes($_POST['faxnr']);
    $emailaddslashes($_POST['email']);
    $webaddslashes($_POST['web']);
    $query"UPDATE zadres (plaatsingsdatum, einddatum, ordernummer, afkomst_id, rubriek_id, naam, zomschrijving, straatnaam, postcode, woonplaats, provincie_id, land_id, contactpersoon, telefoonnummer, mobielnummer, faxnummer, emailadres, website) VALUES ('$plaatdat', '$einddat', '$ordnr', '$afkom', '$rubr', '$naam', '$omsch', '$straat', '$postc', '$woonp', '$prov', '$land', '$contp', '$telnr', '$mobnr', '$faxnr', '$email', '$web') WHERE id='$id'";
    $result mysql_db_query($database$query) or die("Cannot query the database.<br>" mysql_error());
    echo 
    "Data gewijzigd.<br><br>";
    } else {
    $sql"SELECT * FROM zadres WHERE id='$id'";
    $query mysql_query($sql) or die("Cannot query the database.<br>" mysql_error());
    $result mysql_fetch_array($query);
    $plaatsingsdatumstripslashes($result["plaatsingsdatum"]);
    $einddatumstripslashes($result["einddatum"]);
    $ordernummerstripslashes($result["ordernummer"]);
    $afkomst_idstripslashes($result["afkomst_id"]);
    $rubriek_idstripslashes($result["rubriek_id"]);
    $naamstripslashes($result["naam"]);
    $omschrijvingstripslashes($result["omschrijving"]);
    $straatnaamstripslashes($result["straatnaam"]);
    $postcodestripslashes($result["postcode"]);
    $woonplaatsstripslashes($result["woonplaats"]);
    $provincie_idstripslashes($result["provincie_id"]);
    $land_idstripslashes($result["land_id"]);
    $contactpersoonstripslashes($result["contactpersoon"]);
    $telefoonnummerstripslashes($result["telefoonnummer"]);
    $mobielnummerstripslashes($result["mobielnummer"]);
    $faxnummerstripslashes($result["faxnummer"]);
    $emailadresstripslashes($result["emailadres"]);
    $websitestripslashes($result["website"]);
    }
    ?>
    I need help.

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you output the form to edit the address, add:
    HTML Code:
    <input type="hidden" name="id" value="<?php echo $_GET['id'] ?>" />
    Also, in your page you have $id a couple of times, and those should be either $_GET['id'] or $_POST['id'], depending on the circumstances.
    ck :: bringing chris to the masses.

  3. #3
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use $_REQUEST['id']and forget the method you used.

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    I disagree on using the $_REQUEST array.
    My opinion is that you should not use $_REQUEST. It's better to use $_POST and $_GET depending on where the variable is coming from. It increase the readability of you script. And you always know exatly where your variable is coming from.

    What happens if you have a form (method post) containing a field called 'id' and a 'id' variable in your url?

    -Helge

  5. #5
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Helge you are right...i have never thought in the case you have posted...perhaps because I try not to name 2 or more variables equally

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying several things but none of them seem to work.
    I'm almost going crazy right now, because I'm battling this file for 5 full days now.

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Helge
    Hi.
    I disagree on using the $_REQUEST array.
    My opinion is that you should not use $_REQUEST. It's better to use $_POST and $_GET depending on where the variable is coming from. It increase the readability of you script. And you always know exatly where your variable is coming from.

    What happens if you have a form (method post) containing a field called 'id' and a 'id' variable in your url?

    -Helge
    For security purposes, using $_REQUEST can also be a bad thing. If you expect $_POST variables and somebody hacks your querystring, using $_REQUEST can lead to some dastardly results.

  8. #8
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Typically I use $_REQUEST when I don't care whether data came from the $_GET or $_POST arrays, however whenever dealing with data which is inserted into a database (or requires a fair amount of processing/validation) I always use $_POST.
    Regards, Ant.

  9. #9
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wo wants to help me with my files?

  10. #10
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rodney
    Wo wants to help me with my files?
    Sorry Rodney.

    Try to put this right after your } else { but before the $sql.
    PHP Code:
    $id $_GET['id']; 
    If that doesn't do it, do you get any errormessages?

    HTH

    -Helge

  11. #11
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That doesn't work.
    I don't get errormassages.
    I believe it's "something" in my adminfile.
    When I put something like :
    PHP Code:
    <?php 
    if(!isset($_GET['id'])) 
        echo 
    "sh**"
    else 
        echo 
    $_GET['id']; 
    ?>
    ... in formeditadres.php, I do get "sh**" on my screen.

    When I go to formeditadres this is in my browser :
    ../formeditadres.php

    This is my adminfile :
    PHP Code:
    <body>
    <?php
    include("connect.php");
    $query"SELECT id, ordernummer, naam FROM zadres ORDER BY naam";
    $resultmysql_db_query($database$query) or die("Cannot query the database.<br>" mysql_error());
    ?>
    <table width="100%" border="1" cellspacing="2" cellpadding="2">
    <?php
    while ($row mysql_fetch_assoc($result)) { 
        
    $ordernummer $row['ordernummer']; 
        
    $naam $row['naam']; 
    ?>
    <tr>
        <td width="40%"><?php echo "$ordernummer ($naam)";?></td>
        <td width="5%"><a href=formeditadres.php?id=<?echo $row['id'];?>>wijzigen</a></td>
        <td width="5%"><a href=formdeleteadres.php?id=<?echo $row['id'];?>>verwijderen</a></td>
        </tr>
    <?php
    }
    ?>    
    </table>    
    </body>

  12. #12
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is then that the url isn't correct when you click on an edit link? Correct?

    Try
    PHP Code:
    while ($row = mysql_fetch_array($result)) { 
        $ordernummer = $row['ordernummer']; 
        $naam = $row['naam']; 
        $id = $row['id'];
    ?> 
    <tr> 
        <td width="40%"><?php echo "$ordernummer ($naam)";?></td> 
        <td width="5%"><a href=formeditadres.php?id=<?php echo $id?>>wijzigen</a></td> 
        <td width="5%"><a href=formdeleteadres.php?id=<?php echo $id?>>verwijderen</a></td> 
        </tr> 
    <?php 

    ?
    HTH

    -Helge

  13. #13
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do go to the right page.
    It's only a empty page without the data from the id I requested in admin.php.

  14. #14
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rodney
    I do go to the right page.
    It's only a empty page without the data from the id I requested in admin.php.
    Yes. But do the id get transferred to the form edit page.

    In your previous post it didn't seem like that.
    Quote Originally Posted by Rodney
    When I go to formeditadres this is in my browser :
    ../formeditadres.php
    First you need to sort out is: Get the id, through the url, from admin to form edit page. That's why I gave you the code in my last post.

    -Helge

  15. #15
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it works!
    Almost than....
    I only don't get the data that was selected in my drop down lists.

    This is what I use :
    PHP Code:
      <tr>
        <td>Rubriek</td>
        <td>
        <select name="rubr">
        <?php
        
    include("connect.php");
        
    $query "SELECT id, rubriek from zrubriek";
        
    $result mysql_db_query($database$query) or die("Cannot query the database.<br>" mysql_error());
        while (list(
    $id$rubr) = mysql_fetch_row($result))
        {
        if (
    $rubriek_id == $waarde['id'])
        {
        echo (
    "<option value=\"$waarde[id]\">$waarde[rubriek]</option>");
        } else { 
        echo (
    "<option value=\"$waarde[id]\" selected>$waarde[rubriek]</option>");  
        }
        }
        
    ?>
        </select>
        </td>
      </tr>

  16. #16
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rodney
    I only don't get the data that was selected in my drop down lists.
    And I don't get what the problem is Form, drop down? Where did that come from?

    Where do the variables $rubriek_id and $waarde['id'] coming from?

    -Helge

  17. #17
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a form addadress.php to fill the table "zadres".
    I use several drop downs like this to add :
    PHP Code:
        <td>Rubriek</td>
        <td>
        <select name="rubr">
        <?php
        
    include("connect.php");
        
    $query "SELECT id, rubriek from zrubriek";
        
    $result mysql_query($query);
        while (
    $waarde mysql_fetch_array($result))
        {
        echo (
    "<option value=\"$waarde[id]\">$waarde[rubriek]</option>");
        }
        
    ?>
        </select>
        </td>
    Now I also want to see the dropdown in formeditadres.php, only prefilled with the selected data. In case this has to be changed to.
    The variables come from :
    PHP Code:
    <?php
    include("connect.php");
    if(
    $_POST['verstuurd'] == "1") {
    $plaatdataddslashes($_POST['plaatdat']);
    $einddataddslashes($_POST['einddat']);
    $ordnraddslashes($_POST['ordnr']);
    $afkomaddslashes($_POST['afkom']);
    $rubraddslashes($_POST['rubr']);
    $naamaddslashes($_POST['naam']);
    $omschaddslashes($_POST['omsch']);
    $straataddslashes($_POST['straat']);
    $postcaddslashes($_POST['postc']);
    $woonpaddslashes($_POST['woonp']);
    $provaddslashes($_POST['prov']);
    $landaddslashes($_POST['land']);
    $contpaddslashes($_POST['contp']);
    $telnraddslashes($_POST['telnr']);
    $mobnraddslashes($_POST['mobnr']);
    $faxnraddslashes($_POST['faxnr']);
    $emailaddslashes($_POST['email']);
    $webaddslashes($_POST['web']);
    $query"UPDATE zadres (plaatsingsdatum, einddatum, ordernummer, afkomst_id, rubriek_id, naam, zomschrijving, straatnaam, postcode, woonplaats, provincie_id, land_id, contactpersoon, telefoonnummer, mobielnummer, faxnummer, emailadres, website) VALUES ('$plaatdat', '$einddat', '$ordnr', '$afkom', '$rubr', '$naam', '$omsch', '$straat', '$postc', '$woonp', '$prov', '$land', '$contp', '$telnr', '$mobnr', '$faxnr', '$email', '$web') WHERE id='$id'";
    $result mysql_db_query($database$query) or die("Cannot query the database.<br>" mysql_error());
    echo 
    "Data gewijzigd.<br><br>";
    } else {
    $sql"SELECT * FROM zadres WHERE id='$id'";
    $query mysql_query($sql) or die("Cannot query the database.<br>" mysql_error());
    $result mysql_fetch_array($query);
    $plaatsingsdatumstripslashes($result["plaatsingsdatum"]);
    $einddatumstripslashes($result["einddatum"]);
    $ordernummerstripslashes($result["ordernummer"]);
    $afkomst_idstripslashes($result["afkomst_id"]);
    $rubriek_idstripslashes($result["rubriek_id"]);
    $naamstripslashes($result["naam"]);
    $zomschrijvingstripslashes($result["omschrijving"]);
    $straatnaamstripslashes($result["straatnaam"]);
    $postcodestripslashes($result["postcode"]);
    $woonplaatsstripslashes($result["woonplaats"]);
    $provincie_idstripslashes($result["provincie_id"]);
    $land_idstripslashes($result["land_id"]);
    $contactpersoonstripslashes($result["contactpersoon"]);
    $telefoonnummerstripslashes($result["telefoonnummer"]);
    $mobielnummerstripslashes($result["mobielnummer"]);
    $faxnummerstripslashes($result["faxnummer"]);
    $emailadresstripslashes($result["emailadres"]);
    $websitestripslashes($result["website"]);
    }
    ?>

  18. #18
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry Rodney, but I don't follow you.

    I can't tell which code is relevant to the problem. Things don't get better when you use your native (probably) language as variable names.
    Is the 30+ variables you posted relevant to the problem you want help to?

    I suggest that you strip out the irrelevant code. Do only show how you try to get one select to work. Where does the variables to that spesific select come from and the if clause to check which option to pre select.
    Where do the $waarde['id'] variable coming from? I can't tell from the code you provided.

    I can show you how to do this in generic manner, but if you want something spesific you need to provide more information. I don't want to do alot of guessing on how your system work.

    I don't mean to be harsh on you, but it's kind of frustrating when you want help but don't take the time to give a better description of your problem/system.

    -Helge

  19. #19
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry. I thought I had made myself clear.
    But I'll try it again.

  20. #20
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll try to fix the "$waarde" first.

  21. #21
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We are now 2 days later and finally I get all the (right) data in my file (formeditadres).

    When I change something in this file and want to submit it, I get the next error :

    Cannot query the database.
    You have an error in your SQL syntax near '(plaatsingsdatum, einddatum, ordernummer, afkomst_id, rubriek_id, naam, zomschri' at line 1

    Line 1 is <html>, so that cannot be the problem.
    What do I have to look for? I checked the ";", "[", etc.

  22. #22
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    mysql_query
    ($sql) or die(mysql_error());
    ?>
    ...may or may not give you a better ide on what the error is depending on what the error is


    For security purposes, using $_REQUEST can also be a bad thing. If you expect $_POST variables and somebody hacks your querystring, using $_REQUEST can lead to some dastardly results.
    ...thats the entire anti-argument to register globals , just because a variable came from $_POST rather than $_GET should not make your code any more or less secure , if it does you may as well code with register_globals off cos you missed the point.

    I use $_REQUEST a lot where input may come from (in cases I may expect it to) $_GET or $_POST, but its also useful to have them as seperate variables as well , remember that once you have a $_REQUEST variable you can check its source if and when necc'y << still can't spell that!

  23. #23
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rodney.
    You have missed the "key word" SET in your query.
    Try:
    PHP Code:
    $query"UPDATE zadres SET(plaatsingsdatum, einddatum, ordernummer, afkomst_id, rubriek_id, naam, zomschrijving, straatnaam, postcode, woonplaats, provincie_id, land_id, contactpersoon, telefoonnummer, mobielnummer, faxnummer, emailadres, website) VALUES ('$plaatdat', '$einddat', '$ordnr', '$afkom', '$rubr', '$naam', '$omsch', '$straat', '$postc', '$woonp', '$prov', '$land', '$contp', '$telnr', '$mobnr', '$faxnr', '$email', '$web') WHERE id='$id'"
    If still have problems with the query, a tip for debugging is to echo out the query to see if all the variables are set properly. If you can't spot any errors, post the echoed query here (and the error message, if any) and someone will probably look into it.

    A small sidenote: If the id is stored in an integer type column (in the db) you should drop the quotes around it.
    PHP Code:
    (...) WHERE id=$id"; 
    -Helge

  24. #24
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    rotterdam
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Helge

    First of all thanks for all your help.
    The way you told me didn't work.
    I read a few articles and changed the query into :

    PHP Code:
    $query"UPDATE zadres SET plaatsingsdatum='$plaatdat', einddatum='$einddat', ordernummer='$ordnr', afkomst_id='$afkom', rubriek_id='$rubr', naam='$naam', zomschrijving='$omsch', straatnaam='$straat', postcode='$postc', woonplaats='$woonp', provincie_id='$prov', land_id='$land', contactpersoon='$contp', telefoonnummer='$telnr', mobielnummer='$mobnr', faxnummer='$faxnr', emailadres='$email', website='$web' WHERE id='$id'"
    And now it's working !!!!

    It's pure luck and I don't understand why it's working.
    Fanatic newbie as I am, I want to understand what I'm doing and do not want it to be luck everytime.

    Could you tell me what's the difference?

  25. #25
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    I'm glad you finally got it working!

    Both the methods are equal. I usually use the latter one because I find it more readable, and esaier to get right. That's propably why you got it working also.

    I usually "format" the query a bit more to make it even more readable. I would have written the last one like this.
    PHP Code:
    $query"UPDATE zadres 
                SET plaatsingsdatum = '
    $plaatdat', 
                    einddatum       = '
    $einddat', 
                    ordernummer     = '
    $ordnr', 
                    afkomst_id      = '
    $afkom', 
                    rubriek_id      = '
    $rubr', 
                    naam            = '
    $naam', 
                    zomschrijving   = '
    $omsch', 
                    straatnaam      = '
    $straat', 
                    postcode        = '
    $postc', 
                    woonplaats      = '
    $woonp', 
                    provincie_id    = '
    $prov', 
                    land_id         = '
    $land', 
                    contactpersoon  = '
    $contp', 
                    telefoonnummer  = '
    $telnr', 
                    mobielnummer    = '
    $mobnr', 
                    faxnummer       = '
    $faxnr', 
                    emailadres      = '
    $email', 
                    website         = '
    $web
              WHERE id = '
    $id'
                    "

    -Helge


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •