HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
[quote author=Mutley] [code]nl2br($comments)[/code] Should work? You don't need to make it a variable. [/quote] I don't know what version of PHP you're using, but mine requires you to assign it to a variable, unless you're echoing it directly :D [code] <?php $comments = <<<EOT This is line one This is line two This is line three EOT; // This will print on one line echo "$comments"; // This will print on one line nl2br($comments); echo "$comments"; // This will print on multiple lines echo nl2br($comments); // This will print on multiple lines $comments = nl2br($comments); echo "$comments"; ?> [/code] Regards Huggie
-
Setting up a (fairly) simple shopping basket page
HuggieBear replied to nickholt1972's topic in PHP Coding Help
Off Topic: I checked out your page in Firefox, and oh dear!.... :o I'm guessing you're using layers as I navigated to this page.... http://www.appletreenappies.co.uk/products.php?product=multisize I can't see any of the product descriptions as they're obscured by the size/colour/fastening box :( Regards Huggie -
OK, that's be cause you put single quotes around it, and you didn't replace it for yor variable, which was the important part. Change it to this: [code] while($row=mysql_fetch_array($rs)) { $id = $row["id"]; $cat = $row["category"]; $list .= "<a href='details.php?id=$cat'>$cat[/url]\n"; } echo <<<_HTML $list _HTML; [/code] Regards Huggie
-
sure, Make your link look like this: [code=php:0]<href="details.php?id={$row['category']}">{$row['category']}</a> [/code] Obviously change this value for the one you're using Regards Huggie
-
[quote] Anyone point me in the right direction? [/quote] Did you look at the section I pointed you at? That will give you the information you need for getting the IP Address, I assumed you already had the code to insert into the database as you've got the database setup already. If you need info on entering data into the database then check out the manual section relating to your database (more than likely MySQL). Regards Huggie
-
[quote] [code] <title>hi ya</title> </head> <body> this brake does not work <br> this line with brake works <p class="test">hi there i am <br>reddarrow</p> </body> </html> [/code] [/quote] I hate to say it, but that's correct. You should always have paragraph tags around your text. Regards Huggie
-
I agree with logging the details, that's a good idea, however, using the info to restrict areas/features of the site is not a good idea. As you've correctly identified (and it would appear made provision for) is that users IP's will probably change quite regularly. As for how you'd do it, just take a look at the [url=http://uk.php.net/manual/en/reserved.variables.php#reserved.variables.server]Predefined $_SERVER Variables[/url] area of the PHP manual. Regards Huggie
-
Why can't you use [b]<[/b][b]br>[/b] I thought that was valid in HTML Strict. Try [b]<br [/b][b]/>[/b] It might be that it wants a closing tag. According to this line in the DTD, it's fine as text markup... [quote] <!ENTITY % special "A | IMG | OBJECT | BR | SCRIPT | MAP | Q | SUB | SUP | SPAN | BDO"> [/quote] Regards Huggie
-
Yeah, it looks as though you need a while loop around the whole thing. Where you have: [code] <?php $r = mysql_fetch_assoc($res); // All your code here ?> [/code] You should probably have: [code] <?php while ($r = mysql_fetch_assoc($res)){ // All your code here } ?> [/code] This basically says, while there's still rows in the mysql resource, loop through. Regards Huggie
-
Have you read the PHP manual for info on the [url=http://uk.php.net/manual/en/ref.pdf.php]PDF Functions[/url]? If not then this would be a good place to start, it also refers you to some additional documentation. Regards Huggie
-
Posting Form Data To Database and Invoice System
HuggieBear replied to ImJustBrndn's topic in PHP Coding Help
As you have a cart setup already, you're implying that people can order multiple products as once, which means that you must be storing the data somehow already, probably in session variables. Is your cart coded in PHP? This may not actually be too difficult. Regards Huggie -
removing empty elements from the end of an array
HuggieBear replied to johnny5's topic in PHP Coding Help
[quote] Can anybody tell me how to remove just the empty elements on the end of array. [/quote] Maybe you should be looking at why you have empty elements at the end of an array in the first place ;) Regards Huggie -
Can you provide me with the full code for the page you're trying to paginate, and also a list of variable names and values that you're getting from the 'included' config file? Let's help you get this cleared up for you :D Regards Huggie
-
[quote author=OldManRiver] Tried the var assignment with the "{}'s" and got errors! Any other suggestions? [/quote] I think I missed the quotes off that one... try: [code=php:0]$html_str .= "{$_SESSION['display_block']}";[/code] Regards Huggie
-
[quote] Currently I do like '$_POST[var_name]' I want to be able to do '$_POST['var_name']' any way that is possible? [/quote] You can do that by using double quotes " " and putting the variable inside curley braces, known as [url=http://uk.php.net/manual/en/language.types.string.php#language.types.string.parsing]complex syntax[/url]. [code] <?php // Unquoted echo $_POST['name']; // Double quoted echo "{$_POST['name']}"; // Using heredoc (info about this is also on the link provided above) echo <<<HTML {$_POST['name']} HTML; ?> [/code] Regards Huggie
-
Get rid of the exit; at the bottom of login.php and where you have $html_str .= $_SESSION['display_block']; change it to: $html_str .= {$_SESSION['display_block']}; Regards Huggie
-
Sounds as though extract is what you need: [code] <?php extract($_POST); ?> [/code] This imports the key names into the namespace. So if your form has fields, user, pass and submit, then by using the above you can refer to them as $user, $pass, $submit. There's various options with extract, including what to do if a name already exists, I'd suggest you check out the php manual on [url=http://uk.php.net/manual/en/function.extract.php]extract[/url] Regards Huggie
-
It's almost right: [code] <?php $sql = "SELECT SUM(c) as total FROM tablename"; $result = mysql_query($sql); $row = mysql_fetch_row($result); echo "The total is {$row['total']}"; ?> [/code] Regards Huggie
-
Your code looks ok, if you added session_start() to the top of login.php you can remove it. I know I said the top of everypage, but as your including it into cleanpcr.php, there's no need to have it twice. Huggie
-
Is that a frame at the top of the page? Huggie
-
ok, is session_start() at the top of all the pages? This error is common if you're sending something to the browser before you call session_start(). I tend to make it the first thing on every page by default, e.g. [code] <?php session_start(); include('header.php'); include_once('connect.php') echo <<<HTML <html> <head> ..... ?> [/code] If that's not the case, then maybe you could post the first say 25 lines of code for me. Regards Huggie
-
Ohhhh.... Lost my head for a minute. In that case add the following to the top of every page before you output anything to the browser: [code=php:0]session_start(); [/code] Change each instance of $display_block to $_SESSION['display_block']; Then on the form page type: [code=php:0]echo $_SESSION['display_block']; [/code] Easiest way to take things like that between pages is through session variables. Regards Huggie
-
OK, you're missing the echo statements... See the comments I've made in your code... marked like this [b]// <----[/b] [code]<?php // check for required fields from the form if (isset($_POST['log'])) { //connection to server and select database require ('../scripts/db_connect.php'); // create and issue the query $sql = "select usr_id, usr_name, usr_pwd from log_user where usr_name = '$_POST[username]' AND usr_pwd = '$_POST[password]'"; $result = mysql_query($sql,$conn) or die(mysql_error()); if (mysql_num_rows($result) == 1) { $f_uid = mysql_result($result, 0, 'usr_id'); $sql = "select inf_id from user_idx where usr_id=$f_uid"; $residx = mysql_query($sql,$conn) or die(mysql_error()); if (mysql_num_rows($residx) == 1) { $f_inf = mysql_result($residx, 0, 'inf_id'); $sql = "select inf_fnam, inf_lnam from user_info where inf_id=$f_inf"; $resinf = mysql_query($sql,$conn) or die(mysql_error()); } // if authorized, get the value of f_name l_name $f_name = mysql_result($resinf, 0, 'inf_fnam'); $l_name = mysql_result($resinf, 0, 'inf_lnam'); // set authorization cookie setcookie("auth", "1", 0, "/", "localhost @mydomain.com", 0); //create display string $display_block = "<font size=-1><b>Welcome $f_name $l_name. <br>Thank you for logging in!</b></font>"; echo $display_block; } else { $display_block = "<font size=-1><b>Login not successful!</b></font>"; echo $display_block; // <---- This was missing // return; // exit; } } else { $display_block = "<form action='../scripts/login.php' method='POST'><p><strong>User Login:</strong><br> <INPUT TYPE='text' NAME='username'></p><p><strong>Password:</strong><br> <INPUT TYPE='password' NAME='password'></p><p> <br> <input type=image src='../Images/btn-pale(log).jpg' name=log value=log width=120> </form>"; echo $display_block; // <---- This was also missing } ?>[/code] Does that help at all? Huggie
-
I didn't realise you had code already written :D lol I'll take a look now. Regards Huggie
-
OK, you're possibly best using just one page here... Call the page something like login.php and set it up a little like this... [code] <?php // Set any default variables, I've put these here to show you as an example $username = "HuggieBear"; $password = "myPassword"; // Work out what to do next if (!isset($_GET['submit'])){ // if it's the first time the page has been called then display the form showForm(); // Just a call to the function further down } else { // if the submit button's been pushed if (($_POST['user'] == $username) && ($_POST['pass'] == $password)){ echo "Authenticated OK"; // Show this if the submitted username and password match up with what we have } else { echo "We couldn't authenticate you, please try again"; // Show this and the form if they failed to enter the correct details showForm(); } } // Function to show the form function showForm { echo <<<HTML <h1>$message</h1> <form name="login" action="{$_SERVER['PHP_SELF']}" method="POST"> <input type="text" name="user"> <input type="password" name="pass"> <input type="submit" name="submit" value="submit"> HTML; } [/code] Regards Huggie [size=8pt][color=red][b]Note:[/b][/color] This was written on the fly, so may not be 100% accurate but should give you an idea.[/size]