Jump to content

Recommended Posts

ok, i have a table that displays on a page. the table consists of mysql entries from a user. here is the code for the table that is displayed

<?php
echo "<tr><td align='center'>";
			       echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';
			       echo "</td><td align='center'>";
			       echo $row['pc_name'];
			       echo "</td><td align='center'>";
			       echo $row['description'];
			       echo "</td><td align='center'>";
			       echo $row['in_return'];
			       echo "</td><td align='center'>";
		           echo "<a href=composemessage.php><img src=\"images/K_little.png\" border='0'></a>";
				   echo "</td></tr>";
?>

by clicking on the k_little.png it takes you to a screen where you can send a private message to another user. What I'm trying to do is when you click on that k_little picture, i would like it to get the username of the person that you are sending the message to and save it as a $_SESSION variable, so then when your taken to the compose message page of the messaging system, it will already have the username filled in that your sending to message to. Now the mysql table that has the info that is displayed in table format above also has a field in it called user_id, which of course is the same id that I have in another table called members. So how would I go about getting that username????.... I know it will be some sort of query,, but I'm not sure how to write it out? Understand???Basically all the rows that are echoed in the table are assoiciated with different users. Just want to get the username from that row.

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/
Share on other sites

when the table is display it looks like this,,, more than 1 user info in a table

 

user1pic      description    address    k_little.png

user2pic      description    address    k_little.png

user3pic      description    address    k_little.png

 

by clicking the k_little.png i want the username to appear in the to box of the compose message page.

the table that holds the info above has a user_id field that holds a number that matches with another table that has the id of that user, which has the username.  understand now? sorry for the confusion. each k_little.png will retrieve the username of the user that uploaded the userpic.

 

 

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-812831
Share on other sites

Frankly, I see no reason to save it to a session. Just do as Maq suggested and use the GET method.

 

Page with list of users:

<?php
echo "<tr><td align='center'>";
echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';
echo "</td><td align='center'>";
echo $row['pc_name'];
echo "</td><td align='center'>";
echo $row['description'];
echo "</td><td align='center'>";
echo $row['in_return'];
echo "</td><td align='center'>";
echo '<a href="composemessage.php?uid='.$row['user_id'].'"><img src="images/K_little.png" style="border: 0px;" /></a>';
echo "</td></tr>";
?>

 

composemessage.php --> (replace table_name with the appropriate value)

<?php
$uid = $_GET['uid'];

$query = "SELECT username FROM table_name WHERE user_id = '$uid'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);

echo '<form>';
// form here ...
echo '<input type="text" name="to" value="'.$user['username'].'" />';
// ... rest of form here
echo '</form>';
?>

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-812862
Share on other sites

this gives an error in the line below

<?php
	include "connection.php";
	mysql_connect("$host", "$username", "$password") or die("Could not connect.");
    mysql_select_db("$db_name") or die("Could not find database");
	$query = "SELECT username FROM members WHERE user_id = '$uid'";
	$result = mysql_query($query);
	$user = mysql_fetch_array($result);    //error here
	echo '<form>';
	echo '<input type="text" name="to" value="'.$user['username'].'" />';
	echo '</form>';
	?>

so i did this and the text box appears but it is empty,, no username

<?php
	include "connection.php";
	mysql_connect("$host", "$username", "$password") or die("Could not connect.");
    mysql_select_db("$db_name") or die("Could not find database");
	$query = "SELECT username FROM members WHERE user_id = '$uid'";
	$result = mysql_query($query);
	//$user = mysql_fetch_array($result);    //commented this line out just for fun
	echo '<form>';
	echo '<input type="text" name="to" value="'.$user['username'].'" />';
	echo '</form>';
	?>
any ideas why the username isn't showing up?

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-812894
Share on other sites

You're never getting the user_id from the previous page.  Try this (*comments in code*):

 

      mysql_select_db("$db_name") or die("Could not find database");
      $uid = $_GET['uid'];  // Added to get the id from the URL
      $query = "SELECT username FROM members WHERE user_id = '$uid'";
      $result = mysql_query($query) or die(mysql_error()); // Added or die for debugging

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-812903
Share on other sites

i find it good practice to write a query like so when using variables:

$query = "SELECT username FROM members WHERE user_id = '".$uid."'";

 

try doing this:

 

mysql_select_db("$db_name") or die("Could not find database");
      $uid = $_GET['uid'];  // Added to get the id from the URL
      $query = "SELECT username FROM members WHERE user_id = '".$uid."'";
      echo $query; // see what the query looks like
      exit; //stop script
      $result = mysql_query($query) or die(mysql_error()); // Added or die for debugging

 

