Jump to content
Updating IPB tonight Read more... ×

Archived

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

buffness80

Updating MySQL via PHP

Recommended Posts

As kind of a background of my page...we are developing a card game and have the card info in a MySQL db. The info is put in through an html form that is submitted to a php processor (for lack of a better term) and then sent to the MySQL db. I don't have any problems submitting new cards and all the info is put into the db without any problems. However, I then have a page that is used to modify the entries in the db. I can get the info to populate in the html form fields, but when I try and submit them the textarea field will not update. If I take out the textarea field (which is the only multi line field) all the fields update just fine but with it in there it does not update any of them.

Here is what my form looks like WITH the textarea:

[code] <form id='add_player' name='add_player' method='post' action='modify_play_proc.php'>
  <div align='center'>
    <table width='500' border='0' cellpadding='2' cellspacing='2'>
      <tr>
        <td width='150'><div align='right'>Name: </div></td>
        <td><label>
          <div align='left'>
            <input name='name' type='text' id='name' value='$name' size='16' maxlength='16' />
          </div>
        </label></td>
      </tr>
      <tr>
        <td><div align='right'>Type:</div></td>
        <td><label>
          <div align='left'>
            <label>
            <select name='type' id='type'>
              <option value='Offense' selected='selected'>Offense</option>
              <option value='Defence'>Defense</option>
            </select>
            </label>
          </div>
        </label></td>
      </tr>
      <tr>
        <td><div align='right'>Shooter: </div></td>
        <td><label>
          <div align='left'>
            <select name='position_used' id='position_used'>
              <option>Select Position...</option>
              <option value='PG'>Point Guard</option>
              <option value='SG'>Shooting Guard</option>
              <option value='SF'>Small Foward</option>
              <option value='PF'>Power Forward</option>
              <option value='C'>Center</option>
                        </select><strong>Currently: </strong>$position_used          </div>
        </label></td>
      </tr>
      <tr>
        <td><div align='right'>Stats Used: </div></td>
        <td><div align='left'>
          <select name='stats_used' id='stats_used'>
            <option>Select Stat...</option>
            <option value='Drive'>Drive</option>
            <option value='Perimeter'>Perimeter</option>
            <option value='Post'>Post</option>
          </select><strong>Currently: </strong>$stats_used
        </div></td>
      </tr>
      tr>
        <td valign='top'><div align='right'>Description:</div></td>
        <td><label>
          <textarea name='desc' cols='40' rows='10' id='desc'>$desc</textarea>
        </label></td>
      </tr>
      <tr>
        <td><div align='right'></div></td>
        <td><label>
          
          <div align='left'>
            <input type='hidden' name='number' id='number' value='$number'>
            <input type='submit' name='Submit' value='Submit' />
          </div>
        </label></td>
      </tr>
    </table>
  </div>
</form> [/code]

The desc field above is the one in question. You modify the entries in the fields and then submit it to this PHP processor:

[code] <?php

    $name1 = $_POST["name"];
    $type1 = $_POST["type"];
    $desc1 = $_POST["desc"];
    $number1 = $_POST["number"];
    $position_used1 = $_POST["position_used"];
    $stats_used1 = $_POST["stats_used"];
    $def_drive1 = $_POST["def_drive"];
    $def_per1 = $_POST["def_per"];
    $def_post1 = $_POST["def_post"];
    
if ($type1 == 'Offense') {

mysql_connect("localhost" , "login" , "password");
mysql_select_db("dbname");
    
      $sql = "UPDATE plays SET name='$name1', type='$type1', pic='$type1.gif', position_used='$position_used1', stats_used='$stats_used1', desc='$desc1' WHERE number='$number1'";

      $result = mysql_query($sql);
      
      } elseif ($type1 == 'Defense') {
      
mysql_connect("localhost" , "login" , "password");
mysql_select_db("dbname");
    
      $sql = "UPDATE plays SET name='$name1', type='$type1', pic='$type1.gif', def_drive='$def_drive1', def_per='$def_per1', def_post='$def_post1', desc='$desc1' WHERE number='$number1'";

      $result = mysql_query($sql);
      
    }

?> [/code]

I know that this code works because if I take all the "desc" stuff out everything updates just fine. I would normally think it has something to do with it being a multi line textarea but when a card is put in for the first time the "desc" is put in the db just fine.

Oh, and I can echo the desc, so the info is being passed to the php script just fine.

Hopefully that is all the info needed...if anything else is required let me know.

Thanks in advance,

Ryan

Share this post


Link to post
Share on other sites

×

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.