Problem installing on php5

Discussion in 'PHP' started by tobydawson13, Nov 20, 2010.

  1. #1
    Hi there,
    I'm installing this script on a php5 server, and it dosn't seem to be working.
    So I was wondering if anyone could take a look at the script below and let me know if they think there's anything wrong with it.

    The main problem is that the script doesn't seem to be updating when I submit the script. So there may be something wrong with the "if($_POST['update']) {" part?
    The problem isn't within the page head.php

    <?php
    include_once("head.php");
    if($_POST['update']) {
        foreach ($_POST['c_code'] as $key => $value) {
            mysql_query("UPDATE locDest SET destination = '$destination[$key]' WHERE c_code = '$value' ") or die("Error: " . mysql_error());
        }   
    }
    ?>
    <html>
    <head>
    <title>Update List</title>
    <link href="ip.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <form name="form1" method="post" action="<?php echo $_SYSTEM['PHP_SELF']; ?>">
      <table width="650" border="1" align="center" cellpadding="3" cellspacing="3" bordercolor="#000000">
        <tr> 
          <td align=center class="bodyBold"><b>Country</b></td>
          <td width="10" align=center class="bodyBold"><strong>Code</strong></td>
          <td align=center class="bodyBold"><b>Send traffic to</b></td>
        </tr>
        <?php
        $query = "SELECT * from locDest ORDER BY country";
        $result = mysql_query ($query) or die ("Query failed");
        while ($r = mysql_fetch_array($result)) {
            extract($r);
    echo <<<END
        <tr> 
          <td><font class=body>$country</font></td>
         <td align=center class=body>$c_code</font></td>
          <td><input name="destination[]" type="text" value="$destination" size="45"></td>
          <input name="c_code[]" type="hidden" value="$c_code">
        </tr>
    END;
    }
    ?>
      </table>
      <table width="650" border="0" align="center" cellpadding="4">
        <tr> 
          <td align=left width="57%">&nbsp; </td>
          <td align=right width="43%"><input name="update" type="submit" id="update" value="Submit"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    PHP:
    Thanks a lot :)
     
    tobydawson13, Nov 20, 2010 IP
  2. tobydawson13

    tobydawson13 Active Member

    Messages:
    645
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Can anyone see anything wrong with this?
    <?php
    include_once("head.php");
    if($_POST['update']) {
        foreach ($_POST['c_code'] as $key => $value) {
            mysql_query("UPDATE locDest SET destination = '$destination[$key]' WHERE c_code = '$value' ") or die("Error: " . mysql_error());
        }   
    }
    ?>
    PHP:
     
    tobydawson13, Nov 20, 2010 IP
  3. namduong8889

    namduong8889 Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What is $destination? I think it should be $_POST['destination'][$key]

    
    <?php
    include_once("head.php");
    if($_POST['update']) {
        foreach ($_POST['c_code'] as $key => $value) {
            mysql_query("UPDATE locDest SET destination = '".$_POST['destination'][$key]."' WHERE c_code = '$value' ") or die("Error: " . mysql_error());
        }   
    }
    ?>
    
    PHP:
     
    Last edited: Nov 20, 2010
    namduong8889, Nov 20, 2010 IP
  4. tobydawson13

    tobydawson13 Active Member

    Messages:
    645
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Thanks :)
    That seems to work.
     
    tobydawson13, Nov 20, 2010 IP