Spartan 117 Posted February 27, 2007 Share Posted February 27, 2007 Hello, I am having trouble updating a table in mySQL. I am trying to make a page where members can update a profile. Here is my code: <?php include('../config.php'); $ssi_ban = true; ob_start(); include("SSI.php"); ?> <table width="449" border="0" cellpadding="0" cellspacing="0" style="text-align: left; width: 428px;"> <tbody> <tr> <td width="449" style="width: 215px;"><table width="449" height="24" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="10" height="24" align="left" valign="top"> </td> <td width="439" align="left" valign="middle"><div align="left"> <table width="423" height="184" border="1" cellpadding="1" cellspacing="1"> <tr> <td width="149" align="left" valign="middle"><strong>Member Name:</strong></td> <td width="274"> <?php // connect to database here // connect to the mysql server $link = mysql_connect($server, $db_user2, $db_pass2) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database2) or die ("Could not select database because ".mysql_error()); $id = $context['user']['id']; $sql = "SELECT * FROM smf_members WHERE ID_MEMBER = '$id'"; $res = mysql_query($sql) or die (mysql_error()); $r = mysql_fetch_assoc($res); $check = mysql_num_rows($res); // check to make sure your id exists if($check > 0){ // convert all fields to strip slashes and line breaks to <br> $myname = nl2br(stripslashes($r['MemberClanName'])); $myrank = nl2br(stripslashes($r['memberrank'])); $myrealname = nl2br(stripslashes($r['memberrn'])); $mylocation = nl2br(stripslashes($r['location'])); $myxfire = nl2br(stripslashes($r['xfire'])); $mypicture = nl2br(stripslashes($r['memberpic'])); $aboutme = nl2br(stripslashes($r['memberabout'])); ?> <input name="myname" type="text" id="myname" value="<?=$myname ?>"> </td> </tr> <tr> <td height="28" align="left" valign="middle"><strong>Member Rank: </strong></td> <td> <input name="myrank" type="text" id="myrank" value="<?=$myrank ?>"> </td> </tr> <tr> <td align="left" valign="middle"><strong>Real Name </strong></td> <td> <input name="myrn" type="text" id="myrn" value="<?=$myrealname ?>"> </td> </tr> <tr> <td align="left" valign="middle"><strong>Location:</strong></td> <td> <input name="myloc" type="text" id="myloc" value="<?=$mylocation ?>"> </td> </tr> <tr> <td align="left" valign="middle"><strong>Xfire:</strong></td> <td align="left" valign="middle"><input name="myxfire" type="text" id="myxfire" value="<?=$myxfire ?>"></td> </tr> <tr> <td colspan="2" align="left" valign="middle"><hr></td> </tr> <tr> <td colspan="2" align="left" valign="middle"><strong>Member Picture: </strong></td> </tr> <tr> <td colspan="2" align="left" valign="middle"><textarea name="mypic" cols="35" rows="2" id="mypic"><?=$mypicture ?> </textarea></td> </tr> <tr> <td colspan="2" align="left" valign="middle"><hr></td> </tr> <tr> <td colspan="2" align="left" valign="middle"><strong>A Little About <?=$myname ?> </strong></td> </tr> <tr> <td colspan="2" align="left" valign="middle"><textarea name="myabout" cols="35" rows="5" id="myabout"><?=$aboutme ?> </textarea> <?php } else { // show this if ID does not exist echo "<p align=center><font color=\"FFFFFF\"><b>Member Not Found!<b></font></p>"; ?> <?php } ?> </td> </tr> <tr> <td colspan="2" align="left" valign="middle"><hr></td> </tr> <tr align="right"> <td colspan="2" valign="middle"><input name="submit" type="submit" id="submit" value="Save Changes"></td></tr> </table> </div></td> </tr> </table> </td> </tr> </tbody> </table> </form> <?php if ($_POST['submit']) { $myname = $_POST['myname']; $myrank = $_POST['myrank']; $myrn = $_POST['myrn']; $myloc = $_POST['myloc']; $myxfire = $_POST['myxfire']; $mypic = $_POST['mypic']; $myabout = $_POST['myabout']; $sql = "UPDATE smf_members SET MemberClanName='$myname',memberrank='$myrank',memberrn='$myrn',location='$memberloc',xfire='$myxfire',memberpic='$mypic',memberabout='$myabout' WHERE id=$id"; //replace link with your table name above $result = mysql_query($sql); echo "Member Info Updated!"; } ?> The problem is that this does not work. I edit stuff then it echos the Member Info Updated message, but it changes nothing at all. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/40353-solved-php-editing-mysql-problems/ Share on other sites More sharing options...
Spartan 117 Posted February 27, 2007 Author Share Posted February 27, 2007 Wow. Nevermind. I was trying to edit from id. id doesn't exist. In SMF they made it ID_MEMBER. I am embarrassed... Sorry Link to comment https://forums.phpfreaks.com/topic/40353-solved-php-editing-mysql-problems/#findComment-195247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.