wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
You cannot place PHP code within .tpl files as by default PHP code is only parsed within .php files. If you want to parse PHP code within any other file you'll have to modify the servers configuration. The easiest way is to do this using an .htaccess file. First create a new file called .htaccess in your sites root directory (where you upload your site files to). And add the following configuration. AddType application/x-httpd-php .php .tpl If your hosts allows this change to me made your site should load without any errors appearing. If an Error 500 is displayed then you are unable to modify the servers configuration. In which case you'll have no other option but to modify your script so it uses .php files rather than .tpl files
-
Error page not processed if missing is folder without trailing /
wildteen88 replied to dbx's topic in Apache HTTP Server
To force a trailing slash at the end of the url use the following rewrite rule: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://www.yoursite.com/$1/ [R=301,L] Change http://www.yoursite.com to your actual sites address. -
Its to do with how you're including you files. Never start file paths with a / as this tells PHP to load the file from the root of the file system (not your sites document root). How I'd do what you're trying to achieve: <?php if(!isset($_SESSION['360net_id'])) { include '/page_include/login_layout.php'; } elseif(isset($_GET['page'])) { // list all pages that can requested by the user $requestable_pages = array( 'login_action', 'password_recover' ); $page_include_dir = $_SERVER['DOCUMENT_ROOT'] .'/page_include/'; if(in_array($_GET['page'], $requestable_pages)) { include $page_include_dir.$_GET['page'].'.php'; } } else { echo '<h1>404 Not Found</h1></BR> <h4 class="special">Not Found</h4>'; } ?>
-
Change this old code to a loop...help needed.
wildteen88 replied to smeguru's topic in PHP Coding Help
Kens original code should allow this. If your ini is set like this: [leftside] show=yes section1=search section2=tellafriend section3=reviewus section4=linkback Then kens code will be including/requesting for the following files: $_SERVER['DOCUMENT_ROOT']/shared-resources/sidesection.search.inc.php $_SERVER['DOCUMENT_ROOT']/shared-resources/sidesection.tellafriend.inc.php $_SERVER['DOCUMENT_ROOT']/shared-resources/sidesection.reviewus.inc.php $_SERVER['DOCUMENT_ROOT']/shared-resources/sidesection.linkback.inc.php In order for the code to work correctly ensure the path to the files are correct. -
Variable as the field name problem PHP/mysql
wildteen88 replied to danx30's topic in PHP Coding Help
If you fields named a1 .. to .. a12 and you're using the example code I made above Then you'd do: if(isset($_GET['id']) && is_numeric($_GET['id'])) { $id = 'a'.$_GET['id']; $query4 = "UPDATE users SET $id='1' WHERE name='$n1'"; // rest of code } -
New forums will only be made if there is much demand. There would be no point in creating a computer help forum if only a few posts/threads are posted a month/year. Anyway a computer help forum does not quite fit in seeing as we're a PHP support community. For now any computer related help would be better of within the Misc forum.
-
Variable as the field name problem PHP/mysql
wildteen88 replied to danx30's topic in PHP Coding Help
How does 12 get passed to the page? Via the url like filename.php?id=12 In which case to get the id from the url you'll use $_GET['id'] like so if(isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; $query4 = "UPDATE users SET $id='1' WHERE name='$n1'"; // rest of code } -
Variable as the field name problem PHP/mysql
wildteen88 replied to danx30's topic in PHP Coding Help
Well set $id to that particular field you wish to update. -
Or.. just post your current PHP configuration here. It is most probably something really simple.
-
Variable as the field name problem PHP/mysql
wildteen88 replied to danx30's topic in PHP Coding Help
Can you explain what you're trying to achieve with the query? I am not understanding you. -
Variable as the field name problem PHP/mysql
wildteen88 replied to danx30's topic in PHP Coding Help
The basic format for an UPDATE query is UPDATE table_name SET field_name=new value In order for it to function $id will HAVE to be set to a field name. What are you trying to do? What is $id set to? Maybe your query is supposed to be: $query4 = "UPDATE users SET id='$id' WHERE name='$n1'"; -
You'll also need PHP installed and setup with Apache. Have you done this yet? Also ensure you have saved your PHP code to file which ends in .php (eg filename.php NOT filename.html). Also to run your PHP code go to http://localhost/filename.php. Do not load the file directly into the browser (eg file:///C:\path\to\file.php) otherwise the PHP code will not work.
-
To manage MySQL databases you can use phpMyAdmin (this comes with WAMPServer). SQLiteManager is for SQLite databases only, these cannot be used with MySQL (or phpMyAdmin).
-
Change echo "<li"; if ($row['page_url'] == $uri) $class .= ' current_page_item'; echo " class=\"" . $class . "\""; To echo '<li class="' . $class . (($row['page_url'] == $uri) ? ' current_page_item' : null) . '"';
-
Umm, looking at the source code of your site. The PHP code is visible. Which means, 1. Your webhost/hosting account does not support PHP. Check this with your webhost. Or, 2. The file you have placed your PHP code in does not end in an .php extension, eg you have added the code to index.html rather than index.php. PHP code will only be parsed within .php files.
-
The maximum speed your visitors can downloaded from your server will be limited to your upload speed, not your download speed. I don't think Apache has anything to do with the download/upload speed. Its more to do with how your server is setup - hardware wise and how you're connected to the net by your ISP etc.
-
When using PHP code ensure you place it within PHP tags (<?php ?>) Also when using include you'll need to use the absolute/relative path to the file you're including, not just state the filename. In your case the path will be templates/stats.tpl <?php include 'templates/stats.tpl'; ?>
-
It is actually quite simple to do this. I'm assuming your users table has an id field $sql = 'SELECT id, username FROM users_table WHERE username='your_username'"; $result = mysql_query($result); $row = mysql_fetch_assoc($result); echo '<a href="profile.php?id='.$row['id'].'">View '.$row['username'].'\'s Profile</a>'; In profile.php to retrieve the id you'd use $_GET['id'] profile.php if(isset($_GET['id']) && is_numeric($_GET['id'])) { $user_id = (int) $_GET['id']; $sql = 'SELECT * FROM users_table WHERE id=$user_id"; $result = mysql_query($result); $row = mysql_fetch_assoc($result); echo '<pre>'.print_r($row, true).'</pre>'; }
-
By display do you mean have PHP code visible on the page? Or have PHP code run within a .tpl For the latter you can just use include to parse PHP code within a .tpl eg include 'file_with_php_code.tpl'; To display actual PHP code you'll need to convert it to HTML special chars, eg $php = '<?php echo "hello world"; ?>'; echo htmlentities($php, ENT_QUOTES);
-
To output text/HTML/JS/CSS etc you'll need to put it within an echo statement. Example <?php mysql_connect('localhost', 'your_mysql_username', 'your_mysql_password') or die(mysql_error()); mysql_select_db('your_mysql_database') or die(mysql_error()); // your query $sql = 'SELECT count(*) as TotalMovies FROM movies'; $result = mysql_query($sql or die(mysql_error()); // start HTML table echo '<table border="1" cellpadding="5" cellspacing="0"> <tr> <th>Total Movies</th> '; // get the total number of movies $row = mysql_fetch_assoc($result); // display TotalMovies within a table cell echo ' <td>'.$row['TotalMovies'].'</td>'; // end HTML table echo ' </tr> </table>'; ?>
-
Post your full code here.
-
You'd use an HTML table for that.
-
echo $row['count(*)']; should of been $row['TotalMovies'];
-
PHP doesn't understand SQL. You can just dump SQL code into a PHP script and expect it to work. You'll first need to connect to mysql server using mysql_connect, followed by mysql_select_db to use a MySQL database. To run your queries you'll use mysql_query. In order to retireve results from your query you'll use mysql_fetch_assoc. Altogether <?php mysql_connect('localhost', 'your_mysql_username', 'your_mysql_password') or die(mysql_error()); mysql_select_db('your_mysql_database') or die(mysql_error()); // your query $sql = 'SELECT count(*) as TotalMovies FROM movies'; $result = mysql_query($sql or die(mysql_error()); // get the total number of movies $row = mysql_fetch_assoc($result); echo $row['count(*)']; ?>
-
And line 3 is? You'll need to post the code you're using here.