MsKazza Posted June 7, 2016 Share Posted June 7, 2016 Hi all, Hoping someone might have an insight as to why this isn't working for me. The post is working as everything echo's ok, and there are no error messages, however it doesn't update at all. The db connection must be working as the text boxes on forms have an echo of the current content which displays ok. $recordID = $_GET["recordID"]; $result = mysqli_query($con,"SELECT * FROM news WHERE news_id = '$recordID'"); $row = mysqli_fetch_array($result); if (isset($_POST['submit'])) { $news_id = $_POST['recordID']; $news_title = $_POST['news_title']; $news_content = $_POST['news_content']; $publish = $_POST['publish']; $facebook = $_POST['facebook']; echo $news_id; echo $news_title; echo $news_content; echo $publish; echo $facebook; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Perform queries mysqli_query($con,"UPDATE news SET news_title='$news_title', news_content='$news_content', publish='$publish', facebook='$facebook' WHERE news_id='$news_id'"); mysqli_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/301306-update-not-working/ Share on other sites More sharing options...
Solution maxxd Posted June 7, 2016 Solution Share Posted June 7, 2016 There's no way for us to tell why it's failing right now as the SQL looks fine. What you need to do is check the results of the query. See if the query failed; if it did check the error using mysqli_error(). if(!mysqli_query($con, "UPDATE news SET news_title='$news_title', news_content='$news_content', publish='$publish', facebook='$facebook' WHERE news_id='$news_id'")){ print("<p>Don't print the error to screen in a real application; but for testing purposes the error is ".mysqli_error($con)."</p>"); } Also, please note that you're inviting SQL injection by putting suspect data ($_POST values) directly into the SQL. Look into prepared statements - honestly, here's where you're going to find PDO much easier to deal with. Quote Link to comment https://forums.phpfreaks.com/topic/301306-update-not-working/#findComment-1533452 Share on other sites More sharing options...
MsKazza Posted June 7, 2016 Author Share Posted June 7, 2016 Thank you for your reply. I have figured it out it wasn't picking up the news_id properly on post. But thank you for your suggestion on the PDO i will look into it. thanks Quote Link to comment https://forums.phpfreaks.com/topic/301306-update-not-working/#findComment-1533453 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.