Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    conection php with MySQL (case)

    I have problems to make a a case option with my php files.
    I have a index.php with links:

    Code:
    <a href="lib/consultas.php?accion=A">link1</a><br>
    <a href="lib/consultas.php?accion=B">link2</a><br>
    <a href="lib/consultas.php?accion=C">link3</a><br>
    <a href="lib/consultas.php?accion=D">link4</a><br>
    And now, I have another php file: consultas.php
    In this php i have this code:

    Code:
    $conexion = mysql_connect("localhost", "user", "pass");
    mysql_select_db("jiradb", $conexion);
    
    if($accion!=''){
    switch($accion)
    {
    
    case 'A':
    $queEmp = "select * from membershipbase where user_name like 'gbosch'";
    $resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
    $totEmp = mysql_num_rows($resEmp);
    echo Usuario: "<strong>".$rowEmp['USER_NAME']."</strong><br>";
    echo Grupo: "<strong>".$rowEmp['GROUP_NAME']."</strong><br>";
    break;
    
    case 'B':
    $queEmp = "select * from membershipbase where user_name like 'jcodina'";
    $resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
    $totEmp = mysql_num_rows($resEmp);
    echo Usuario: "<strong>".$rowEmp['USER_NAME']."</strong><br>";
    echo Grupo: "<strong>".$rowEmp['GROUP_NAME']."</strong><br>";
    break;
    
    }
    }
    When I execute my first link the php i don't work correctly. I don't see nothing! Why???

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    $accion will not exist unless you have register_globals enabled (deprecated; not recommended).
    You want to perform the switch on $_GET['accion']:
    PHP Code:
    if (isset($_GET['accion']))
    {
        switch (
    $_GET['accion'])
        {
            case 
    'A':
             ...
        }

    Since you're output code is the same, you may want to consider using the switch to only create the required sql, and perform the actual output after the switch. If you do this though, you'll need a default action for you're switch so you get something, even if its just to die you're script off.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    very very thanks!


  •  

    Posting Permissions

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