Jump to content

PHP - Making a new webpage automatically?

Okay so far the test website I'm using allows for the following with PHP.

 

  • Login system
  • Events page which is loaded form a database. Add event for admin.
  • News page which is loaded form a database. Add news for admin.

 

So the events page and the news page shows the events in table one below the other.

 

What I would like is that when I create and event/news article a completely new webpage will be created with the events details in it. and from the events page there will be thumbnails that can be clicked and bring the user to that specific page.

 

I could let you see the site, although it could cause controversy.

Link to comment
https://linustechtips.com/topic/364792-php-making-a-new-webpage-automatically/
Share on other sites

Link to post
Share on other sites


<A href:"whateversite.com" target="blank">

</a>

~New~  BoomBerryPi project !  ~New~


new build log : http://linustechtips.com/main/topic/533392-build-log-the-scrap-simulator-x/?p=7078757 (5 screen flight sim for 620$ CAD)LTT Web Challenge is back ! go here  :  http://linustechtips.com/main/topic/448184-ltt-web-challenge-3-v21/#entry601004

Link to post
Share on other sites

<A href:"whateversite.com" target="blank"></a>
That was literally of no help.

Your explanation of your request/issue was literally of no help.

Is this a framework? Where did you get the script?

Can you show us the code?

--Neil Hanlon

Operations Engineer

Link to post
Share on other sites

Your explanation of your request/issue was literally of no help.

Is this a framework? Where did you get the script?

Can you show us the code?

 

The php was done by myself. 

 

Essentially what happens is the the php connects to a mysql database then the information is entered into a form, on which when submitted will be inserted into the database. I then have a php file were it gets all the information from the events table on the database and then from there table are created that hold the values from the database. 

Here is the website: http://orangelodge44.comuv.com/Events.php

Look at the events table. Those values are taken from the mysql database and each new record gets it's own table. What I really want is that when I create an event and all the data goes to the database, a completely new webpage will be created.

Link to post
Share on other sites

Can I see the DDL for your database? http://en.wikipedia.org/wiki/Data_definition_language

 

Essentially what you need to do is make it link to a page such as "event.php?id=123" where 123 is the event's ID in the database.

 

Then in your code, you grab that id using

$_GET['id']
and query the database to get the event where the ID = 123 (or w/e). If it returns nothing, treat the request as a 404. Otherwise, get the data, and show it to the user.

--Neil Hanlon

Operations Engineer

Link to post
Share on other sites

 

Can I see the DDL for your database? http://en.wikipedia.org/wiki/Data_definition_language

 

Essentially what you need to do is make it link to a page such as "event.php?id=123" where 123 is the event's ID in the database.

 

Then in your code, you grab that id using

$_GET['id']
and query the database to get the event where the ID = 123 (or w/e). If it returns nothing, treat the request as a 404. Otherwise, get the data, and show it to the user.

 

 

In regard to the bolded bit how would I achieve that and for it do still show all the rest of the standard page (navbar, footer  etc.) but have the content div just have the specific detail for that event_ID?

Link to post
Share on other sites

Create a page event.php. The url will contain a query string for the id of the event. The body of the page will contain code necessary to request that event from the database and render it into an html template which is served to the user. Simple stuff.

Link to post
Share on other sites

Create a page event.php. The url will contain a query string for the id of the event. The body of the page will contain code necessary to request that event from the database and render it into an html template which is served to the user. Simple stuff.

I get what you mean but I'm trying to think of how that will work with my setup :/

Link to post
Share on other sites

In regard to the bolded bit how would I achieve that and for it do still show all the rest of the standard page (navbar, footer  etc.) but have the content div just have the specific detail for that event_ID?

 

Your event.php would look something like this

<body>	<header>		//Your header code	</header>	<div id="eventContent">		<?php 			if(isset($_GET['id'])){				//mysql or mysqli escaping then set $_GET['id'] to something like $eventID				//query the database the same way you have been doing				//display the results of the query on the page			}else{				//If there isn't a query string ie everything after the question mark in the url				//do what you want here, maybe just receive the latest event by default			}		?>	</div>	<footer>		//Your footer code	</footer></body>

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

 

Your event.php would look something like this

<body>	<header>		//Your header code	</header>	<div id="eventContent">		<?php 			if(isset($_GET['id'])){				//mysql or mysqli escaping then set $_GET['id'] to something like $eventID				//query the database the same way you have been doing				//display the results of the query on the page			}else{				//If there isn't a query string ie everything after the question mark in the url				//do what you want here, maybe just receive the latest event by default			}		?>	</div>	<footer>		//Your footer code	</footer></body>

 

I see but I would still like the tables on my event page to remain but say when the title is clicked then they are brought to a newly created webpage were all the details are. 

Link to post
Share on other sites

I see but I would still like the tables on my event page to remain but say when the title is clicked then they are brought to a newly created webpage were all the details are. 

 

event.php, not events.php. Your listening stays, each title in the table will link to event.php along with the id of the event in the url query string.

Link to post
Share on other sites

 

Your event.php would look something like this

<body>	<header>		//Your header code	</header>	<div id="eventContent">		<?php 			if(isset($_GET['id'])){				//mysql or mysqli escaping then set $_GET['id'] to something like $eventID				//query the database the same way you have been doing				//display the results of the query on the page			}else{				//If there isn't a query string ie everything after the question mark in the url				//do what you want here, maybe just receive the latest event by default			}		?>	</div>	<footer>		//Your footer code	</footer></body>

Eww no. Why would you suggest using the mysql_ library? It's been obsolete for eleven years.

--Neil Hanlon

Operations Engineer

Link to post
Share on other sites

Essentially what you need to do is make it link to a page such as "event.php?id=123" where 123 is the event's ID in the database.

Then in your code, you grab that id using

$_GET['id']
and query the database to get the event where the ID = 123 (or w/e). If it returns nothing, treat the request as a 404. Otherwise, get the data, and show it to the user.

 

 

Whoa! Big red flag going up...

 

I haven't seen anyone here say anything about cleansing that VAR!

It needs mentioning that without cleansing your variables, using prepared statements or stored procedures, you are just opening your database up for SQL Injection abuse.

 

I highly recommend this as further reading.

http://php.net/manual/en/security.database.sql-injection.php

Link to post
Share on other sites

Whoa! Big red flag going up...

 

I haven't seen anyone here say anything about cleansing that VAR!

It needs mentioning that without cleansing your variables, using prepared statements or stored procedures, you are just opening your database up for SQL Injection abuse.

 

I highly recommend this as further reading.

http://php.net/manual/en/security.database.sql-injection.php

 

...

 

No shit. Really? </sarcasm>

 

 

 

Using prepared statements should be assumed in today's world.. especially since the mysql_ libraries (made for MySQL 4.1) are eleven years old. Yes. The data should be sanitized before being used--but that's a given.

--Neil Hanlon

Operations Engineer

Link to post
Share on other sites

No need to be sarcastic less you expect a sarcastic comment in return.

 

It bares saying even still, that even thoug the libraries are old, people learning them may not be familiar with the safety aspects.

Anyone very new to PHP and MySQL stumbling on this thread may assume (wrongly or not) that parsing the var directly to the database is OK, when the more experienced devs know otherwise.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×