ibz786
-
Posts
29 -
Joined
-
Last visited
Posts posted by ibz786
-
-
In the words of Doc Brown from, Back to the Future "Great Scott!!"
I think that code has fixed it
I am very grateful for yours and everyone's help, very much appreciated
Thank You very much
Just a question, how did you figure it out? I ask since i wish to better my PHP coding skills
-
this is:
users.php
<?php include ('includes/connect.php'); session_start(); $query = mysql_query("SELECT * FROM users WHERE id = " . $_SESSION['user'] . ""); $user = mysql_fetch_assoc($query) ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div id="banner" style="background-color:#000000"> <img src="images/logo.png"> <form id="searchbox" action="#" method="post"> <input type="text" id="search" name="search" value=""> <input type="submit" id="submit" name="submit" value="Search"> </form> <a href="home.php"> Home | </a> <a href="profile.php?id=<?php echo $user['id']; ?>"> Profile | </a> <a href="#"> Messages | </a> <a href="settings.php"> Settings | </a> <a href="users.php"> Users | </a> <a href="logout.php"> Sign Out </a> </div> <div> <?php $members = mysql_query("SELECT * FROM users"); while($allusers = mysql_fetch_assoc($members)) { echo "<table> <tr> <td> <a href=\"profile.php?id=" . $allusers['id'] . "\">" . $allusers['fullname'] . "</a> </td> </tr> </table>"; } ?> </div> </body> </html>
So basically what im trying to do here is when i hover the usernames which are links
they say:
localhost/sblog/profile.php?id=1 or 2 or 3 depending on their links etc
So when i click on the links i want them to take me to the users profile which i have clicked on and not my own
Hope that makes sense
-
Ok to the profile.php file i have added this
<?php include('includes/connect.php'); session_start(); if ($_GET['user'] != "") { $query = mysql_query("SELECT * FROM users WHERE id = " . $_GET['user'] . ""); } else { $query = mysql_query("SELECT * FROM users WHERE id = " . $_SESSION['user'] . ""); } $user = mysql_fetch_assoc($query) ?>
The $_GET bit doesnt work
I understand that the $_SESSION['user'] shall allow for me to get the logged in users profile
But i I dont know how to grab other users profile using the $_GET method, if someone could help i would be grateful
Thank You
-
-
Erm unfortunately that code didnt work
In addition i dont understand it, hmm im rather stuck at the moment :/
-
Hey, thanks for that i shall try it. Just to quickly ask, the code you have posted do i put that in profile.php?
My apologies for the confusion
Ok heres what i mean:
in home.php the page is operating under the session of the currently logged in user, e.g. id = 1 is John Doe for example
using the code i have for home.php i can access John Doe's profile since his id matches that of the users database
I created users.php to display all the users as links, so if i wish to view their profile all i need to do is click on them
when i hover over the user names, their id value appears
e.g. profile.php?id=3 profile.php?id=4 etc
However due to an error in profile.php i can only access the logged in users profile
My apologies if i repeating myself or not making sense i haven't had much sleep lol
-
Hi, for my coursework i need to make a microblogging website, similar to that of Twitter
I have created a MySQL Database, and also the login and registration forms
I am able to log in as a user and also change user submitted information i.e. Name, About Me etc
The problem i am having is that when i access the logged in users profile page e.g. John Doe, i can access it fine
However, when i wish to access say James Smith or any other user, i am redirected back to John Doe's profile
login.php
$query = mysql_query("SELECT * FROM users WHERE username = '$user'") or die(mysql_error()); $login = mysql_fetch_array($query); if(md5($pass) == $login['password']) { $_SESSION['user'] = $login['id']; header("Location: home.php"); }
home.php
<?php include ('includes/connect.php'); session_start(); $query = mysql_query("SELECT * FROM users WHERE id = " . $_SESSION['user'] . ""); $user = mysql_fetch_assoc($query) ?> <a href="profile.php?id=<?php echo $user['id']; ?>"> Profile | </a>
users.php
<?php include ('includes/connect.php'); session_start(); $query = mysql_query("SELECT * FROM users WHERE id = " . $_SESSION['user'] . ""); $user = mysql_fetch_assoc($query) ?> <?php $members = mysql_query("SELECT * FROM users"); while($allusers = mysql_fetch_assoc($members)) { echo "<table> <tr> <td> <a href=\"profile.php?id=" . $allusers['id'] . "\">" . $allusers['fullname'] . "</a> </td> </tr> </table>"; } ?>
In all honesty i do know that the fault lies with the $_SESSION bit of the code since everything i do will only access the profile of the user who is logged in
However i dont know how i am able to allow the logged in user to access their own profile as well as view other people's profile.
Another problem is how do i follow users?
I have a table called 'follow'
I have two columns, user_id and follower_id, both being foreign keys
However i honestly dont understand how to use PHP code to make users follow each other
If anyone could assist me with any part of this i would be very grateful
Thank You
-
Hi guys, i have not started this as of yet, however i will be given a project to make a micro-blogging website similar to that of Twitter or Facebook but obviously on a much smaller scale
I have been searching on google however i have not found anything. Maybe i haven't been using the right words in my query, not sure :-/
I have been trying to do some research, however i can't seem to find how to incorporate @ tags found in Twitter / Facebook.
e.g. If i want to tag a person in a Status Update:
Hey @John Smith, Football in the park at 3pm?
If anyone is able to help i would be grateful
Thank You
-
Hi, flolam
Thanks for all your help i really appreciate it
The code works enough for me to be satisfied with it, your efforts are much appreciated it,
Thank you very much
All the best to you
-
Yeah sorry i realised that straight after i posted that my aplogies, been a long day
Ok now what happens is that ive got the code to increment the house visits by one, however, it doesnt overwrite e.g. 4 (for house one) to 5, i just creates a whole new line :s
-
Ok ive made the code to work slightly:
It has indeed incremented it, by one however i have a few errors, i have uploaded a picture of the error
My current code is:
<?php if (isset($_POST['mybox'])) { $filename = "houses2.txt"; $fileOpen = fopen($filename, "a"); $visit = $_POST['mybox']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); $newVisit = $item_array[3]+=1; $fileText = "Number of Visits - " . $newVisit . "<br>"; echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); echo("<br>"); fwrite($fileWrite, $fileText); } fclose($fileOpen); } ?>
Not sure where im going wrong :S
[attachment deleted by admin]
-
you changed the wrong code.
replace $fileText = $item_array[3]+1;
with $item_array[3] += 1;
My apologies,
I tried changing that however, the problem remains the same, it doesnt seem to replace 4 with 5 (for the first property)
I just seems to overwrite the whole txt file and leaves it blank
Not sure what to do here really :/
-
try this
$item_array[3] += 1;
instead of
$fileText = $item_array[3]+1;
Hi i tried that:
echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3] += 1 . "<br>");
unfortunately it didnt work :S
I may have not put it in the right area, but still not sure :/
Edit:
Also i have realised that when i write "houses2.txt" Instead of updating the number of visits, the whole file becomes blank :S
-
Indeed, its part of my coursework
I know for a fact that all that i am doing would be so much easier via an SQL Database, and i have more of an idea on how to do it on there since arrays as such wouldnt be needed etc ...
However our lecturer wants to read it from a text file which is really troublesome
-
Im really confused, if the thing i need is either to write or append
I feel it maybe appened, but how do i ?
e.g.
After clicking on the first house, increase (and write to the file) the number of visits from 4 to 5?
If anyone knows where im going wrong please help in addition i know in the code provided i have:
"houses.txt" and then "houses2.txt", i was just experimenting since i didnt want to spoil the original file if anything were to go wrong
-
I have a text file with the following:
HA11QS, 200, house1.jpg, 4
HA22BR, 280, house2.jpg, 10
HA33AB, 390, house3.jpg, 3
HA44CD, 320, house4.jpg, 8
I have a form:
<?php if (isset($_POST['price'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r"); $max = $_POST['price']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); if (((int) $item_array[1]) <= $max) { ?> <form action='visit2.php' method='post'> <?php echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); ?> <input type='checkbox' name='mybox'> <input type='submit' value='Visit Property'> </form> <?php } } fclose($fileOpen); } ?>
and i also have "visit.php"
<?php if (isset($_POST['mybox'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r+"); $filename2 = "houses2.txt"; $fileWrite = fopen($filename2, "w"); $visit = $_POST['mybox']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); $fileText = $item_array[3]+1; if ($visit == true) { echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3] . "<br>"); echo("<br>"); fwrite($fileWrite, $fileText); } } fclose($fileOpen); fclose($fileWrite); } ?>
What i need is , when the user in the form, clicks on the checked box, it sends the information to 'visits.php' and it writes to the text file, increasing the selected value by one
Please can anyone help, im really struggling with this
Thank You
-
Hmm ive tried alot of things but im having now luck, is anyone able to help me with this
If you are then i would be extremely grateful thanks
-
Hmm thats not really what i need
Ive read somewhere, that i need to have
both the "r+"
and then the fwrite function
However im really not sure how to handle this, can any one help me please?
Thanks
-
I have a textfile called 'houses.txt':
HA11QS, 200, house1.jpg, 4
HA22BR, 280, house2.jpg, 10
HA33AB, 390, house3.jpg, 3
HA44CD, 320, house4.jpg, 8
I have a php file which puts all this into an array and using a form, when the user enters a value e.g. 300 it, displays all the houses equal to or less than that. This works fine
<?php if (isset($_POST['price'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r"); $max = $_POST['price']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); if (((int) $item_array[1]) <= $max) { echo("<form action='visit.php' method='post'>"); echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); echo("<input type='checkbox' name='mybox'>"); echo("<input type='submit' value='Visit Property'>"); echo("</form>"); } } fclose($fileOpen); } ?>
However what i need to do is using a form, (Form values which i have just recently added to the code supplied above)
Is that when a user clicks on property, it returns the house or houses selected with the checkboxes and the number of houses visits are incremented by 1 each time
All i have is:
<?php if (isset($_POST['mybox'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r+"); $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); $house_visit = $item_array[3]; $house_visit++; echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); echo("<br>"); } fclose($fileOpen); } ?>
But it really doesnt work, if anyone can help me i would be grateful
Thanks
-
Thank You soo much i really appreciate all your help
It works now
Thanks again and all the best to you
-
Hi i tried using that code but i get really confused in understandng it
with the
(preg_match('/(^|, )'.$max.'($|,)/i', $row)
It didnt work for me unfortuantely, and also i need for it to be read from the file
Thanks for your help its much appreciated
-
Lol, sorry about my bad english i was rushing and wasn't paying attention
Ok what exactly i am looking for is:
If the user enters: 4, this information is sent back to the array where it searches it, and the shows all the houses which have the number 4, in this case, e.g.
HA11QS, 200, house1.jpg, 4 since this house has had 4 visits,
If the user had entered, 320 then:
HA44CD, 320, house4.jpg, 8
if what the user enters is not in the array then it will return a message saying "Not found", however i havent added this yet, but can do
Hope this helps, Thanks
-
Hi,
I have a Comma Delimited File called "houses.txt" with the contents of:
HA11QS, 200, house1.jpg, 4
HA22BR, 280, house2.jpg, 10
HA33AB, 390, house3.jpg, 3
HA44CD, 320, house4.jpg, 8
I have a web form "form2.html":
<html> <head> <title>Untitled Document</title> </head> <body> <form action="any.php" method="post"> Please Enter Anything <input type="text" name="any"> <input type="submit" value="Submit"> </form> </body> </html>
and PHP code of "any.php":
<?php if (isset($_POST['any'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r"); $max = $_POST['any']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); if (in_array($max,$item_array)) { echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); echo("<br>"); } } fclose($fileOpen); } ?>
What i need is for the user to input anything they wish for example:
4, which would search the array and find that the first house has had 4 visits or
HA44CD, to find the last house on the list etc ... however unfortunatley its not working for, if anyone can help me i would grateful
Thank You
-
Hi, sorry about not replying earlier i have been busy so i wasnt able to finish of my code until now. I would like to thank you both, you have been extremely helpful, without your help i would have struggled
Thank You
PHP Loop change after the first Iteration
in PHP Coding Help
Posted
Hi there guys
Basically im trying to call images from my SQL DB (which is fine)
and im trying to echo them out using a while loop (which is also fine)
So in turn my results display 200 x 200 images of whatever im trying to call from my DB
However i wish to display it as that from my array loop, i wish for the first picture to be 200 x 200 then the rest are 100 x 100
If anyone can please help me i would be most grateful
Thank You