Jump to content

[SOLVED] Form Issue


Zepo.

Recommended Posts

I cant seem to get it to work, it just refreshes when you hit update.

 

<?php
session_start(); 

if (isset($_SESSION['name'])) {
if($_SESSION['rights'] >= 5){

echo "<div class='pagetitle'>Personal Notepad</div>
<div style='margin:10px'>
<br />
<table cellpadding='4' cellspacing='0' border='0' align='center' width='95%' class='tborder' id='optionsform' >
<colgroup span='2'>
<col style='width:45%'></col>
<col style='width:55%'></col>
</colgroup>
<tr>
<td class='tcat' align='center' colspan='2'>
<b>Notepad</b>
</td>
</tr>
<tr valign='top'>
<td class='optiontitle'  colspan='2'><div>Notepad</div></td>
</tr>
<tbody id='tbody_keywords'>
<form method='post'>
<tr valign='top'>
<td class='alt1'><div class='smallfont' ><center><textarea name='staff[notes]' style='width: 95%' rows='13'>$staff[notes]</textarea><br /><br />
<input type='hidden' name='action' value='editnotes'>
<input type='submit' name='submit' value='  Update  '></center></form></div></td>
</tr>
</tbody>
</table>";
}
}


function editnotes($action){

$_SESSION['name'] == $name;

mysql_query("UPDATE staff SET notes='$staff[notes]' WHERE $name='$staff[name]'");

echo "<div class='pagetitle'>Personal Notepad</div>
<div style='margin:10px'>
<br />
<table cellpadding='4' cellspacing='0' border='0' align='center' width='95%' class='tborder' id='optionsform' >
<colgroup span='2'>
<col style='width:45%'></col>
<col style='width:55%'></col>
</colgroup>
<tr>
<td class='tcat' align='center' colspan='2'>
<b>Admin CP Main</b>
</td>
</tr>
<tr valign='top'>
<td class='optiontitle'  colspan='2'><div>Notepad</div></td>
</tr>
<tbody id='tbody_keywords'>
<tr valign='top'>
<td class='alt1'><br /> Your notes have been updated!<br/></div></td>
</tr>
</tbody>
</table>";
}

?>

 

 

 

Whats wrong??

Link to comment
https://forums.phpfreaks.com/topic/57178-solved-form-issue/
Share on other sites

I changed it to

$staff=mysql_query("SELECT * FROM staff WHERE name='$name'");
$staff=mysql_fetch_array($staff);
mysql_query("UPDATE staff SET notes='$staff[notes]' WHERE name='$_SESSION['name']'");

 

But now it comes up Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/burly/public_html/dev/admin/includes/notepad.php on line 46

Link to comment
https://forums.phpfreaks.com/topic/57178-solved-form-issue/#findComment-282585
Share on other sites

I changed it to

$staff=mysql_query("SELECT * FROM staff WHERE name='$name'");
$staff=mysql_fetch_array($staff);
mysql_query("UPDATE staff SET notes='$staff[notes]' WHERE name='$_SESSION['name']'");

 

But now it comes up Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/burly/public_html/dev/admin/includes/notepad.php on line 46

 

Sorry, but im still learning.

Link to comment
https://forums.phpfreaks.com/topic/57178-solved-form-issue/#findComment-282591
Share on other sites

Try...

 

<?php

if ($result = mysql_query("SELECT * FROM staff WHERE name='{$_SESSION['name']}'")) {
  if (mysql_num_rows($result)) {
    $staff = mysql_fetch_array($result);
    if (!mysql_query("UPDATE staff SET notes='{$staff['notes']}' WHERE name='{$_SESSION['name']}'")) {
      echo mysql_error();
    }
  }
} else {
  echo mysql_error();
}

?>

Link to comment
https://forums.phpfreaks.com/topic/57178-solved-form-issue/#findComment-282594
Share on other sites

Ok, well now its updating it, but its updating it with nothing.

 

Heres what i got:

<?php
session_start(); 

$result = mysql_query("SELECT * FROM staff WHERE name='{$_SESSION['name']}'");
$staff = mysql_fetch_array($result);

if (isset($_SESSION['name'])) {
if($_SESSION['rights'] >= 5){

echo "<div class='pagetitle'>Personal Notepad</div>
<div style='margin:10px'>
<br />
<table cellpadding='4' cellspacing='0' border='0' align='center' width='95%' class='tborder' id='optionsform' >
<colgroup span='2'>
<col style='width:45%'></col>
<col style='width:55%'></col>
</colgroup>
<tr>
<td class='tcat' align='center' colspan='2'>
<b>Notepad</b>
</td>
</tr>
<tr valign='top'>
<td class='optiontitle'  colspan='2'><div>Notepad</div></td>
</tr>
<tbody id='tbody_keywords'>
<form method='post'>
<tr valign='top'>
<td class='alt1'><div class='smallfont' ><center><textarea name='notes' value='$notes' style='width: 95%' rows='13'>$staff[notes]</textarea><br /><br />
<input type='submit' name='submit' value='  Update  '></center></form></div></td>
</tr>
</tbody>
</table>";
}
}

 if (isset($_POST['submit'])) {
   editnotes();
 }


function editnotes(){

mysql_query("UPDATE staff SET notes='$notes' WHERE name='{$_SESSION['name']}'");

echo "<div style='margin:10px'>
<br />
<table cellpadding='4' cellspacing='0' border='0' align='center' width='95%' class='tborder' id='optionsform' >
<tr valign='top'>
<td class='optiontitle'  colspan='2'><div>Notepad</div></td>
</tr>
<tbody id='tbody_keywords'>
<tr valign='top'>
<td class='alt1'> Your notes have been updated!<br/></div></td>
</tr>
</tbody>
</table>";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/57178-solved-form-issue/#findComment-282626
Share on other sites

Change....

 

mysql_query("UPDATE staff SET notes='$notes' WHERE name='{$_SESSION['name']}'");

 

to

 

mysql_query("UPDATE staff SET notes='{$_POST['notes']}' WHERE name='{$_SESSION['name']}'");

 

Otherwise... based on this....

 

$staff=mysql_query("SELECT * FROM staff WHERE name='$name'");
$staff=mysql_fetch_array($staff);
mysql_query("UPDATE staff SET notes='$staff[notes]' WHERE name='$_SESSION['name']'");

 

This example may help you out.

 

<?php

 session_start();

 if (isset($_POST['submit'])) {
   $note = mysql_real_escape_string($_POST['note']);
   if (mysql_query("UPDATE staff SET notes = '$note' WHERE name = '{$_SESSION['name']}'")) {
     echo "Update complete";
   } else {
     echo "UPDATE Failed " . mysql_error();
   }
 } else {
   if ($result = mysql_query("SELECT notes FROM staff WHERE name = '{$_SESSION['name']}'")) {
     if (mysql_num_rows($result)) {
       $row = mysql_fetch_assoc($result);
       echo "<form method=\"post\">";
       echo "  <textarea name=\"note\">{$row['notes']}</textarea>";
       echo "  <input type=\"submit\" name=\"submit\">";
       echo "</form>";
     }
   } else {
     echo "SELECT Failed " . mysql_error();
   }
 }

?>

Link to comment
https://forums.phpfreaks.com/topic/57178-solved-form-issue/#findComment-282632
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.