Jump to content

[SOLVED] Update when submiting


corkg

Recommended Posts

Hi

 

I have this code (below) it is a notepad when I submit the data it does not bring up the latest data that i have just submitted.


<?php
session_start();
include_once "includes/db_connect.php";
include_once"includes/functions.php";
logincheck();
$username=$_SESSION['username'];
$query=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($query);
$query1=mysql_query("SELECT * FROM user_info WHERE username='$username'");
$user=mysql_fetch_object($query1);

if (($_POST['change_notes']) && ($_POST['notes'])){
$notes=strip_tags($_POST['notes']);

mysql_query("UPDATE users SET notes='$notes' WHERE username='$username'");
echo "Your notes have been updated"; 
}
?>
<html>
<body>
<center>
  <br>
  <table width="713" border="1" class="thinline" rules="none" cellpadding="0" cellspacing="0" bordercolor=black bgcolor="">
    <tr>
      <td width="709" height="21" class="header">
        <div align="center"><font color="#FFFFFF">Note Pad</font> </div></td>
    </tr>
    <tr>
      <td ><table width="100%" height="383"  border="0" cellpadding="2" cellspacing="2">
        <tr>
          <td><form action="" method="POST">
         
              <br>
              <center><textarea name="notes" cols="100" rows="15" id="notes"><?php echo "$fetch->notes"; ?></textarea></center>
              <br>

              <br>
              <center><input name="change_notes" type="submit" id="change_notes" value="submit">
              </center><br>        
          </form></td>
        </tr>
      </table></td>
    </tr>
  </table>
  <br>
  <p> </p>
</center><p>
<?php include_once"includes/footer.php"; ?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/55540-solved-update-when-submiting/
Share on other sites

let me get this straight. it is a webpage notepad for users of your website. and they just out in notes and stuff and press a button which puts it in your database? and you can't get it to display the data that has been updated??

 

Regards ACE

I have got it working but can't get it to submit if there is nothing in the field

 

<?php
session_start();
include_once "includes/db_connect.php";
include_once"includes/functions.php";
logincheck();
$username=$_SESSION['username'];

if (($_POST['change_notes']) && ($_POST['notes'])){
$notes=strip_tags($_POST['notes']);

mysql_query("UPDATE users SET notes='$notes' WHERE username='$username'");
($_POST['change_notes']) && ($_POST['notes']);

echo "Your notes have been updated"; 
}
?>
<html>
<body>
<center>
  <br>
  <table width="713" border="1" class="thinline" rules="none" cellpadding="0" cellspacing="0" bordercolor=black bgcolor="">
    <tr>
      <td width="709" height="21" class="header"><div align="center"><font color="#FFFFFF">Note Pad</font> </div></td>
    </tr>
    <tr>
      <td ><table width="100%" height="383"  border="0" cellpadding="2" cellspacing="2">
          <tr>
            <td><form action="" method="POST">
                <br>
                <center>
                  <textarea name="notes" cols="100" rows="15" id="notes" ><?php $query=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($query);
$query1=mysql_query("SELECT * FROM user_info WHERE username='$username'");
$user=mysql_fetch_object($query1); echo "$fetch->notes"; ?>
</textarea>
                </center>
                <br>
                <br>
                <center>
                  <input name="change_notes" type="submit" id="change_notes" value="submit">
                </center>
                <br>
              </form></td>
          </tr>
        </table></td>
    </tr>
  </table>
  <br>
  <p> </p>
</center>
<p> </p>
</body>
</html>

I have fixed it using the code below

 

logincheck();
$username=$_SESSION['username'];
if(($_POST['change_notes']) && ($notes==NULL)){
mysql_query("UPDATE users SET notes='' WHERE username='$username'");}


if (($_POST['change_notes'])&&($_POST['notes'])){
$notes=($_POST['notes']);
mysql_query("UPDATE users SET notes='$notes' WHERE username='$username'");


echo "Your notes have been updated"; 

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.