Foser Posted July 7, 2007 Share Posted July 7, 2007 $userdata = mysql_fetch_assoc(mysql_query("SELECT * FROM user_info WHERE username = '$username'")); if (isset($_POST['submit'])){ mysql_query("UPDATE user_info SET username = '$_POST[username]', email = '$_POST[email]', project = '$_POST[project]', active = '$_POST[status]', admin rights = '$_POST[rights]' WHERE username = '$_GET[user]'"); echo "Your Information has been successfully updated."; } for some reason my information does not updatre correcly. am i doing something wrong? Quote Link to comment Share on other sites More sharing options...
Leppy Posted July 7, 2007 Share Posted July 7, 2007 Try this to see if there is any error in your query: $userdata = mysql_fetch_assoc(mysql_query("SELECT * FROM user_info WHERE username = '$username'")); if (isset($_POST['submit'])){ if(!mysql_query("UPDATE user_info SET username = '$_POST[username]', email = '$_POST[email]', project = '$_POST[project]', active = '$_POST[status]', admin rights = '$_POST[rights]' WHERE username = '$_GET[user]'")){ echo 'something is wrong: '.mysql_error(); } else { echo "Your Information has been successfully updated."; }} But what I suspect is there is no affected rows so there is something not right with your query. Are you sure the row you are trying to update exist? Quote Link to comment Share on other sites More sharing options...
Foser Posted July 7, 2007 Author Share Posted July 7, 2007 <?php include('../../config.php'); session_start(); // Authentication if ($_SESSION['LOGGEDIN'] !== TRUE){ echo "You are not logged in. Click <a href=\"../../index.php\">here</a> to login."; exit;} $result = mysql_num_rows(mysql_query("SELECT admin_rights FROM user_info WHERE username = '$_SESSION[uNAME]'")); if ($result != TRUE){ echo "You are not authorized to view the selected page."; exit;} $username = $_GET['user']; // Prevent unwanted input $query = mysql_query("SELECT * FROM user_info WHERE username = '$username'"); if (mysql_num_rows($query) == 0) { echo "You have inputed incorect data"; exit; } $userdata = mysql_fetch_assoc(mysql_query("SELECT * FROM user_info WHERE username = '$username'")); if (isset($_POST['submit'])){ mysql_query("UPDATE user_info SET username = '$_POST[username]', email = '$_POST[email]', project_name = '$_POST[project]', active = '$_POST[status]', admin rights = '$_POST[rights]' WHERE username = '$_GET[user]'"); echo "Your Information has been successfully updated."; } ?> <form id="form1" name="form1" method="post" action=""> User Updating System <table width="233" border="0"> <tr> <th width="91" scope="col"><div align="left">Username:</div></th> <th width="144" scope="col"><label> <input name="username" type="text" id="username" value="<?php echo $_GET['user']; ?> " /> </label></th> </tr> <tr> <th scope="col"><div align="left">E-mail:</div></th> <th scope="col"><label> <input name="email" type="text" id="email" value="<?php echo $userdata['email']; ?>" /> </label></th> </tr> <tr> <th scope="col"><div align="left">Project</div></th> <th scope="col"><label></label> <div align="left"> <label></label> <div align="center"> <?php echo("<select name=\"project\">"); $query = mysql_query("SELECT names FROM projects"); while(mysql_fetch_assoc($query)){ echo "<option value='{$query['name']}'>{$query['name']}</option>"; } echo "</select>"; ?> </div> </div></th> </tr> <tr> <th scope="col"><div align="left">Status:</div></th> <th scope="col"><?php if ($userdata['active'] == TRUE){ echo "<select name='status' id='status'> <option value='TRUE' selected='selected'>active</option> <option value='FALSE'>unactive</option> </select>";} if($userdata['active'] == FALSE){ echo "<select name='status' id='status'><option value='TRUE'>active</option> <option value='FALSE' selected='selected'>unactive</option>";} ?></th> </tr> <tr> <th scope="col"><div align="left">Rights</div></th> <th scope="col"><p> <label></label> <label><?php if ($userdata['admin_rights'] == TRUE){ echo "<select name='rights' id='rights'> <option value='TRUE' selected='selected'>admin</option> <option value='FALSE'>user</option> </select>";} if($userdata['admin_rights'] == FALSE){ echo "<select name='rights' id='rights'><option value='TRUE'>admin</option> <option value='FALSE' selected='selected'>user</option>";} ?></label> <br /> </p> <label></label></th> </tr> </table> <label> <input type="submit" name="submit" id="submit" value="Update" /> </label> <label></label> <label></label> </form> heres my entire script all fields choosen in the databsae are real and made sure they were spelled properly Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 7, 2007 Share Posted July 7, 2007 Did you do Leppy's suggestion? Change this line: mysql_query("UPDATE user_info SET username = '$_POST[username]', email = '$_POST[email]', project_name = '$_POST[project]', active = '$_POST[status]', admin rights = '$_POST[rights]' WHERE username = '$_GET[user]'"); To: mysql_query("UPDATE user_info SET username = '$_POST[username]', email = '$_POST[email]', project_name = '$_POST[project]', active = '$_POST[status]', admin rights = '$_POST[rights]' WHERE username = '$_GET[user]'")or die(mysql_error()); If there is an error, that will tell you what it is. 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.