daveoffy Posted December 6, 2008 Share Posted December 6, 2008 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"); } Quote Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/ Share on other sites More sharing options...
gevans Posted December 6, 2008 Share Posted December 6, 2008 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/#findComment-707700 Share on other sites More sharing options...
daveoffy Posted December 6, 2008 Author Share Posted December 6, 2008 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/#findComment-707717 Share on other sites More sharing options...
gevans Posted December 6, 2008 Share Posted December 6, 2008 sorry it should be mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/#findComment-707725 Share on other sites More sharing options...
daveoffy Posted December 6, 2008 Author Share Posted December 6, 2008 Wow, I didn't even notice that. Quote Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/#findComment-707732 Share on other sites More sharing options...
gevans Posted December 6, 2008 Share Posted December 6, 2008 Hows it running now? Quote Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/#findComment-707740 Share on other sites More sharing options...
daveoffy Posted December 6, 2008 Author Share Posted December 6, 2008 wonderful. Thank you so much. Quote Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/#findComment-707778 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.