you should always learn to echo back a query if it is not working correctly...sometime you find that the $uid variable isn't gettting inserted into the query properly.

 

let us know what you find.

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-812980
Share on other sites

starting to get a little confused on why this is so difficult.... see anything wrong....

<?php
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT imgpath, item_name, description, in_return FROM member_trades WHERE category = 'Video Games' $limit";
$uid = $_GET['user_id'];
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
			       
echo "<table border='1' bgcolor='#FFFFFF'><tr><td bgcolor='#B8D2EO'><H3>Image</h3></td><td bgcolor='#B8D2EO'><H3>Item&nbspName</H3></td><td bgcolor='#B8D2EO'><H3>Description</H3></td><td bgcolor='#B8D2EO'><H3>Seeking</H3></td><td bgcolor='#B8D2EO'><H3>		                             Contact&nbspUser</H3></td></tr>";
                       while ($row = mysql_fetch_array($result))
		           {
            	       echo "<tr><td align='center'>";
			       echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';
			       echo "</td><td align='center'>";
			       echo $row['item_name'];
			       echo "</td><td align='center'>";
			       echo $row['description'];
			       echo "</td><td align='center'>";
			       echo $row['in_return'];
			       echo "</td><td align='center'>";
		           echo '<a href="composemessage.php?uid='.$row['user_id'].'"><img src="images/K_little.png" style="border: 0px;" /></a>';

				   echo "</td></tr>";
				   }
?>

<?php
	include "connection.php";
	mysql_connect("$host", "$username", "$password") or die("Could not connect.");
    mysql_select_db("$db_name") or die("Could not find database");
        $uid = $_GET['uid'];  // Added to get the id from the URL
        $query = "SELECT username FROM members WHERE user_id = '".$uid."'";
        echo $query; // see what the query looks like
        exit; //stop script
        $result = mysql_query($query) or die(mysql_error()); // Added or die for debugging
	$user = mysql_fetch_array($result);    
	echo '<form>';
	echo '<input type="text" name="to" value="'.$uid['username'].'" />';
	echo '</form>';
	?>

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-814059
Share on other sites

You took the exit; out, right?  When you echo out the sql statement does it look correct?  Are you still getting the "column not found" error?  If so, go to your database and ensure it's exactly the same.

 

Also, when you call the extracted you're using $uid rather than $user.

 

      $user = mysql_fetch_array($result);    
      echo '</pre>
<form>';
      echo '';<

 

needs to be:

 

      $user = mysql_fetch_array($result);    
      echo '</pre>
<form>';
      echo '';  // CHANGED<

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-814062
Share on other sites

i do not think that the GET command is working,,

<?php
$query = "SELECT imgpath, item_name, description, in_return FROM member_trades WHERE category = 'Video Games' $limit";
$uid = $_GET['user_id'];
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
echo "<table border='1' bgcolor='#FFFFFF'><tr><td bgcolor='#B8D2EO'><H3>Image</h3></td><td bgcolor='#B8D2EO'><H3>Item&nbspName</H3></td><td bgcolor='#B8D2EO'><H3>Description</H3></td><td bgcolor='#B8D2EO'><H3>Seeking</H3></td><td bgcolor='#B8D2EO'><H3>		                             Contact&nbspUser</H3></td></tr>";
while ($row = mysql_fetch_array($result))
{
   echo "<tr><td align='center'>";
   echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';
   echo "</td><td align='center'>";
   echo $row['item_name'];
   echo "</td><td align='center'>";
   echo $row['description'];
   echo "</td><td align='center'>";
   echo $row['in_return'];
   echo "</td><td align='center'>";
   echo '<a href="composemessage.php?uid='.$row['user_id'].'"><img src="images/K_little.png"         style="border:0px;" /></a>';

   echo "</td></tr>";
}
?>

when i click on the picture and it goes to composemessage.php,,,,,, should the url have the username at the end of it.  this is what it looks like now

 

composemessage.php?uid=

 

shouldn't the users name be after the =

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-814085
Share on other sites

in my query string shouldn't i be selecting the user_id  also... i just noticed that it wasn't there... would that make a difference????

 

<?php
"SELECT imgpath, item_name, description, in_return FROM member_trades WHERE category = 'Video Games' $limit";
?>

change it to

<?php
"SELECT imgpath, item_name, description, in_return, user_id FROM member_trades WHERE category = 'Video Games' $limit";
?>

Link to comment
https://forums.phpfreaks.com/topic/154575-solved-help-please/#findComment-814090
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.