0

i throw a string value from the database in an input box...when i click update button, i need to clear the textbox after clicking update button..how?thanks a lot...

4
Contributors
7
Replies
12
Views
6 Years
Discussion Span
Last Post by lloydsbackyard
1
<form onsubmit='document.getElementById("textbox").value="";'>
<!-- or -->
<input type='submit' onclick='document.getElementById("textbox").value="";'>

or any other combination of form/input & onanything

Edited by almostbob: n/a

0

Use some javascript?

// Make sure input as an ID
// e.g. <input type="text" id="message">
// put this in Javascript in for when the user has submitted the form

<script type="text/javascript">
input = document.getElementById('message');
input.value="";
</script>

0

i tried some of the codes above but i cant get it still...the purpose is to update the record...after clicking update the value of the "uname" textbox will be deleted...the values was taken from the datatabase....

below is my code..

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'studentaccount';
$con = mysql_connect ($server,$user,$password);
$db = mysql_select_db($database);
 if (!$db || !$con)
 {
     die ('<h3>SERVER DOWN BE BACK LATER</h3>');
 }
 else
     {
     $user_id=$_GET['user_id'];
     $query = "SELECT * FROM users WHERE user_id=$user_id";
     $result = mysql_query($query);
     $records = mysql_fetch_array($result);
     //$cur_prev = $records ['previledge'];
     //echo $user_id;


     if (isset($_POST['update']))
     {
            $uname = strtoupper($_POST ['uname']);
            $prev = strtoupper($_POST ['prev']);
            $user = md5($_POST ['user']);
            $pass = md5($_POST ['pass']);
            $date = date("Y-m-d");
            $repeatpass = md5($_POST ['repeatpass']);
           // echo "$uname/$prev/$pass/$date/$repeatpass";
            $user_box = $_POST ['user'];
            $pass_box = $_POST ['pass'];
            $repeat_box = ($_POST ['repeatpass']);

            $query = "UPDATE users 
                      SET name='$uname',
                        previledge ='$prev',
                        password = '$pass',
                        date = '$date'
                      WHERE user_id = '$user_id';";

            if (($user_box)=='' || ($pass_box)=='' || ($repeat_box)=='')
            {
            echo "ALL FIELDS ARE REQUIRED!";
            }
            else if(($pass)!= ($repeatpass))
            {
            echo "PASSWORD MISMATCH";
            }   
            else 
            {    
              $result = mysql_query($query);
              if ($result)
              {
                  echo "SUCCESSFULLY SAVED!";
              }
              else
              {

                  echo "SAVE FAILED";
              }   
            }
     } 
      if (isset($_POST['delete']))
      {


          $query = "DELETE FROM users
                    WHERE user_id = '$user_id'";
          $result = mysql_query($query);


          if ($result)
          {
              echo "Successfully Deleted!";
          }
          else
          {
              echo "Delete Failed!";
          }

     }
 }
 ?>



<form method="POST" action="" >
    <table align="center">
            <tr>
            <td>Name:</td>
            <td><input type="text" name="uname" value="<?php echo$records['name'];?>"></td>
        </tr>
        <tr>
            <td>Previledge:</td>
            <td>
                <?php
                 $query = "SELECT * FROM previledges";
                $result = mysql_query($query);
                echo "<select name='prev'>";
                while($records = mysql_fetch_array($result))
                {
                  echo "<option>{$records ['prev_desc']}</option>";
                }
                   echo "</select>";
                ?>
                </td>
        </tr>
        <tr>
            <td>Username</td>
            <td><input type="text" name="user" ></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type="password" name="pass"></td>
        </tr>
         <tr>
            <td>Repeat Password</td>
            <td><input type="password" name="repeatpass"></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" name="update" value="Update" ><input type="submit" name="delete" value="Delete"></td>

        </tr>
    </table>

</form>

Edited by pyTony: fixed formatting

0

Try this, there is probably an easier way to just attach a function and onclick to your submit but try that :)

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'studentaccount';
$con = mysql_connect ($server,$user,$password);
$db = mysql_select_db($database);
if (!$db || !$con)
{
die ('<h3>SERVER DOWN BE BACK LATER</h3>');
}
else
{
$user_id=$_GET['user_id'];
$query = "SELECT * FROM users WHERE user_id=$user_id";
$result = mysql_query($query);
$records = mysql_fetch_array($result);
//$cur_prev = $records ['previledge'];
//echo $user_id;


if (isset($_POST['update']))
{
?>
<script type="text/javascript">
var input = document.getElementById('user');
input.value="";
</script>
<?
$uname = strtoupper($_POST ['uname']);
$prev = strtoupper($_POST ['prev']);
$user = md5($_POST ['user']);
$pass = md5($_POST ['pass']);
$date = date("Y-m-d");
$repeatpass = md5($_POST ['repeatpass']);
// echo "$uname/$prev/$pass/$date/$repeatpass";
$user_box = $_POST ['user'];
$pass_box = $_POST ['pass'];
$repeat_box = ($_POST ['repeatpass']);

$query = "UPDATE users 
SET name='$uname',
previledge ='$prev',
password = '$pass',
date = '$date'
WHERE user_id = '$user_id';";

if (($user_box)=='' || ($pass_box)=='' || ($repeat_box)=='')
{
echo "ALL FIELDS ARE REQUIRED!";
}
else if(($pass)!= ($repeatpass))
{
echo "PASSWORD MISMATCH";
} 
else 
{ 
$result = mysql_query($query);
if ($result)
{
echo "SUCCESSFULLY SAVED!";
}
else
{

echo "SAVE FAILED";
} 
}
} 
if (isset($_POST['delete']))
{


$query = "DELETE FROM users
WHERE user_id = '$user_id'";
$result = mysql_query($query);


if ($result)
{
echo "Successfully Deleted!";
}
else
{
echo "Delete Failed!";
}

}
}
?>



<form method="POST" action="" >
<table align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="uname" value="<?php echo$records['name'];?>"></td>
</tr>
<tr>
<td>Previledge:</td>
<td>
<?php
$query = "SELECT * FROM previledges";
$result = mysql_query($query);
echo "<select name='prev'>";
while($records = mysql_fetch_array($result))
{
echo "<option>{$records ['prev_desc']}</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="user" ></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>Repeat Password</td>
<td><input type="password" name="repeatpass"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="update" value="Update" ><input type="submit" name="delete" value="Delete"></td>

</tr>
</table>

</form>
0

<td><input type="text" name="uname" value="<?php if(!$_post){echo $records['name'];} ?>"></td>

Edited by almostbob: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.