andy_b_1502 Posted May 28, 2012 Share Posted May 28, 2012 Hi all, Trying to get my coding to work, so that users may edit or update there user profiles, whats the best way to go about this. Here's what i have as the form: <form action="view02.php" method="post" enctype="multipart/form-data" class="cursive"> <table width="316" border="0"> <tr> <td colspan=2><h1>Edit Your details </h1> <p>fill out the form with your details...</p></td> </tr> <tr> <td> </td> <td><p> </p> <p>Click update to edit...</p> <p> </p></td> </tr> <tr> <td> </td> <td><p> </p> <p> </p> <p> <p> </p></td> </tr> <tr> <td>Website:</td> <td><p> </p> <p> <input name="website" type="text" id="website" value="optional" /> </p> <p><a href="view02.php?id=<?PHP echo $row['id']; ?>&website=$website">Update</a></p> <p> </p></td> </tr> <tr> <td>Primary Number:</td> <td><p> </p> <p> <input name="phone" type="text" id="phone" value="incl. area code" /> </p> <p><a href="view02.php?id=<?PHP echo $row['id']; ?>&number1="incl. area code">Update</a></p> <p> </p></td> </tr> <tr> <td>Secondary Number:</td> <td><p> </p> <p> <input name="phone2" type="text" id="phone2" value="optional" /> </p> <p><a href="view02.php?id=<?PHP echo $row['id']; ?>&number2=1">Update</a></p> <p> </p></td> </tr> <tr> <td>Company Description:</td> <td><p><em>Write a description of what your company does, the services it offers and any additional information here.</em> </p> <p> <textarea rows="10" cols="100" name="premiumuser_description" id="premiumuser_description"></textarea> </p> <p><a href="view02.php?id=<?PHP echo $row['id']; ?>&description=1">Update</a> </p></td> </tr> <tr> <td> </td> </tr> <tr></tr> </table> </form> And the coding "view02.php": <?PHP session_start(); include ('php only scripts/db.php'); $id = (int) $_GET['id']; $website = (int) $_GET['website']; $phone = (int) $_GET['number1']; $phone2 = (int) $_GET['number2']; $premiumuser_decription = (int) $_GET['description']; $query = "UPDATE companies SET website = '$website', phone = '$phone', phone2 = '$phone2', premiumuser_description = '$premiumuser_decription' WHERE id = '$id'"; $result = mysql_query($query ) or die("SELECT Error: ".mysql_error()); header("url=view01.php?id=" . $row['id']); exit(); ?> How do i get it to update properly? Thanks Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/ Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 i'm trying to get the values to update on each section or field by clicking the "update" buttons. At the moment it updates with the number 0 for everything i update lol? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349230 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 Because you are casting each value as an integer using (int). Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349231 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 Thanks, ive changed it now to: <?PHP session_start(); include ('php only scripts/db.php'); $id = $_GET['id']; $website = $_GET['website']; $phone = $_GET['number1']; $phone2 = $_GET['number2']; $premiumuser_decription = $_GET['description']; $query = "UPDATE companies SET website = '$website', phone = '$phone', phone2 = '$phone2', premiumuser_description = '$premiumuser_decription' WHERE id = '$id'"; $result = mysql_query($query ) or die("SELECT Error: ".mysql_error()); header("url=view01.php?id=" . $row['id']); exit(); ?> but something weird happened, i get this error message: The server encountered an unexpected condition which prevented it from fulfilling the request. The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log. Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349235 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 If there was an error, you should be able to see it in the error log Is there anything in your error_log? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349236 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 i was just looking for that? where do i find it? Also iv'e noticed that the details (i changed the user's website) has been updated to: $website, so thats also incorrect Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349237 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 i was just looking for that? where do i find it? Check the directory in which the error occurred. Also iv'e noticed that the details (i changed the user's website) has been updated to: $website, so thats also incorrect Come again? I don't know what you're referring to. Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349239 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 well $website was in the code i uploaded... i was saying that it's actually uploading $website from this line of code: $website = $_GET['website']; $query = "UPDATE companies SET website = '$website' My question is, how do i get it to upload what the user inputs into the field, NOT $website and so on for the other fields. Ill look for the error log now, thanks Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349242 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 You are using POST as the method in your <form> block. And then using $_GET to retrieve said values in your PHP. Either switch the form method to GET or change your $_GET's to $_POST's. I recommend the latter. Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349247 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 Okay, i changed the forms method to GET but i'm still getting the same error: The server encountered an unexpected condition which prevented it from fulfilling the request. The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log. Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349251 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 That error could be anything. The error is basically telling you to locate the applicable error log for more specific details. Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349255 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 i have located the error log, it's in my host's cpanel..... unfortunately the error log is empty? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349256 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 does that suggest there isn't any output if the log is empty? if why is this happening? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349259 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 Is this error sporadic? You made it sound like it happened when I told you to remove (int) from your code (which would not generate an Internal Server error). To expedite a fix, I would send that message to your hosting provider and have them look into their logs. Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349262 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 I'm not sure what's causing this, thats why i was asking to see if you or anybody else knew? I already have done what you said, contacted my host; they said it was a scripting issue and told me to debug it from my side (not that helpful lol) Being as you said about the (int) do you reckon i should change anything add/take away from that area or area's? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349263 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 Change this line: header("url=view01.php?id=" . $row['id']); to header("Location: view01.php?id=" . $row['id']); exit(0); Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349264 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 and omit exit(); also? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349265 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 okay so it reads like this: header("Location: view01.php?id=" . $row['id']); exit(0);; exit(); it's currently NOT giving me the error message, but is logging out, and not going back to the same page... nor it updating the details of that user Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349266 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 sorry. i meant the previous page, when the update occurs, it should go back to view01.php?=id Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349267 Share on other sites More sharing options...
wigwambam Posted May 28, 2012 Share Posted May 28, 2012 Try commenting out this line: header("Location: view01.php?id=" . $row['id']); Just after it, put: echo $query; Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349268 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 Thanks, i commented out the section: /* header("Location: view01.php?id=" . $row['id']); */ echo $query; exit(0);; exit(); ?> this is what i'm getting now: UPDATE companies SET website = '$website', phone = '', phone2 = '', premiumuser_description = '' WHERE id = '51' Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349269 Share on other sites More sharing options...
wigwambam Posted May 28, 2012 Share Posted May 28, 2012 What happens if you cut/paste that SQL into phpMyAdmin? Does it work? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349270 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 Thanks, i commented out the section: /* header("Location: view01.php?id=" . $row['id']); */ echo $query; exit(0);; exit(); ?> this is what i'm getting now: UPDATE companies SET website = '$website', phone = '', phone2 = '', premiumuser_description = '' WHERE id = '51' $website is being printed to the screen in variable form? Can you post your current code, please? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349272 Share on other sites More sharing options...
andy_b_1502 Posted May 28, 2012 Author Share Posted May 28, 2012 <?PHP session_start(); include ('php only scripts/db.php'); $id = $_GET['id']; $website = $_GET['website']; $phone = $_GET['number1']; $phone2 = $_GET['number2']; $premiumuser_decription = $_GET['description']; $query = "UPDATE companies SET website = '$website', phone = '$phone', phone2 = '$phone2', premiumuser_description = '$premiumuser_decription' WHERE id = '$id'"; $result = mysql_query($query ) or die("SELECT Error: ".mysql_error()); /* header("Location: view01.php?id=" . $row['id']); */ echo $query; exit(0);; exit(); ?> Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349273 Share on other sites More sharing options...
mrMarcus Posted May 28, 2012 Share Posted May 28, 2012 Not sure how you managed to get exit(0);; exit(); from the code I gave you. Simply put: exit(0); However, that is not the problem. Can you post your latest form. And... $website is being printed to the screen in variable form? Meaning, you literally see '$website' on the screen when you echo $query? Link to comment https://forums.phpfreaks.com/topic/263272-updateedit/#findComment-1349275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.