Jump to content

[SOLVED] UPdate!?


mikelmao

Recommended Posts

Whats wrong about this?

<?php
    include "connect.php";
    if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
    mysql_query("UPDATE servers SET `name`='". $_POST['name'] ."' AND `ip`='". $_POST['ip'] ."' AND `port`='". $_POST['port'] ."' AND `desc`='". $_POST['desc'] ."' WHERE id='". $_POST['id'] ."'");
    echo "The changes have been made.";
    }
    $a = mysql_query("SELECT * FROM servers WHERE id=". $_GET['id'] ."");
    while($r = mysql_fetch_array($a))
    {
      echo "<form method='post'>
      <table>
      <input type='hidden' value='". $_GET['id'] ."' name='id'>
      <tr>
      <td>Server Name:</td> <td><input type='text' value='". $r['name'] ."' name='name'></td>
      </tr>
      <tr>
      <td>Server IP:</td><td><input type='text' value='". $r['ip'] ."' name='ip'></td>
      </tr>
      <tr>
      <td>Server Port:</td><td><input type='text' value='". $r['port'] ."' name='port'></td>
      </tr>
      <tr>
      <td>Description:</td><td><textarea rows='8' cols='35' name='desc'>". nl2br($r['desc']) ."</textarea></td>
      </tr>
      <tr>
      <td><input type='submit' value='Submit'></td>
      </tr>
      </table>
      </form>";
    }
?>

 

Something is wrong because it updates the Name to 0

Link to comment
Share on other sites

Most likely $_POST['name'] is not being set. Echo it to check.

 

Because it updates it to $_POST['name'] ."' AND `ip`='". $_POST['ip'] ."' AND `port`='". $_POST['port'] ."' AND `desc`='". $_POST['desc'] ."' WHERE id='". $_POST['id'] ."' which is FALSE (or 0)

 

Check the syntax for UPDATE query.

http://dev.mysql.com/doc/refman/5.0/en/update.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.