...

View Full Version : PHP Webpage Inputting HELP!!



Joemoemofo
07-17-2009, 11:12 PM
I had a question. First, I am going to start off and say that I am a complete PHP noob lol so bare with me. Anyways, I want to create something where all I do is login to a certain page (i guess sort of like a CMS but only one thing needed), and I can add for example, a business profile page already setup and formatted (templated in html, just missing the variables), all I need to do is add in certain things like a picture or maybe some google maps code for one variable and maybe some other information all in the seperate sections all on this one page. Then when I submit, it takes all of this and creates a .php file named by me in the creation page and uploads it to a certain folder where it is now viewable. How would I go about doing this and what is this called? I just need some basic information on it to research. PHP manual is no help, I figured professional coders like you guys would consider helping me. Its so confusing and if you have anymore questions I will be able to answer them.

Zangeel
07-17-2009, 11:31 PM
What you want to do is research the syntax and basics of all major functions. if conditionals, post, get, database setup, connections, etc. w3schools.com will get you around the basics.

Once you have all that down, coding is just concept. Think of what you want to do, and think of how to do it with the building blocks of knowledge you have.

For something like that, you'll wanta mysql (or any other databaste) driven website. This might make you want to research basic mysql.

But you'll have to create two tables.. one for users, the other for profiles.

I wouldnt create a file itself, I would enter the information, pictures, etc, into the database, then output it via get. You know, how normal profiles (myspace, facebook, etc) profiles are made, they arent physical files.

http://yoursite.com/profile.php?id=1

a url like that will show the first profile. On profile.php you'd have code like



$_GET['id'] = (int) $ID; // this is the variable in the url profile.php?id={THIS IS WHAT WE'RE GETTING}

$q = mysql_query("SELECT * FROM `profiles` WHERE `id` = $ID");
$row = mysql_fetch_assoc($q);


Now.. unless you understand the database design you might be confused. But basically, we're selecting all ROWS from the table named PROFILES, where the id is the id in the URL. So now we can display the data DYNAMICALLY based on the url.

So, if the rows in the table for profiles are like

Id
Name
Age
Gender

ID is the row that controls the bottom rows, so if we selected row 1 it would be like selected all the data under the first record.


id = 1 | name = john doe | age = 20 | gender = male

^so that's the information we selected in the mysql_query in the php code. Now to display it on the profile.php page, we use the mysql_fetch_assoc function to echo out the variables.

like this



$_GET['id'] = (int) $ID; // this is the variable in the url profile.php?id={THIS IS WHAT WE'RE GETTING}

$q = mysql_query("SELECT * FROM `profiles` WHERE `id` = $ID");
$row = mysql_fetch_assoc($q);

echo "

<table>
<tr>
<td>Name</td><td>$row['name']</td>
<tr>
<td>Age</td><td>$row['age']</td>
</tr>
<tr>
<td>Gender</td><td>$row['gender']</td>
</tr>
</tr>
</table>

";

So that's the basic structure. And the other things you want, like logins, and the page to input data for the profile im sure others can help with.

The login system, just add to the "user" table, an ID row (primary key) auto incriminate yadayada, username, and password rows. theres a bunch of tutorials for that kinda thing. Populate it with your username and pass you wanna use to login. Then use some mysql function like mysql_num_rows, and if conditionls to compare if the login n pass are in the database and if they match up. then add a session if they match, and you're logged in. (like i said theres tons of tuts on this)

the cms type page, just add a form to fill out the info, and once the form is filled insert the data into the profile database table, so it can be displayed on the profile.php page.

So that's really breif how to do this sort of thing. Learn the basics good, and post here when you get stuck on something or need some help, we can help step by step.

Joemoemofo
07-17-2009, 11:43 PM
Man your awesome! Very well constructed answer. Very understandable. I will thoroughly look into and if worst comes to worst I might hit someone up with some dough to finish it out.

Joemoemofo
07-18-2009, 05:43 AM
Been working on it, and looking through your post and had a few questions and comments. I do not want users (unless if thats for me to logon in the backend and edit or add profiles since its only going to be me). Is that what you meant? Also, how would I go about creating table necessary for my project? Still trying to grasp the knowledge and ability to do all of this at a low budget ha.

Joemoemofo
07-18-2009, 05:53 AM
How much would anyone charge to set this up for me? I am on a real tight budget and I am not smart when it comes to MySQL or PHP plus I don't have the time to piddle around since I have other things to accomplish that I know I can do myself haha. Let me know at joemoemofo@yahoo.com or leave a post.

Zangeel
07-18-2009, 09:40 AM
I'll send you a PM here on CF.

Joemoemofo
07-26-2009, 01:35 AM
Alright I decided to give this a shot, and I have all the forms and processing files made, now I'm having trouble displaying it. The information gets entered perfectly into the tables with id auto-incrementing, here's the code of my display file:


<?php

mysql_connect("xxxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxxx");
mysql_select_db("xxxxxxxxxx");

$_GET['id'] = (int) $ID; // this is the variable in the url profile.php?id={THIS IS WHAT WE'RE GETTING}

$q = mysql_query("SELECT * FROM `profile` WHERE `id` = $ID");
$row = mysql_fetch_assoc($q);

echo "

<table>
<tr>
<td>Name</td><td>$row['name']</td>
<tr>
<td>Age</td><td>$row['age']</td>
</tr>
<tr>
<td>Gender</td><td>$row['gender']</td>
</tr>
</tr>
</table>

";


The error comes up saying this when I browse the page:


Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/46/d2733/htdocs/c/stuff.php on line 15

Line 15 is the first $row['name']

What is the problem here? I've tried the "while" loops but I don't think that is what I want. I want to be able to display the contents of any row anywhere in the display file separately.

MattF
07-26-2009, 09:44 AM
echo '<table>
<tr>
<td>Name</td><td>'.htmlspecialchars($row['name']).'</td>
</tr>
<tr>
<td>Age</td><td>'.htmlspecialchars($row['age']).'</td>
</tr>
<tr>
<td>Gender</td><td>'.htmlspecialchars($row['gender']).'</td>
</tr>
</table>';

Joemoemofo
07-27-2009, 06:23 AM
now its just give my


$ID = $_GET['id'];

trouble by saying "Parse error: syntax error, unexpected T_STRING in blah blah/format.php on line 10"

Joemoemofo
07-27-2009, 07:36 AM
fixed it... nvm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum