Jump to content

Insert into existing record


TheEddy

Recommended Posts

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.