View Profile Problem.
Moderator: General Moderators
View Profile Problem.
Recently i have been trying to create a script where you can click on a members name and view their profile. The best way i could think of is making a table column named 'userprofile' and insert a link tag to their profile ID. My code so far go's like:
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=".$row['ID']."'>".$username."</A>";
$query = "UPDATE members SET userprofile = '$userprofile1'";
$result = mysql_query($query) or die("Query Error!");
Obviously i have created variable values for the names ect... But i keep getting a query error. Can someone please help me out here!!!
Regards
Joe - God is good, I am better
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=".$row['ID']."'>".$username."</A>";
$query = "UPDATE members SET userprofile = '$userprofile1'";
$result = mysql_query($query) or die("Query Error!");
Obviously i have created variable values for the names ect... But i keep getting a query error. Can someone please help me out here!!!
Regards
Joe - God is good, I am better
I get an error saying, Query Error!. Which most obviously means that i have a problem with the query:
$userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=".$row['ID']."'>".$username."</A>";
$query = "UPDATE members SET userprofile = '$userprofile1'";
$userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=".$row['ID']."'>".$username."</A>";
$query = "UPDATE members SET userprofile = '$userprofile1'";
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
I tried echoing variables with no luck at all. It shows the username as its stored in the code itself but it was not attaching the ID number to the end of the link. The code go's like:
<?php
$username = "Joe"; //Test varaibe. The value will actually be passed from a form link.
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result))
{
$row = mysql_fetch_array($result);
$ID1 = $row['ID'];
$userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=$I ... rname."</A>";
echo $userprofile1;
mysql_close($link);
}
I am now going to try Steveo's method on the real code. Any more help would be great as im struggling deeply with this?
regards
Joe
God is good. I am better
<?php
$username = "Joe"; //Test varaibe. The value will actually be passed from a form link.
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result))
{
$row = mysql_fetch_array($result);
$ID1 = $row['ID'];
$userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=$I ... rname."</A>";
echo $userprofile1;
mysql_close($link);
}
I am now going to try Steveo's method on the real code. Any more help would be great as im struggling deeply with this?
regards
Joe
Make a var_dump after:
$row = mysql_fetch_array($result);
echo "<pre>";
var_dump($row);
echo "</pre>";
if the $row['ID"] is ok,
try this:
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=". ... rname."</A>";
$row = mysql_fetch_array($result);
echo "<pre>";
var_dump($row);
echo "</pre>";
if the $row['ID"] is ok,
try this:
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=". ... rname."</A>";
I tried that aswell delorian with no luck. I yet again done another small test but this time change the value of $userprofile to 1 instead of the ID column. The code for that test went like:
<?php
$username = "Mcaster";
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
if (mysql_num_rows($result))
{
$row = mysql_fetch_array($result);
$ID1 = "1";
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=". ... rname."</A>";
echo $userprofile1;
}
?>
And all worked well, giving me the data for member ID #1 but i just cant seem to get it to add the $row['ID'] instead of assigning the variable with a direct value. Any help!!!
Regards
Joe God is good. I am better
<?php
$username = "Mcaster";
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
if (mysql_num_rows($result))
{
$row = mysql_fetch_array($result);
$ID1 = "1";
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=". ... rname."</A>";
echo $userprofile1;
}
?>
And all worked well, giving me the data for member ID #1 but i just cant seem to get it to add the $row['ID'] instead of assigning the variable with a direct value. Any help!!!
Regards
Joe God is good. I am better
I tried that aswell delorian with no luck. I yet again done another small test but this time change the value of $userprofile to 1 instead of the ID column. The code for that test went like:
<?php
$username = "Joe";
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
if (mysql_num_rows($result))
{
$row = mysql_fetch_array($result);
$ID1 = "1";
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=". ... rname."</A>";
echo $userprofile1;
}
?>
And all worked well, giving me the data for member ID #1 but i just cant seem to get it to add the $row['ID'] instead of assigning the variable with a direct value. Any help!!!
Regards
Joe God is good. I am better
<?php
$username = "Joe";
$link = mysql_connect("???", "???", "???") or die("Could not connect");
mysql_select_db("???");
$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
if (mysql_num_rows($result))
{
$row = mysql_fetch_array($result);
$ID1 = "1";
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=". ... rname."</A>";
echo $userprofile1;
}
?>
And all worked well, giving me the data for member ID #1 but i just cant seem to get it to add the $row['ID'] instead of assigning the variable with a direct value. Any help!!!
Regards
Joe God is good. I am better
Try replacing....
with....
I also notice that you do not have a WHERE clause in your update statement therfore all rows will be updated?
Code: Select all
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=".$ID1."'>".$username."</A>";Code: Select all
$userprofile1 = "<a href='http://www.mysite.com/viewprofile?ID=".$ID1."'>".$username."</A>";
$userprofile1 = addslashes($userprofile1);If there's one row returned, then you are first doing a mysql_fetch_assoc(), this grabs the row, then you try a mysql_fetch_array() which will be empty, as you've already got the row. So you basically need to remove the first mysql_fetch_assoc() and leave the fetch inside the if(mysql_num_rows($result))$query = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query($query) or die("Error");
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result))
{
$row = mysql_fetch_array($result);
$ID1 = $row['ID'];
$userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=$I ... rname."</A>";
echo $userprofile1;
mysql_close($link);
}
This is what happens when you do not use
Code: Select all
when posting your code-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
delorian wrote:This is what happens when you do not useCode: Select all
when posting your code [/quote] using thetags would not have affected that. They wouldn't have pointed that out to you.Code: Select all
EDIT: why are my php tags messed up here?? - Admin Edit: it was theCode: Select all
<?php $query = "SELECT * FROM members WHERE username = '$username'"; $result = mysql_query($query) or die("Error"); $row = mysql_fetch_assoc($result); if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); $ID1 = $row['ID']; $userprofile1 = "<A href='http://www.mysite.com/viewprofile?ID=$ID1'>".$username."</A>"; echo $userprofile1; mysql_close($link); } ?>Code: Select all
in the quote from delorian, should be ok now (weird bug though)