cazconv Posted February 13, 2010 Share Posted February 13, 2010 Hi, im building a social networking site for my dissertation and im having a little trouble with one part updating the status's I can get it updated in the database but I cant figure out how to have a user to a status, I have a table of : CREATE TABLE Dis_Status (username varchar(255), StatusID INT (2) NOT NULL AUTO_INCREMENT, Status Varchar(255), PRIMARY KEY (StatusID), FOREIGN KEY (username) REFERENCES Dis_Teen(username)); Heres my Profile Page <?php session_start(); require_once('dbconnect.php'); if (isset($_SESSION["username"])) { $username = $_SESSION['username']; } else { // not logged in so redirect header("location: login.php"); exit; } if (isset($_SESSION["password"])) { $password = $_SESSION['password']; } else { // not logged in so redirect header("location: login.php"); exit; } if (isset($_SESSION["fullname"])) { $First_Name = $_SESSION['fullname']; } if (isset($_SESSION["gender"])) { $Gender = $_SESSION['gender']; } if (isset($_SESSION["group"])) { $GroupCode = $_SESSION['group']; } if (isset($_SESSION["surname"])) { $Surname = $_SESSION['surname']; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="style2.css" /> <title>TASN - Talk, Play, Share</title></head> <body> <h2> Talk, Play, Share </h2> <div class = "Logo"> <img src = "logo.png" height = "50px" width = "150px" /> </div> <div class = "logout"> <a href = "logout.html"> Logout </a> </div> <hr> <h1> <?php echo $First_Name . "s"; echo " "; echo "Profile Page"; ?> </h1> <h3> <div class = "StatusPost"> <form action="status.php" method="post"> Status: <input type="text" name="Status"/><br> <input type="Submit" value="Post" style="background-color:#3300CC; color: #ffffff;"/> </form> </div> <?php $result = mysql_query("SELECT Group_Name FROM Dis_Group WHERE Group_Code='$GroupCode'"); echo "<div class = \"ProfileInfo\">"; echo "Name:"; echo " "; echo $First_Name." ".$Surname; echo "<br>"; echo "Status:"; echo "<br>"; echo "Group:"; echo " "; while ($row = mysql_fetch_array ($result)) { echo $row[0]; } echo "</div>"; if ($Gender == "Female") { echo "<div class = \"profilepic\">"; echo '<img src = "girl.png" width = "150px" height = "150px">'; echo "</div>"; } else { echo "<div class = \"profilepic\">"; echo '<img src = "boy.png" width = "150px" height = "150px">'; echo "</div>"; } ?> </h3> </body> </html> And heres Status.php <?php require_once('dbconnect.php'); include 'Profile.php'; $Status=$_POST['Status']; $Status = stripslashes($Status); $Status = mysql_real_escape_string($Status); //if username is $sql="INSERT INTO Dis_Status(Status) VALUES ('$_POST[status]'.'$_POST[status]')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo $Status ?> How can i insert the username of the person already logged in into the status table along with thier status??? Sorry if im not making much sense im not used to asking questions on forums. Link to comment https://forums.phpfreaks.com/topic/191973-php-status-update/ Share on other sites More sharing options...
mapleleaf Posted February 13, 2010 Share Posted February 13, 2010 UPDATE Dis_Status SET status = 'Status' WHERE username = 'whatever'; It is an UPDATE that you need not INSERT. Obviously that query is not exact but I hope it gives the idea. Also it is easier to read if you put code in the code tags Link to comment https://forums.phpfreaks.com/topic/191973-php-status-update/#findComment-1011840 Share on other sites More sharing options...
abazoskib Posted February 13, 2010 Share Posted February 13, 2010 the best way would be to use a user_id instead of the username. lookups, searches, and sorts will be fatser if you use an auto incremented int primary key as the relating attribute. Link to comment https://forums.phpfreaks.com/topic/191973-php-status-update/#findComment-1011909 Share on other sites More sharing options...
cazconv Posted February 16, 2010 Author Share Posted February 16, 2010 Thanks I changed the query to Update Dis_Status SET Status = '$_POST[status]' Where TeenID = $TeenID But its not updating the database at all Link to comment https://forums.phpfreaks.com/topic/191973-php-status-update/#findComment-1013106 Share on other sites More sharing options...
cazconv Posted February 16, 2010 Author Share Posted February 16, 2010 Hi thanks guys, I've worked it out now Link to comment https://forums.phpfreaks.com/topic/191973-php-status-update/#findComment-1013119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.