GingerRobot
Staff Alumni-
Posts
4,082 -
Joined
-
Last visited
Everything posted by GingerRobot
-
What did you hope you would achieve by searching in this way? If you tell us what you are actually trying to do, we might be able to tell you a way of doing it.
-
You use GET. Ever done a google search and wondered what all the junk after the url is? For example: http://www.google.co.uk/search?hl=en&q=test&btnG=Google+Search&meta= You can pass variables through the url in this way. As an example, we'll use page1.php and page2.php. page1.php: <?php $var = 'foo'; echo '<a href="page2.php?var='.$var.'">Click here</a>'; ?> page2.php: <?php echo $_GET['var']; //output would be foo ?> You can also pass multiple variables in the url by separating each variable name and value pair with an ampersand (&) - rather like the above google example. So, in answer to your original question, you would make your links something along the lines of: echo '<a href="ViewProfile.php?user='.$row['user'].'">View profile</a>'; And then on Viewprofile.php: <?php $user = $_GET['user']; $sql = "SELECT * FROM `yourtable` WHERE `user`='$user'" //query and display data ?> I hope that explains it. Although i feel i might have rambled slightly.
-
Sessions - passing SID around in the URL
GingerRobot replied to GingerRobot's topic in PHP Coding Help
Yeah, you were right. It seems php either adds a hidden field(for forms) or adds a variable to the end of the query string(for link etc) containing the session id. You do then have to retrieve it from the relevant array and set it using session_id(). Seems strange that it doesn't automatically do anything with header("location:...) transfers though...i had to add the php session id in myself: header("location:http://localhost/loggedin.php?PHPSESSID=".session_id()); At least it works now. Thanks again for the help. -
Sessions - passing SID around in the URL
GingerRobot replied to GingerRobot's topic in PHP Coding Help
Ok, ill give that a go. To be honest, im not really worrying about it. It was an exercise to better understand it. Having tested it before, i always thought cookies HAD to be on for sessions to work - then i found out that wasn't correct, so im just trying to see how it works. -
Im having trouble getting sessions to work if cookies are disabled. As i understood it, if cookies are disabled, then php attempts to pass the session ID around in the URL, allowing the session to stay active. Im trying to see how this works, but i cant seem to get a most basic login to work whilst cookies are turned off. Login.php: <?php session_start(); if(isset($_POST['submit'])){ $_SESSION['loggedin'] = true; header("location:loggedin.php"); } ?> <form action="login.php" method="post" > username: <input type="text" name="user" /> <br /> <input type="submit" name="submit" value="login" /> </form> And loggedin.php: <?php session_start(); if(isset($_POST['submit'])){ session_destroy(); header("location:login.php"); } if($_SESSION['loggedin'] == false){ echo 'You are not logged in. Click <a href="login.php" />here</a> to log in'; }else{ echo 'You are logged in. Hello'; ?> <form action="loggedin.php" method="post"> <input type="submit" name="submit" value="log out" /> </form> <?php } ?> With cookies turned on, this works fine and shows me as logged in. However, when i turn cookies off, i always get the "you are not logged in" message. I have changed my php.ini setting for session.use_trans_sid to 1. I wonder if im just missing something completely stupid. Any help would be appreciated.
-
mysql_real_escape_string() - Weird problem
GingerRobot replied to SharkBait's topic in PHP Coding Help
Are you sure you are getting two backslashes? I would expect you to either get one or three. If magic_quotes is on, i would expect 3. That is because with the setting, the string becomes: The car\'s paint job is great to look at Before you've done anything. Then, when you apply the mysql_real_escape_string() function, it escapes both the single quote and the backslash, resulting in 3 backslashes: The car\\\'s paint job is great to look at Without magic_quotes, you should just get the 1 backslash. The function should just escape the single quote. -
I really cant think why you would get a quote there - it should be an integer variable. Can you show how/where youdefine $theme_id? Also, just to make 100% certain this is the problem, try modifying your or die statement(which, presumably you already have hence the above error) $sql = "UPDATE theme SET theme.img_file = '".$newname."' WHERE theme.id = '".$theme_id."'"; mysql_query($sql) or die(mysql_error().'<br />Query: '.$sql);
-
I dont think there's any prebuilt way of doing it. If you google you'll find some functions that others have wrote though.
-
[SOLVED] Anyone see where Im getting this error?
GingerRobot replied to dewey_witt's topic in PHP Coding Help
I suspect the problem is that you are using the foreach on an array which might not exist. If no-one checks any of your checkboxes for a particular type, then you'll get an error. Try checking to see if any have been selected@ <?php if(count($yourarray) > 0){ //you can use the foreach here } ?> -
Ok, well since you're making it the value of an html element, i'd go for using the html entities. Otherwise, the browser will get confused, since you surround the value in quotes and it finds other quotes.
-
Thats probably the way you're going to have to do it, or, if this is just for output, you could use the HTML entity: " for the double quotes and: ' for the singles. Although you dont need to escape the single quotes if you are surrounding your string in doubles.
-
Ah i see. The easiest solution is still probably along the same lines. Have a 'hidden' image tag: <img src="http://www.mysite.com/counter.php?userid=2300" style="display:none">
-
Usually you link to a php script in an image tag. The php script generates an image which displays a counter.
-
[SOLVED] no mysql commands will works at all please help
GingerRobot replied to zhahaman2001's topic in PHP Coding Help
Well, if you're accessing your mysql database through phpMyAdmin ok, then i would say that php and mysql are installed ok. So, i would guess that display_errors is set to off in your php.ini settings(try changing it to on) and that there is a problem with all your mysql commands. Could it be that you've forgotten to connect? -
Couple of questions about sending info to MySQL db
GingerRobot replied to JeBu's topic in PHP Coding Help
Well, you dont actually HAVE to list the field names. If you're inserting into all of the fields, its perfectly valid not to. -
I might be missing the point completely, but dont you just list the fields and use or? $sql = "UPDATE table SET the field = 999 WHERE field1=4 OR field2=4 OR field3=4 OR field4=4";
-
Is it possible for a page to know if it's been included?
GingerRobot replied to aka_bigred's topic in PHP Coding Help
If you take a look at the page for the function on the php site: http://uk3.php.net/include/ It shows that you can pass a variable in the URL if you make the path to the included file absolute. So, if you were to pass a varible in the url which was something like included=yes, you'd be able to set up your 'includee' to check for that variable, and do somethign differant if it equals yes. -
Well, it works fine for me. I wonder if its to do with something elsewhere in your code? Try putting just that code in a file and running.
-
If you are only wanting the first 3 records, add a LIMIT 3 clause to your mysql query.
-
Yes, you must name the select tag as an array with square brackets. Take this example: <?php if(isset($_POST['submit'])){ foreach($_POST['select'] as $value){ echo 'You selected '.$value.'<br />'; } } ?> <form action="<?php echo $_SERVER['phpself']; ?>" method="post"> <select name="select[]" multiple="multiple"> <option value="var1">Var 1</option> <option value="var2">Var 2</option> <option value="var3">Var 3</option> <option value="var4">Var 4</option> <option value="var5">Var 5</option> </select> <br /> <input type="submit" name="submit" /> If you were to select all 5 options, the output would be: You selected var1 You selected var2 You selected var3 You selected var4 You selected var5
-
If you were to post the relevant script rather than give us a link to the full code, you'd probably get more responses. However, to get you started, try adding an or die statement to your query: <?php $update=" UPDATE players SET name='$name',recordid='$recordid',dob='$dob',tall='$tall',weight='$weight',picture='$picture' WHERE id=$player_id"; $new_club=mysql_query($update,$db) or die(mysql_error().'<br />On query:'.$update); ?>
-
If you're just trying to remove the last character from your string, which presumably the last comma would be, use substr(). Easier and more efficient than regular expressions.
-
So just to be clear, its basically working, but the problem is that you have two wranks displayed? If so, i still think this is your best bet. I'd say you have two options - either list the exact fields you want rather than using *, or if you are outputing your results in php, then just only show one of the wranks.
-
Ok thanks, ill take a look when i get home.