Zepo. Posted June 26, 2007 Share Posted June 26, 2007 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?? Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 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? Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 Well the staff thing isnt the problem. How can i get the form to call it then =]. Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 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(); } ?> Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 Thank you very much =]. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 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'"); Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Where is $name defined? Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 That defines $_SESSION['name'], not $name. Where is $name defined? Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 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(); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Actually... this code doesn't do anything. It selects data from the database, then updates it with the same data. Maybe an explination of exactly what your trying to do is in order. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 actually i just wanna update it. Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 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? Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 I just wanna update $staff[notes] from the priorly defined $staff[notes] . Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 Not enough information I'm afraid. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 26, 2007 Share Posted June 26, 2007 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(); } } ?> Quote Link to comment Share on other sites More sharing options...
Zepo. Posted June 26, 2007 Author Share Posted June 26, 2007 Thank you VERY much thorpe. I love you....lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.