Sigmahokies Posted November 21, 2019 Share Posted November 21, 2019 Hi everyone, I need a help...I don't understand why it is not work. I'm trying to "update" data in database, but it couldn't do that. Maybe there is wrong script in PHP. Can you find what did I do wrong? //Edit data from database if(isset($_GET['edit'])) { $edit = $_GET['edit']; $update = "select * FROM sampleDB where ID = '$edit';"; $updated = mysqli_query($GaryDB, $update); $change = mysqli_fetch_assoc($updated); if($change) { $editted = "<tr><td colspan='4'><input type='text' name='update' value='".$change['ID']."' readonly></td></tr> <tr><td colspan='5'><input type='text' name='update1' value='".$change['FirstName']."'></td></tr> <tr><td colspan='5'><input type='text' name='update2' value='".$change['LastName']."'></td></tr> <tr><td colspan='5'><input type='text' name='update3' value='".$change['City']."'></td></tr> <tr><td colspan='5'><input type='text' name='update4' value='".$change['State']."'></td></tr> <tr><td><input type='radio' name='update5' value='EST'>EST</td><td><input type='radio' name='update5' value='CST'> CST</td><td><input type='radio' name='update5' value='MST'> MST</td><td><input type='radio' name='update5' value='PST'> PST</td></tr> <tr><td colspan='5'><input type='submit' name='updateddata' value='Update data'></td><tr>"; if(isset($_POST['updateddata'])) { $updateFirst = $_POST['update1']; $updateLast = $_POST['update2']; $updateCity = $_POST['update3']; $updateState = $_POST['update4']; $updateTime = $_POST['update5']; $updated = "UPDATE `sampleDB` SET `FirstName`='$updateFirst', `LastName`='$updateLast', `City`='$updateCity', `State`='$updateState', `TimeZone`='$updateTime' WHERE `ID` = '$edit';"; $up_date = mysqli_query($GaryDB, $update); if(isset($up_date)) { header('location: sampleDB.php'); } else { $updated2 = "Could not updated data"; } } } } Anyone can help will be very appreciate Thanks, Gary Link to comment Share on other sites More sharing options...
niche Posted November 21, 2019 Share Posted November 21, 2019 Where's it breaking and what error messages are you getting? Link to comment Share on other sites More sharing options...
Sigmahokies Posted November 21, 2019 Author Share Posted November 21, 2019 No error is showing, all syntax are corrected. Only I see that data has not change when I entered the update a data in the database. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 21, 2019 Share Posted November 21, 2019 $updated = "UPDATE `sampleDB` SET `FirstName`='$updateFirst', `LastName`='$updateLast', `City`='$updateCity', `State`='$updateState', `TimeZone`='$updateTime' WHERE `ID` = '$edit';"; $up_date = mysqli_query($GaryDB, $update); See the difference, it still picking up the select statement variable. Link to comment Share on other sites More sharing options...
Sigmahokies Posted November 22, 2019 Author Share Posted November 22, 2019 Oh, I missed that part, I just changed that $updated from $update. Seem it doesn't work with update in database, it's result same. It haven't update...I think something is missing, I tried to use PHP tester, test showed it's fine. Very odd. Link to comment Share on other sites More sharing options...
Sigmahokies Posted November 22, 2019 Author Share Posted November 22, 2019 Never mind everyone, I found to make it work...I remove "action='[file]'" from HTML form. Thank you for effort Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now