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
Share on other sites

Whats wrong??

 

Plenty. For starters...

 

You never actually call your editnotes() function anywhere and your editnotes function contains what appears to be an array ($staff), however this is not defined anywhere.

 

 

Link to comment
Share on other sites

There is a config, this file is included in a different file that has the config in it, which defines most of the stuff, also

<input type='hidden' name='action' value='editnotes'>

Does that not call the editnotes function?

Link to comment
Share on other sites

Functions have there own scope. Unless you include this config file within the function, $staff does not exist within it. This still doesn't explain the fact that you never call your function. Hence, all this code does is refresh the form.

Link to comment
Share on other sites

Remove the $action peram from your editnotes() definition. It doesn't seem to be used. Then place this at the top of your script.

 

<?php

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

?>

Link to comment
Share on other sites

ok, but i cant figure out whats wrong with this now:

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

Link to comment
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
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
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
Share on other sites

Is that the best discription you've got? I assume you meen select the data from the database? Is this just one record we are going to be updating or do you need the form to handle multiple records based on an id?

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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