Jump to content

Recommended Posts

I have it so users can update their profile. If they have already created the row in the table I want it to update, if it didn't create a row in a table yet (never updated profile) i want it to CREATE.

 

Need to add code above this and into this...

$qry = "INSERT INTO profile(member_id, music, books, activities, interests, quotes, about_me) VALUES('$member_id', '$music', '$books', '$activities', '$interests', '$quote', '$about_me');";
$result = @mysql_query($qry);
if($result) {
	header("location: profile-success.php");
	exit();
}else {
	die("Query failed");
}

 

Link to comment
https://forums.phpfreaks.com/topic/135799-solved-create-else-update/
Share on other sites

<?php
$query = "SELECT member_id FROM profile WHERE member_id='$member_id'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if($num_results){
  $query = "UPDATE profile SET music='$music', books=$books", activities='$activities', interests='$interests', quotes='$quote', about_me='$about_me' WHERE member_id='$member_id'";
  $result = mysql($query);
  if($result){
    header('Location: profile-success.php');
    exit();
  } else {
    die('Query Failed');
  }
} else {
  $query = "INSERT INTO profile (member_id, music, books, activities, interests, quotes, about_me) VALUES('$member_id', '$music', '$books', '$activities', '$interests', '$quote', '$about_me')";
  $result = mysql_query($query);
  if($result){
    header('Location: profile-success.php');
    exit();
  } else {
    die('Query Failed');
  }
}
?>

 

see if that works for you

Warning: Wrong parameter count for mysql() on line 33

Query Failed

 

Line 33:

  $result = mysql($query);

 

Code around it:

$query = "SELECT member_id FROM profile WHERE member_id='$member_id'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if($num_results){
  $query = "UPDATE profile SET music='$music', books='$books', activities='$activities', interests='$interests', quotes='$quote', about_me='$about_me' WHERE member_id='$member_id'";
  $result = mysql($query);
  if($result){
    header('Location: profile-success.php');
    exit();
  }

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.