-
Posts
364 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Love2c0de
-
Setting up server in Aptana
Love2c0de replied to Love2c0de's topic in Editor Help (PhpStorm, VS Code, etc)
Update, Now I am getting the files to open up in the browsers ok only when I select 'Use built-in web server' though and my PHP code isn't executing. The url in the address bar now is: http://127.0.0.1:8020/Single-Fathers/index.php Anyone know what I am doing wrong? When I select the server which I set up it is still bringing up the error dialog with the message stated in my previous post. Kind regards, L2c. -
Good morning guys, Just wondering if you could possibly help me setup my WAMP server to work with Aptana 3? I have googled it and found a response from another blog type website and have tried what they said but to no avail. I have setup my workspace to be in C:\wamp\www. I have opened up my files in Aptana from the www\ folder, the same ones I had in my text editor. I went to Window -> Preferences and then Aptana Studio -> Web Servers and created a new web server. For the name I put 'Coder'. For the Base URL I put http://localhost For Document Root I put C:\wamp\www Not sure what I am doing wrong, when I try to run my index.php using the 'Run' button, it is opening up the file in FF and prompting for download. When I go to 'Run Configurations' and the 'Web Browser' node and click on the FF one, when I select 'Use selected server' and choose the one which I created nd try to run FF, it brings up an error saying: "'Launching Firefox - Internal Server' has encountered a problem. Generic server doesn't suport start". It is only when I choose 'Use built-in web server' in the configurations that it actually opens up firefox but then as stated it prompts for download. The link which is in the address bar when FF opens and prompts for download is this : file:///C:/wamp/www/Fathers/index.php Please help me, I really want to give IDE's a chance and I can't get this to work (first timer) Thanks in advance, Regards, L2c.
-
Can I define a session variable before session_start()?
Love2c0de replied to suckerpunch's topic in PHP Coding Help
Yes. It must be at the very top of your code also. <?php session_start(); //now you can set session variables anywhere in the script. ?> Kind regards, L2c. -
Have you started writing your action file? I don't mind writing a very basic script for you, just to get the information to your email, but you will have to improve on it as I will purposely leave certain things out. This will help you to actually understand why you need to check certain things because if we go and write the whole thing for you, you're going to learn absolutely nothing at all and will most likely have to come back to forums and ask similar questions. Kind regards, L2c.
-
I noticed one problem. With the date() function, you are only specifying the format in which you want the date to display, but you don't actually provide a timestamp or anything else or it to format. Kind regards, L2c.
-
Hi benjahnee, good evening to you. I thought I'd re-write your script because I think for this case you should process the PHP code first, then output what you need, instead of mixing processing and raw HTML together. <?php $secret = rand(1,10); // Check if the form has been submitted if(isset($_POST['guess'])) { $guess = intval($_POST['guess']); $secret = intval($_POST['secret']); $output = ""; if($guess == $secret) { $output .= "<h1>Correct!</h1>"; $output .= "<a href='#'>Play again</a>"; } elseif($guess < $secret) { $output .= "<h1>Your answer was too low. Please try again!"; } else { $output .= "<h2>Your answer was too high. Please try again!</h2>"; } } ?> <html> <head> <title>Page Name</title> </head> <body> <form action="" method="post"> <input type="hidden" name="secret" value="<?php echo $secret; ?>" /> Guess: <input name="guess" type="text" /> <input type="submit" value="Guess!" /> </form> <?php if(isset($output)) { print($output); } ?> </body> </html> It looks a lot cleaner. Hope this helps. Kind regards, L2c.
-
Run a var_dump() on $uri just after setting it. It's returning an empty string for me even though when I do print_r($_SERVER), there is a value in theat index. There is a problem which lies in your dirname() call I think, you are passing a filename when you should be passing a directory name. Whether it is affecting it I don't know because you seem adamant you are successfully getting to the header page and the only place you use the $uri variable is in the header call.. Kind regards, L2c.
-
You declare a session as $_SESSION['session_name']. You missed the dollar sign. $_SESSION is a superglobal, just like $_SERVER which you used previously. Take a look here:http://php.net/manual/en/language.variables.superglobals.php Also, I'm pretty sure if you start a session in a file, then locate to a new file using a header() call, then you have to restart the session also with session_start(). If you locate to the new page with an include() or require(), you don't have to re-declare the session_start(). Depends what you want to do because obviously after including the file it will return to the calling script eventually. Hope this helps. Kind regards, L2c.
-
Thanks for your reply. That's exactly what I have read about which is why I was unsure of whether it was a 'standard' thing to do for member areas. After reading this I immediately thought about checking whether a session is set, and if it isn't, then header them back to the homepage or something. Would that suffice or would there have to be other checks put in place to make sure someone doesn't just access the area without being logged in, and if so, would you be able to give me a hint at what I should be looking for? Kind regards, L2c.
-
Good evening, I have a site where you can login and it works all fine and dandy. Currently, after login, they are sent back to the homepage, where PHP checks whether a session is set to decide upon what content to print. I am going to change this so that they redirect to an actual members area. I have tried to create a visual of my site directory to help assist my question. Here it is: [] = Directory Name --> Sub Files [GamingSite] -->index.php [styles] [js] [images] [core] //Inside [core] -->register.php -->login.php -->logout.php -->upload.php -->sidebars.php -->initialize.php -->reset.php -->page_views.txt [content] [db_queries] [demos] Where should I create my content for the members area? Should I create a new directory within the /core/ directory let's say core/members_area/ or should I just put it with my other page content (which is in the /content/ directory, believe it or not! )? Thanks in advance for your thoughts & assistance. Kind regards, L2c.
-
Good evening, I have wrote this for you. Is this what you want? <html> <head> <style type="text/css"> html, body { margin: 0px; } #main_container { width: 80%; margin: auto; } #left_container { width: 20%; height: 300px; background: green; float: left; } #right_container { width: 20%; height: 300px; background: yellow; float: right; } #content_container { background: blue; width: 60%; height: 300px; margin: auto; } #footer { width: 100%; clear: both; height: 100px; background: pink; } </style> </head> <body> <div id="main_container"> <div id="left_container"> left column </div> <div id="right_container"> right column </div> <div id="content_container"> main content </div> <div id="footer"> footer </div> </div> all of these divs are within the 'main_container' div, adjust the width as needed. </body> </html> Also don't use the <b> bold HTML tag, it's deprecated. Style it in CSS instead, something like #left_container { font-weight: bold;} (being very generic there)..... Hope this helps, Kind regards, L2c.
-
Good evening Salathe, That's correct, I've setup a CHAR table field to cater for tihs value. I think my code should work now because I check the length of $_GET['letter'] and make sure it's equal to 1 before performing the preg_match(). Here is my completed code: <?php $conn = mysqli_connect("localhost","root","","gaming") or die("Error: ".mysqli_error()); $qry = "SELECT game_id, release_date, game_desc, game_icon FROM games"; if(isset($_GET['letter'])) { if(strlen($_GET['letter']) == 1) { if(preg_match("/[A-Z]/", $_GET['letter']) === 1) { $qry .= " WHERE game_tag = '{$_GET['letter']}'"; } else { header("Location: ?page=games"); } } else { header("Location: ?page=games"); } } $sql = mysqli_query($conn, $qry) or die("Error: ".mysqli_error($conn)); $game_output = ""; while($row = mysqli_fetch_assoc($sql)) { $game_output .= "<div class='game_containers'>"; $game_output .= "<img src='images/game_icons/{$row['game_icon']}' alt='{$row['game_id']}' class='game_icon' />"; $game_output .= "<h3 class='game_header'>{$row['game_id']}</h3>"; $game_output .= "<p class='game_desc'>{$row['game_desc']}</p>"; $game_output .= "<hr />"; $game_output .= "Release Date: <span class='game_date'>{$row['release_date']}</span>"; $game_output .= "</div>"; } mysqli_close($conn); ?> I'm always open to suggestions on how to do things better though. I had the length in mind when I decided to go for regexp but didn't know how to edit the regular expression so I used strlen() instead. Kind regards, L2c.
- 5 replies
-
- preg_match()
- regexp
-
(and 3 more)
Tagged with:
-
Text dropped after whitespace using mysqli_query
Love2c0de replied to emmavt's topic in PHP Coding Help
As a suggestion, do all your trimming etc BEFORE you setup a query string. Kind regards, L2c. -
You know I was going to try that but I thought you only had to add the opening and closing brackets when you were looking for more than one type of match. Thanks very much for the prompt response also! Kind regards, L2c.
- 5 replies
-
- preg_match()
- regexp
-
(and 3 more)
Tagged with:
-
Good morning, I have a script and I'm trying to check whether it contains 1 character and whether it is between A and Z. preg_match() seems to be returning 0 and I'm not sure why. Here is my code: <?php $conn = mysqli_connect("localhost","root","","gaming") or die("Error: ".mysqli_error()); $qry = "SELECT game_id, release_date, game_desc, game_icon FROM games"; if(isset($_GET['letter'])) { /*if(strlen($_GET['letter']) == 1) { } else { header("Location: ?page=games"); }*/ $match = preg_match("/A-Z/", $_GET['letter']); echo $match; $qry .= " WHERE game_tag = '{$_GET['letter']}'"; } $sql = mysqli_query($conn, $qry) or die("Error: ".mysqli_error($conn)); $game_output = ""; while($row = mysqli_fetch_assoc($sql)) { $game_output .= "<div class='game_containers'>"; $game_output .= "<img src='images/game_icons/{$row['game_icon']}' alt='{$row['game_id']}' class='game_icon' />"; $game_output .= "<h3 class='game_header'>{$row['game_id']}</h3>"; $game_output .= "<p class='game_desc'>{$row['game_desc']}</p>"; $game_output .= "<hr />"; $game_output .= "Release Date: <span class='game_date'>{$row['release_date']}</span>"; $game_output .= "</div>"; } mysqli_close($conn); ?> When I echo $match, it always returns 0 even though $_GET['letter'] contains say 'M' or 'C' Any thoughts? Kind regards, L2c.
- 5 replies
-
- preg_match()
- regexp
-
(and 3 more)
Tagged with:
-
Never knew it existed! nice one.
-
The beings of the pleiades will soon be amongst us.
-
Can't edit my post but in the second section of code change the variable from $tmt to $stmt. Regard, L2c.
-
I believe it is because you re checking the return value of prepare() within an if statement. prepare returns an object on success or FALSE on failure. Try this out and see if it helps you: $cmd = "INSERT INTO Users(UserFirstName, UserLastName, UserEmail, UserCode, UserExpireDate) VALUES (?,?,?,?,?)"; $stmt->prepare($cmd) or die ("Error with prepared statement.".mysqli_error()); $stmt->bind_param('sssss', $UserFirstName, $UserLastName, $UserEmail, $UserCode, $UserExpireDate); $stmt->execute(); $stmt->store_result(); $rows = $stmt->affected_rows; if($rows == 1) { echo "<b>Invitation updated in the db</b>"; } else { echo "<span class='error'>Prepare Failed</span>"; } Failing that you could change your if statement to this: if(!$tmt->prepare($cmd))) { //error } else { //success } Does this help at all? Kind regards, L2c.
-
Which exam?
-
Great post Psycho, totally agree. I'm not a decent php developer by any means but just frequenting several forums for a few years, trying to help people solve their problems no matter how big or small, it's been quite invaluable for me. My CSS has got better from doing this 100%. I never understood display: inline and display: inline-block for example, or the difference between inline and block level elements etc but now I can explain what they are. Another example is venturing off into jQuery after being advised on a forum and it's such a great framework to code with. Having said that, I was finally able to grasp the concept of PHP templates after watching a couple videos on youtube. I was on a forum and this dude tried to explain on several occasions and I just couldn't grasp it until I watched those videos and I'm so glad I can understand the concept now as it saves work. I learnt about how to work with a directory with functions like dirname() and scandir(). From that was arrays, using functions such as in_array() and array_unshift(). This may seem pretty simple to you but when first starting out this was fantastic for me. I'd say watch some tutorials and try to understand the concept first, once you understand, go off and create your own application. I know exactly what you mean, I feel like I am stuck at a point and I don't know where to go next. Kind regards, L2c.
-
I stated those were examples, implying there were more possible dangerous queries. Kind regards, L2c.
-
I'd block all attempts at someone trying to enter DELETE or UPDATE for example. I wouldn't let anyone run a query at all though. Regards, L2c.
-
I think that is because your query is set up to 'SELECT ALL' so it will select all the photo_category images where the id matches so any which are the same will be selected. I'm not sure how to fix it though and I'm not sure if that is entirely correct but that was my initial thoughts. Hope it helps. Regard, L2c.
-
Does your problem lie when you host it online? If so have you changed your sql connection values in your "database_connection.php" script? Regards, L2c.