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
https://forums.phpfreaks.com/topic/138869-solved-update/
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
https://forums.phpfreaks.com/topic/138869-solved-update/#findComment-726152
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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