-
Posts
155 -
Joined
-
Last visited
-
Days Won
3
Everything posted by Frank_b
-
do you never get PHP errors? perhaps you should turn on error reporting? are you trying to serve an image or html with this code?
-
Display posts in order from newest to oldest by date?
Frank_b replied to Epicballzy's topic in PHP Coding Help
what field type did you use to store the date in your database? it should be a date or datetime type. -
Re-populating a checked Radio Button on a form - Please Help.
Frank_b replied to dweezer81's topic in PHP Coding Help
try: $win_status = ''; $ew_status = ''; if (isset($_POST['bet_details_bet_type'])) { $selected_radio = $_POST['bet_details_bet_type']; if ($selected_radio == 'WIN') { $win_status = ' checked="checked"'; } elseif ($selected_radio == 'EW') { $ew_status = ' checked="checked"'; } }- 4 replies
-
- radio button
- re-populating
-
(and 2 more)
Tagged with:
-
in JSON: [] is an array. {} is an object. Now we do have two types of arrays in PHP. 1. normal / numeric 2. associative a numeric array will produce a JSON array like this: [ "Frank", "Netherlands", 44 ] while an associative will produce a JSON object(!) like this: { "Frontname":"Frank", "Country":"Netherlands", "Age":44 } Now the first opening array is a numeric one (because we see a [ character). The elements inside that array are JSON objects so we need to start there with an associative PHP array. At the end we will get this: <?php $array = array( // numeric array array( // associative array 'key' => 'OWM1', 'values' => array( // numeric array array( // associative array 'x' => 'EW', 'y' => 4 ), array( 'x' => 'RSE', 'y' => 3 ), // and so on ) ), array( 'key' => 'OWM2', 'values' => array( array( 'x' => 'EW', 'y' => 4 ), array( 'x' => 'RSE', 'y' => 2 ), // and so on ) ), ); // show us the json: echo '<pre>'; echo json_encode($array, JSON_PRETTY_PRINT); echo '</pre>'; ?>
-
Sometimes it happens that you have a BOM (Byte Order Mark) on top of your file(s). http://en.wikipedia.org/wiki/Byte_order_mark You are able to check the files in an hex-editor like for example http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm. If there are a few bytes on top of the file before the content that you wrote this causes output and therefor the header() function will not work anymore. To get rid of it open a new php file in a php edittor, copy and past your code from the old file into the new file and save the new file. (overwrite the old one!)
-
First of all: Not all PHP features are a good practise to use. You will never find ob_start() and other ob_* functions inside my code files. First off all ob_* functions is just caching your output. But besides of that you would not need them if you follow one golden rule: Allways first handle your PHP logic without a single output. On the bottom of your script (i prefer in an other file) you start your output. <?php require_once 'include/config.php'; $message = 'Please login'; if($_SERVER['REQUEST_METHOD'] == 'POST') { $success = login(...); if($success) { header('Location: member.php'); exit; // do not forget to use exit after header('Location: ???'); } $message = 'Wrong credentials'; } include '/path/to/templates/loginform.html.php'; ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Login</title> </head> <body> <?php echo $message; ?> <!-- Login form here --> </body> </html>
-
How to load pages within a template properly
Frank_b replied to holdorfold's topic in PHP Coding Help
Give an array as the second parameter to showpage() $var = 'This is a variable'; $data = array( 'var' => $var, // more variables ); showpage("author.html.php", $data); Then into the showpage function use extract() to make the associative array as variables: function showpage($templateName, $data) { extract($data); unset($data); // if you wish include '/bla/bla/'.$templateName; } The template could be something like this: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php echo $var; ?> </body> </html> -
checking for duplicates when writing to text file
Frank_b replied to cobusbo's topic in PHP Coding Help
You can 'link' data from the database to other websites in various ways. The point is that databases gives you a normalized way to store huge amounts of records and a fast way to search those records. Its much more faster then using a csv file. -
checking for duplicates when writing to text file
Frank_b replied to cobusbo's topic in PHP Coding Help
Only possible if you first read the users.csv into memory and then scan every entry to see if there is a match. You should better store this into a database. -
my check boxes are not being sent in the email
Frank_b replied to hammahead's topic in PHP Coding Help
$fields{"selectedProjects"} = "None"; if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){ $fields{"selectedProjects"} = implode(', ', $_POST['projects']); } -
The whole point is that the results from the database (if we are talking about multiple records) are stored in two dimensional arrays. Therefor you are not able to simply use 'in_array()' . This will do: foreach($sectors as $sector) { foreach($uc_sid as $uc) { if($sector['sid'] == $uc['sid']) { echo 'found: ' . $sector['sid'] . '<br>'; } } }
-
The small blocks take 20% plus 5px spacing each. So the remaining width will be: 60% - 10px. You can use the css3 calc function: .large { float: left; height: 95px; background-color: blue; width:calc(60% - 10px); }
-
Newbie here, trying to build a contact form with a mailer
Frank_b replied to synergyworks's topic in PHP Coding Help
if i look to your test mail it seems that your provider does not support the PHP mail() function or that the mail configuration of the server is not right configured. -
you can redirect straight out of php <?php header("Location: http://www.example.com?id=1&name=frank"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> Of course you will need to generate the url string to get this done but that is not too difficult. Beware that you have to use the header function before you made a single output. (ouput like html and e.g. with the echo function from out php)
-
http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
-
You will have to use javascript to do this. try to learn something about javascript or if you did tell us what you have so far and which part is too hard for you
-
Allright, sorry to hear that you had a car accident. In your case i should start with the design and not with the technical details on how to post a form and send an email. So to start creating your page with the form you can use HTML and for the design you can use CSS. from both there are plenty tutorials on the internet and i think you don't really need to buy a book. In this design just forget about the datepicker. instead of this just make two input fields with HTML like any other basic inputfield. Later you will learn to use javascript with the JQuery library (or another library) that has a ready to use datepicker.
-
Later you can retrieve information out of the two tables with just one query. For example all family members from only one user WITH the information from the usertable for that one user. just google on 'mysql joins'
-
$total = mysql_num_rows($query) or die ("E112-101A"); that is unlogic. The keyword or takes a role in a logic expression. Think about if(mysql_num_rows($query) or die ("E112-101A")) ... if the first part of the expression (before the or) gives a TRUE than the expression will stop. But if the first part gives FALSE the expression will continue with the second part after the as which does stop your script with die(). For the case that you might not know it, FALSE equals to 0 (zero) and all other values equals to TRUE. in more helpfull words i could say that mysql_num_rows() and the combination 'or die()' is a very bad combination.You should alway check php.net for what values could be returned by the function you use, in this case the mysql_num_rows() function. Just take a look under the "Return Values" chapter here: http://www.php.net/manual/en/function.mysql-num-rows.php. you will learn that any value from of zero can be returned or FALSE on failures. Now comes a little bit hard to understand part of PHP. PHP can distinguish a FALSE from a 0 but you should use a special === or !== operator. $rows = mysql_num_rows($query); if($rows === FALSE) die('E112-101A');
-
I think using the full URL with 'http://' should solve your problem: header('Location: http://www.website.com/username');
-
assuming that you have a primary key column in your database with the name 'userid' you should do the following $sql = "SELECT userid, username, password FROM users WHERE username = '$username' and password = '$pas'"; $query_login = $db->prepare($sql); $result = $query_login->execute(array('username' => $username, 'password' => $pas)); if ($result->rowCount() > 0) $uid = $result['userid']; echo $uid;
-
It depends on the situation. I render pages using multiple controllers and multiple views. For example if you want to place a list in a sidebar of -by example- the last 10 posts of your blog over a number of pages it would be stupid to copy and past that code to every page that need to be rendered. In such a situation its better to make a new controller and a new view. That view wont render more then a html list (<ul>) within a container div. Some frameworks give not much posibilities to call another controller from the main-view but the better ones do. I use Symfony.
-
Try to use .html() instead of .text()
-
Because i saw two topics about simple login i made a simple example that has four php files. You will find it here: http://forums.phpfreaks.com/topic/288722-login-page-without-sql-that-saves-users-and-password-on-file/
-
Login page without SQL that saves users and password on file
Frank_b replied to DexterTheCat's topic in PHP Coding Help
Because i saw two topics about simple login i made a simple example that has four php files: <?php // index.php ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Welcome</title> </head> <body> <h1>Welcome on my homepage</h1> <ul> <li><a href="login.php">Login</a></li> <li><a href="secured_area.php">Secured area</a></li> </ul> </body> </html> <?php // login.php $message = ''; $users = array( 'Frank' => '1234', 'Rick' => 'abcd', ); session_start(); if($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($users[$_POST['username']]) && $users[$_POST['username']] == $_POST['password']) { // login succesfull $_SESSION['login'] = 1; $_SESSION['username'] = $_POST['username']; header('Location: secured_area.php'); exit; } else { $message = 'Wrong credentials'; } } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Login</title> </head> <body> <h1>Login</h1> <form action="" method="post"> <table> <tr> <td colspan="2"><?php echo $message; ?></td> </tr> <tr> <td>Username:</td><td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td><td><input type="password" name="password" /></td> </tr> <tr> <td> </td><td><input type="submit" value="Login" /></td> </tr> </table> </form> </body> </html> <?php // secured_area.php // if not logged in then redirect to login page // add this to every secured page session_start(); if(!isset($_SESSION['login']) || $_SESSION['login'] != 1) header('Location: login.php'); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Secured Area</title> </head> <body> <h1>Welcome in the secured area</h1> <p>Welcome <?php echo $_SESSION['username']; ?></p> <ul> <li><a href="index.php">Homepage</a></li> <li><a href="logout.php">Logout</a></li> </ul> </body> </html> <?php // logout.php session_start(); unset($_SESSION['login']); unset($_SESSION['username']); header('Location: index.php'); ?>