Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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);
  8. I dont think there's any prebuilt way of doing it. If you google you'll find some functions that others have wrote though.
  9. Make your life a lot simpler: $sql = "UPDATE theme SET theme.img_file = '$newname' WHERE theme.id = '$theme_id'"; Its so early for me to come up with a coherent explanation of the quotes though. Im sure i would just confuse the issue.
  10. 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 } ?>
  11. 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.
  12. 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: &#34; for the double quotes and: &#39; for the singles. Although you dont need to escape the single quotes if you are surrounding your string in doubles.
  13. 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">
  14. Usually you link to a php script in an image tag. The php script generates an image which displays a counter.
  15. 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?
  16. Well, you dont actually HAVE to list the field names. If you're inserting into all of the fields, its perfectly valid not to.
  17. 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";
  18. 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.
  19. 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.
  20. If you are only wanting the first 3 records, add a LIMIT 3 clause to your mysql query.
  21. 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
  22. 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); ?>
  23. 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.
  24. 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.
  25. Ok thanks, ill take a look when i get home.
×
×
  • 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.