Chappers Posted July 1, 2007 Share Posted July 1, 2007 Hi, I've got some code which, although I've messed around with it since, was working fine. Now it's not altering the data in the MySQL table. It's not even bringing up the confirmation message to say the data has been entered, nor is any error appearing. <?php require("connect.php"); $title="Edit Profile"; include("header.php"); $username = $_SESSION['username']; $result = mysql_query("SELECT status FROM profiles WHERE username='".$username."'") or die ('Error retrieving status for status check because: ' . mysql_error()); $row = mysql_fetch_assoc($result); $current_status = $row["status"]; echo "current status is {$current_status}"; if (isset($_POST['submit'])) { $new_status = $_POST['status']; mysql_query("UPDATE profiles SET status='$new_status' WHERE username='$username'") or die (mysql_error()); echo "<span class='n'>Status $new_status for $username inserted into table</span>"; } echo " <form action='{$_SERVER['PHP_SELF']}' method='post'> <table width='60%' align='center' border='1' cellspacing='0' cellpadding='3'> <tr> <td align='center'> <input type='submit' name='status' value='Single'> </td> <td align='center'> <input type='submit' name='status' value='Married'> </td> </tr> </table> </form> "; include('footer.php'); ?> Is it my code or might my free host be suffering some kind of glitch? Thanks Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/ Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Hmmm...I don't see anything wrong with the code. Try putting this at the top of your script. <?php error_reporting(E_ALL); ?> Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287474 Share on other sites More sharing options...
teng84 Posted July 1, 2007 Share Posted July 1, 2007 echo the query and look if variables are still intact Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287477 Share on other sites More sharing options...
AndyB Posted July 1, 2007 Share Posted July 1, 2007 Where's the session_start() instruction? Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287479 Share on other sites More sharing options...
Cless Posted July 1, 2007 Share Posted July 1, 2007 At the start of the script, you must put session_start(); . It should work. Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287481 Share on other sites More sharing options...
Chappers Posted July 1, 2007 Author Share Posted July 1, 2007 It seems not to be recognising that the submit button has been pressed, as nothing is coming up from an echo placed within the: if (isset($_POST['submit'])) {. Error reporting E_ALL isn't bringing up anything. I just click on the submit button (either Single or Married one) and the page refreshes looking identical, with an echo showing no change to the status field in the MySQL table. Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287482 Share on other sites More sharing options...
Chappers Posted July 1, 2007 Author Share Posted July 1, 2007 session_start(); is included in the required connect.php file. Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287485 Share on other sites More sharing options...
Cless Posted July 1, 2007 Share Posted July 1, 2007 Ah, I see. Well, I'm not entirely sure what the problem could be. I'll try using it on my website (however, edited, since, if directly ripped, will not work, because of mysql information). Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287486 Share on other sites More sharing options...
AndyB Posted July 1, 2007 Share Posted July 1, 2007 um, there's no point checking for isset($_POST['submit']) when the submit buttons are NAMEd status Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287487 Share on other sites More sharing options...
Cless Posted July 2, 2007 Share Posted July 2, 2007 Hmm, the reason must be because your using <form action="{$_SERVER['PHP_SELF']}" method="post"> I've never heard of PHP_SELF... why would you need to use that? Or does it mean keep the same page, but update information? o.O Otherwise, it must be the fact you are trying to update information before the information is set. Hmm, it seemed to work when I moved this: if (isset($_POST['submit'])) { $new_status = $_POST['username']; mysql_query("UPDATE Username SET username='$new_status' WHERE username='$username'") or die (mysql_error()); echo "<span class='n'>Status $new_status for $username inserted into table</span>"; } Below the form... Try it. Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287493 Share on other sites More sharing options...
pocobueno1388 Posted July 2, 2007 Share Posted July 2, 2007 Hmm, the reason must be because your using <form action="{$_SERVER['PHP_SELF']}" method="post"> I've never heard of PHP_SELF... why would you need to use that? Or does it mean keep the same page, but update information? o.O Otherwise, it must be the fact you are trying to update information before the information is set. Hmm, it seemed to work when I moved this: if (isset($_POST['submit'])) { $new_status = $_POST['username']; mysql_query("UPDATE Username SET username='$new_status' WHERE username='$username'") or die (mysql_error()); echo "<span class='n'>Status $new_status for $username inserted into table</span>"; } Below the form... Try it. None of what you just said would work. They are using $_SERVER['PHP_SELF'] correctly, so that shouldn't be the issue. Also, it is fine that the PHP coding is above the form. Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287505 Share on other sites More sharing options...
Chappers Posted July 2, 2007 Author Share Posted July 2, 2007 AndyB, seems I realised the same thing just before coming back here to say I'd found the trouble, only to see you'd already posted it. For some reason, I must have changed the submit button name last night, then forgotten I'd done it tonight. leaving me wondering why it wasn't working. The evils of long work days and staying up till the early hours on the computer. Thanks everyone. Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287506 Share on other sites More sharing options...
pocobueno1388 Posted July 2, 2007 Share Posted July 2, 2007 Ah! I think I have found the problem. This line right here: if (isset($_POST['submit'])) { You don't have any inputs named "submit", so any code in between isn't even being touched. Try changing that line to this: if (isset($_POST['status'])) { Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287508 Share on other sites More sharing options...
AndyB Posted July 2, 2007 Share Posted July 2, 2007 Well done, Chappers. Maybe the occasional beer break would have helped If you're happy with this, please use the SOLVED button at the bottom of the page. Ah! I think I have found the problem. Yup, right in this thread Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287510 Share on other sites More sharing options...
Cless Posted July 2, 2007 Share Posted July 2, 2007 Hmm, the reason must be because your using <form action="{$_SERVER['PHP_SELF']}" method="post"> I've never heard of PHP_SELF... why would you need to use that? Or does it mean keep the same page, but update information? o.O Otherwise, it must be the fact you are trying to update information before the information is set. Hmm, it seemed to work when I moved this: if (isset($_POST['submit'])) { $new_status = $_POST['username']; mysql_query("UPDATE Username SET username='$new_status' WHERE username='$username'") or die (mysql_error()); echo "<span class='n'>Status $new_status for $username inserted into table</span>"; } Below the form... Try it. None of what you just said would work. They are using $_SERVER['PHP_SELF'] correctly, so that shouldn't be the issue. Also, it is fine that the PHP coding is above the form. ...Alright then. I'm quite new to PHP, so, I don't really know way too much... o.O Link to comment https://forums.phpfreaks.com/topic/58001-solved-this-code-wont-insert-data-into-mysql-tableshould-it/#findComment-287515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.