TheEddy Posted August 1, 2010 Share Posted August 1, 2010 <?php if(!isset($_SESSION)) { session_start(); } // UNCOMMENT NEXT LINE TO PRINT THE $_SESSION ARRAY TO THE SCREEN . . . // echo '<pre>'; print_r($_SESSION); echo '</PRE>'; if(empty($_SESSION['userID']) || $_SESSION['authorized'] != true ) { header("Location: login.php"); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/xml; charset=utf-8" /> <meta http-equiv="refresh" content="5;url=editprofile.php"> <title>Saving Profile</title> </head> <body> <?php require_once ("dbconn.php"); ?> <?php $userID = $_SESSION['userID']; $insert_query = 'insert into users WHERE userID='$userID'( aim, msn, yim, psnID, xblGamertag, otherContact ) values ( "' . $_POST['aim'] . '", "' . $_POST['msn'] . '", "' . $_POST['yim'] . '", "' . $_POST['psnID'] . '", "' . $_POST['xblGamertag'] . '", "' . $_POST['otherContact'] . '" )'; mysql_query($insert_query); ?> Your profile has been saved! You will now be redirected from where you came from. <br /><a href="editprofile.php" title="Click here if you don't want to wait">Click here if you don't want to wait.</a> </body> </html> It creates a new record but I want it to update an existing one. It's an editprofile script. Link to comment https://forums.phpfreaks.com/topic/209474-insert-into-existing-record/ Share on other sites More sharing options...
joel24 Posted August 1, 2010 Share Posted August 1, 2010 you need to use an update query instead of insert. Link to comment https://forums.phpfreaks.com/topic/209474-insert-into-existing-record/#findComment-1093738 Share on other sites More sharing options...
TheEddy Posted August 1, 2010 Author Share Posted August 1, 2010 you need to use an update query instead of insert. <?php require_once ("dbconn.php"); ?> <?php $userID = $_SESSION['userID']; $insert_query = 'UPDATE users SET aim="' . $_POST['aim'] . '", msn="' . $_POST['msn'] . '", yim="' . $_POST['yim'] . '", psnID="' . $_POST['psnID'] . '", xblGamertag="' . $_POST['xblGamertag'] . '", otherContact="' . $_POST['otherContact'] . '", WHERE userID = $userID;' mysql_query($insert_query); ?> It says I did something wrong but I can't find it Link to comment https://forums.phpfreaks.com/topic/209474-insert-into-existing-record/#findComment-1093903 Share on other sites More sharing options...
litebearer Posted August 1, 2010 Share Posted August 1, 2010 perhaps try... $aim=$_POST['aim']; $msn = $_POST['msn']; $yim = $_POST['yim']; $psnID =$_POST['psnID']; $xblGamertag = $_POST['xblGamertag']; $otherContact= $_POST['otherContact']; $insert_query = "UPDATE users SET aim='$aim, msn='$msn', yim='$yim', psnID='$psnID', xblGamertag='$xblGamertag', otherContact= '$otherContact' WHERE userID = '$userID'"; Link to comment https://forums.phpfreaks.com/topic/209474-insert-into-existing-record/#findComment-1093905 Share on other sites More sharing options...
joel24 Posted August 2, 2010 Share Posted August 2, 2010 try implement mysql_error() so you can see the error message if the query isn't functioning. Don't use or die() when the site is live for production, there are much nicer error reporting methods. i.e. <?php require_once ("dbconn.php"); ?> <?php $userID = $_SESSION['userID']; $insert_query = 'UPDATE users SET aim="' . $_POST['aim'] . '", msn="' . $_POST['msn'] . '", yim="' . $_POST['yim'] . '", psnID="' . $_POST['psnID'] . '", xblGamertag="' . $_POST['xblGamertag'] . '", otherContact="' . $_POST['otherContact'] . '", WHERE userID = $userID;' mysql_query($insert_query) or die(mysql_error()); ?> It says I did something wrong but I can't find it What does it say? Link to comment https://forums.phpfreaks.com/topic/209474-insert-into-existing-record/#findComment-1094019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.