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"); } 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 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(); } 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); 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. 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? 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. Link to comment https://forums.phpfreaks.com/topic/135799-solved-create-else-update/#findComment-707778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.