Everything posted by .ęνø.
-
PHP Code
Ok I've finally gotten back to this, lol. I think I'm really close to the working code right now. It's connecting to the database successfully, the $dyn_page variable is working fine, there aren't any typos, so I've put it up to something being wrong with the execution. Because it doesn't show anything. // in config.php $db_host = "***"; # host $db_name = "***"; # database name $db_user = "***"; # username $db_pass = "***"; # password // in functions.php $db_connect = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db($db_name,$db_connect); $dyn_page = isset($_GET['page']) ? $_GET['page'] : "home"; function show_content(){ $query = sprintf("SELECT content FROM a_main WHERE short='$dyn_page'", mysql_real_escape_string($dyn_page)); $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo $row['content']; } mysql_free_result($result); } // in index.php require_once("config.php"); require_once("functions.php"); show_content($dyn_page); Also, could someone confirm that this code is secure? Or could that be easily exploited?
-
Creating new pages + tables
Ok, I don't usually add people I don't know, but I'll send you my address for the sake of helpin you out a bit if I can (lol).
-
Creating new pages + tables
Still at 0 new messages. :\
-
Creating new pages + tables
No prob, but I didn't get no PM.
-
Keep geting Form SPAM
Your best bet is to try setting up reCAPTCHA. Best free anti-spam I've come across.
-
Creating new pages + tables
First you need to set the variable it using $_GET. eg. If I wanted to use "page" for the variable like index.php?page=1 I would use this. What it does exactly, is it checks if the variable in the URL is set, if it is set then it sets the page variable to whatever you had in the URL. If it isn't set in the URL it automatically sets it to "home". $page = isset($_GET['page']) ? $_GET['page'] : "home"; Then you can use that variable to dynamically show content based on the variable you have in the URL. The way I do it is I set a function, which calls for the page "$page.php" in the "content" folder. If it exists it includes the file, if it doesn't exist it shows a 404 page. My final code is this: $page = isset($_GET['page']) ? $_GET['page'] : "home"; function show_content($page){ $file = file_exists("content/$page.php") ? "content/$page.php" : "content/404.php"; require_once($file); } And to call it all I have to do is place "show_content($page)" wherever I want it to show up, and then whenever I go to "www.example.com/index.php?page=example" it would look for "www.example.com/content/example.php" and if it can't find it, it would show "www.example.com/content/404.php", BUT if I went to "www.example.com/index.php" it would show "www.example.com/content/home.php". It shouldn't take you too much to modify that code to suit your needs. Good luck! EDIT: I might eventually make this into a proper tutorial, lol.
-
Creating new pages + tables
Ok, I'll get back to you a bit later, I'm not at home at the moment.
-
Creating new pages + tables
Sorry for the bump - but if you still need help on the ?id=# thing I can give you a hand.
-
News viewer
What I meant was you could use a blog script to get a similar outcome, but I was looking at the wrong thing anyway I just realized, lol.
-
News viewer
If I'm looking at the right thing, it's a php powered script. I'd say look for a blog script if you want something similar.
-
PHP Code
Yeah I've done all the SQL stuff, I'll have another look at this tonight and see what I can do with it.
-
PHP Code
It's not working for me. :\ Here's what I got: function new_show_content(){ $db = mysql_connect(*,*,*); // put the right values/variables in here $page = mysql_escape_string($_GET['page']); // prevents SQL injection attacks $resultSet = mysql_query("SELECT content FROM mydb.pages WHERE page='$page'",$db); // do query $firstRow = mysql_fetch_row($resultSet); // get the first row, or FALSE if no rows available if($firstRow === FALSE) { /* No result, so do the 404 */ include("content/404.php"); } else { $content = $firstRow[0]; // [0] is the first entry, so is the value of the 'content' field in this row echo $content; // } }
-
PHP Code
That is pretty much correct. So if I were to go "www.example.com/index.php?page=home" it would call the database, then show table: pages, row: home, field: content. I'm really not sure about the row part. :s I'm not too good with SQL yet.
-
PHP Code
First thing I'll say is, I'm very comfortable with HTML, an intermediate PHP coder, and a beginner at SQL. Now, this is what I have functioning at the moment: Function that reads the page= variable in the URL, and displays "content/$page.php", but if it doesn't exist, it shows a 404. $dyn_page = isset($_GET['page']) ? $_GET['page'] : "home"; function show_content($dyn_page){ $dyn_file = file_exists("content/$dyn_page.php") ? "content/$dyn_page.php" : "content/404.php"; require_once($dyn_file); } Now, this is what I want to have functioning: Function that reads the page= variable in the URL, and calls upon an SQL database to echo "database name > pages > $page > content", but if it doesn't exist, it shows a 404. And a way to show a textbox to edit "database name > pages > $page > content". Then a way to generate a table row showing "database name > pages > (all) > title". Sorry if that sounds a bit complicated, lol.