Jump to content

Questions... a few


jasonhardwick

Recommended Posts

ok i've got a set of questions that revolve around a network of users. Normally i would post them separate but just figured if anyone could help on anything that would be great... thanks

 

{ps: failure can get annoying}

 

let me explain a little.

 

I'm putting together a site that alows you to create a network of users. you can search for and view USER X's page and if you want invite him to your network you can via a  php button in the right hand corner. this button adds USER X's username and a , to a coulmn in my user table called "network_invite". now that php button needs to change based on the "network_invite" & "network" columns in my user table.  so if you art viewing USER X's page and he is already a "network member" (ie your name is in the "network" colum) your right hand corner button will then change to a "Remove from Network" button with a different action (php below).

 

ok so my questions are:

 

1: When I run the current button php I always get an "Invite to network" button?

2: When i try to run the "Invite to network" script it dosent seem to do anything?

3: I have no clue on how to delete an username from a string in the "network" column?

4: I need help adding a "username," to a string in the "network_invite" column?

5: I need help moving a "username," from a string in the "network_invite" column to a string in the "network" column?

 

 

 

Button Code:

<?php

			include "config.php";

				$username=$_SESSION['username'];
				$user_profile=$_GET['username'];

			$sql4 = "SELECT *
       from user
WHERE uname = '$user_profile' 
	";
	$sql5 = "SELECT *
       from user
WHERE uname = '$username' 
	";

$result4 = mysql_query($sql4) or die (mysql_error());
$row4 = mysql_fetch_assoc($result4);

$result5 = mysql_query($sql5) or die (mysql_error());
$row5 = mysql_fetch_assoc($result5);

//$user_profile=$_GET['username'];


if($row5['network'] == "user_profile")
{
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"accept_network.php\">";
   echo "<input name=\"network_invite\" type=\"hidden\" id=\"network_invite\" value =\"$user_profile\"/>";
   echo "<input name=\"invitee\" type=\"hidden\" id=\"invitee\" value =\"$username\"/>";
echo "<label>"."<input type=\"submit\" name=\"button\" id=\"button\"  value=\"Accept in network\" />"."</label>";
   echo "</form>";


else if($row4['network'] == "user_profile")
{
echo "<form id=\"form2\" name=\"form2\" method=\"post\" action=\"remove_network.php\">";
   echo "<input name=\"network\" type=\"hidden\" id=\"network\" value =\"$username\"/>";
   echo "<input name=\"invitee\" type=\"hidden\" id=\"invitee\" value =\"$user_profile\"/>";
echo "<label>"."<input type=\"submit\" name=\"button\" id=\"button\"  value=\"Remove from network\" />"."</label>";
   echo "</form>";


else
if($row4['network_invite'] == "user_profile")
{
   echo "network invite pending";


else	
{
echo "<form id=\"form3\" name=\"form3\" method=\"post\" action=\"add_invite.php\">";
   echo "<input name=\"network_invite\" type=\"hidden\" id=\"network_invite\" value = \"$username\"/>";
   echo "<input name=\"invitee\" type=\"hidden\" id=\"invitee\" value = \"$user_profile\"/>";
echo "<label>"."<input type=\"submit\" name=\"button\" id=\"button\" value=\"invite to network\" />"."</label>";
   echo "</form>";
}}}


// swhile ($row = mysql_fetch_assoc($result)) {

           // }
               ?>

 

 

Accept To Network Code:

<?php

include "config.php";

$tbl_name="user";

$user_profile=$_POST['invitee'];
$network_invite=$_POST['network_invite'];

$query=("Select * from user where uname='$name'");
$result= mysql_query($query); 
$num=mysql_num_rows($result);
//
// this is were I need a way to move from one column to another
//
$sql="UPDATE user SET network_invite = '$network_invite' WHERE uname = '$user_profile'";
//
//
$result = mysql_query($sql) or die (mysql_error());

if($result)
{
echo "Your have accepted ".$network_invite." to your network"."<BR/>";  
}
else
{
echo "Error";
}

?>

 

Remove from network code:

<?php

include "config.php";

$tbl_name="user";

$user_profile=$_POST['invitee'];
$network=$_POST['network'];

$query=("Select * from user where uname='$name'");
$result= mysql_query($query); 
$num=mysql_num_rows($result);

$sql="UPDATE user SET network = '$network' WHERE uname = '$user_profile'";

$result = mysql_query($sql) or die (mysql_error());

if($result)
{
echo "You have removed ".$network_invite." from your network"."<BR/>";  
}
else
{
echo "Error";
}

?>

 

 

Invite to network code:

<?php

include "config.php";

$tbl_name="user";

$user_profile=$_POST['invitee'];
$network_invite=$_POST['network_invite'];

$query=("Select * from user where uname='$name'");
$result= mysql_query($query); 
$num=mysql_num_rows($result);

$sql="UPDATE user SET network_invite = '$network_invite' WHERE uname = '$user_profile'";

$result = mysql_query($sql) or die (mysql_error());

if($result)
{
echo "Your Invite to".$network_invite."has been sent"."<BR/>";  
}
else
{
echo "Error";
}

?>

 

 

Link to comment
Share on other sites

At the heart of all of your questions is the problem of database stucture. You should not be storing a comma delimited field in one of your columns. You should have a separate table listing all invites to networks and all networks that a person belongs to.

 

I suggest you read up on database normalization. This topic here might get started.

Link to comment
Share on other sites

Yeah I know that there are many better ways to do everything!, and once i get my code working in my learning stage then i will rebuild it the proper way so if anyone could get my "freshman code" to work or some sugestions. then i can take a fresh look at the site and use what i've learned to build it better, but we all know that when your building a site while learning if you dont set a get it done goal you end up constantly starting over to use the "proper" code and structure then it never gets done.

 

any help would be great. thanks

Link to comment
Share on other sites

Yeah I know that there are many better ways to do everything!, and once i get my code working in my learning stage then i will rebuild it the proper way so if anyone could get my "freshman code" to work or some sugestions. then i can take a fresh look at the site and use what i've learned to build it better, but we all know that when your building a site while learning if you dont set a get it done goal you end up constantly starting over to use the "proper" code and structure then it never gets done.

 

any help would be great. thanks

 

I'd have to disagree with that last sentence of yours. I'm still learning and I end having to start over all the time, but once you get it down, it feels better that you did it the proper way, thus, you can apply what you just learned on some other script and end up having to start over less often.

Link to comment
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.