Jump to content

quick question


danposs86

Recommended Posts

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

<?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

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

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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...