danposs86 Posted April 20, 2007 Share Posted April 20, 2007 What i want to do is set a row from a mysql table as "$update" so i can use it later on in the page.Just doesnt seem to be working. <?php $sql = "SELECT name FROM ibf_members WHERE id='$member_id'"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "Edited by: ".$row['name']." "; $update = $row['name']; }?> Any ideas? Link to comment Share on other sites More sharing options...
msd Posted April 20, 2007 Share Posted April 20, 2007 <?php $sql = "SELECT name FROM ibf_members WHERE id='".$member_id."'"; $query = mysql_query($sql); $row = mysql_fetch_assoc($query); echo "Edited by: ".$row["name"]; $update = $row["name"];?> First, because you need a name only from one row, you don't need a while.Try the code above. Link to comment Share on other sites More sharing options...
danposs86 Posted April 20, 2007 Author Share Posted April 20, 2007 have put that code in but it doesn't work how i want. Heres the rest of the code: <?phpif (!isset($_POST['submit'])) {?><table><tr><form action="" method="post"><td align="right" width="150">Edited by:</td><td align="left"><?php $sql = "SELECT name FROM ibf_members WHERE id='".$member_id."'"; $query = mysql_query($sql); $row = mysql_fetch_assoc($query); echo $row["name"]; $update = $row["name"];?></td></tr><?php $sql = "SELECT * FROM site_news WHERE news_ID = '$_GET[refer]'"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<tr><td align='right'>Title:</td><td align='left'><input type='text' name='title' size='40' value='".$row['news_title']."'></td></tr>"; echo "<tr><td align='right'>News:</td><td align='left'><textarea type='text' name='news' cols='40' rows='5'>".$row['news_post']."</textarea></td></tr>"; }?><tr><td colspan="2"><input type="submit" name="submit" value="Edit News"></td></tr></form><?php} else {$news_date = date("d-m-Y");mysql_query("UPDATE site_news SET news_updatename = '$update', news_updatedate = '$news_date', news_title = '$_POST[title]', news_post = '$_POST[news]' WHERE news_ID = '$_GET[refer]'");echo "<td>Success! The news has been edited! <a href='admin.php'>Back to Admin Panel</a></td>";}?></tr></table> Ignore the crappy mess its in.towards the bottom you can see i am wanting to put '$update' into the table. It's not working though. Link to comment Share on other sites More sharing options...
msd Posted April 20, 2007 Share Posted April 20, 2007 But where do you get "$member_id" from? I don't see you getting it by GET or POST. Link to comment Share on other sites More sharing options...
danposs86 Posted April 20, 2007 Author Share Posted April 20, 2007 ohh sorry, theres some php at the very top of the page. It is using the member_id to get the username, and it is displaying the username correctly.It's just getting it to save the username in the table. Do you need to see that php?EDIT: it's taken from a session used for a user login in. Link to comment Share on other sites More sharing options...
msd Posted April 20, 2007 Share Posted April 20, 2007 Post all the php code that has influence on this problem. Link to comment Share on other sites More sharing options...
danposs86 Posted April 20, 2007 Author Share Posted April 20, 2007 It's a cookie actually lol <?php$member_id = $_COOKIE['member_id'];$pass_hash = $_COOKIE['pass_hash'];$thequery = mysql_query("SELECT m.id AS id, m.member_login_key AS password, m.name AS name, m.email AS email, m.mgroup AS mgroup, m.new_msg AS new_msg, m.show_popup AS show_popup, g.g_id AS g_id, g.g_access_cp AS g_access_cp FROM ibf_members m LEFT JOIN ibf_groups g ON ( g.g_id = m.mgroup) WHERE id='$member_id' AND member_login_key= '$pass_hash'") or die(mysql_error());$member = mysql_fetch_array($thequery);?> Link to comment Share on other sites More sharing options...
msd Posted April 20, 2007 Share Posted April 20, 2007 So, is the username extracted ok from the database?But it just won't update the other table?And are you sure that $_GET["refer"] exists in the "site_news" table? Link to comment Share on other sites More sharing options...
danposs86 Posted April 20, 2007 Author Share Posted April 20, 2007 yeah it is showing the username and all the information correctly. It is inputing the date and any changes into the table correctly, just not the name of the user that has done the edit.The $_GET["refer"] is used in the hyperlink that takes it to the page, so it isnt in the table. Link to comment Share on other sites More sharing options...
msd Posted April 20, 2007 Share Posted April 20, 2007 yeah it is showing the username and all the information correctly. It is inputing the date and any changes into the table correctly, just not the name of the user that has done the edit. Weird. Double check table fields in database and your query.The $_GET["refer"] is used in the hyperlink that takes it to the page, so it isnt in the table.You didn't understand my question, but it doesn't matter. Link to comment Share on other sites More sharing options...
danposs86 Posted April 20, 2007 Author Share Posted April 20, 2007 sorted it, by shoving this in: <?php} else { $sql = "SELECT name FROM ibf_members WHERE id='".$member_id."'"; $query = mysql_query($sql); $row = mysql_fetch_assoc($query); $update = $row["name"]; $news_date = date("d-m-Y");mysql_query("UPDATE site_news SET news_updatename = '$update', news_updatedate = '$news_date', news_title = '$_POST[title]', news_post = '$_POST[news]' WHERE news_ID = '$_GET[refer]'");echo "<td>Success! The news has been edited! <a href='admin.php'>Back to Admin Panel</a></td>";}?> it may not be pretty but it works lol Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now