I am lost!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
javiqq
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2008 9:15 am

I am lost!

Post by javiqq »

I'm a newbie and although I've worked with PHP before I've never developed code for dynamic websites. But I was recently hired (was unemployed for 6 months) for a job as a programmer analyst and one of my projects is to develop a complex dynamic website but I need help. I am completely lost. I need this job to pay the bills, but I'm completely lost!

my project is to develop a website that does the following:
  • Create a form that allows someone to upload data into the database
  • Allows someone to edit those entries
  • Dynamically generates a list of entries from a database, with a link to files or URLs for each entry
  • Allow visitors to order what they see (no CC's required)
  • Create a search feature for those entries by a word, category or audience
I think that's really hard. I have background in web development but not that deep into programming. All this has to be done by the end of this month. I'm currently reading the book PHP & MySQL for DUMMIES (like me) and taking small tutorials online and use the book as a reference.

But I'm really lost. I've learned how to create databases and tables within it. Don't even know where to start regarding coding.Can anyone with programming experience shed some light as to what I can do to get this started or at least tell me something that will give me hope because I'm really getting frusted. :oops:
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: I am lost!

Post by andyhoneycutt »

Well, you'll probably want to start by building a dummy table in the database and setup a dummy form and fool around with plugging data into the database through the form. After that, maybe tackle testing the issue of needing to update/edit the values in the database.

Once you have a simple understanding of how php interacts with mysql you may want to setup your project in earnest.

Do you know SQL at all? If not, I'd suggest reading a bit about SQL statements, then check the reference in the php.net manual regarding mysql functions. After a crash course on all that you should have at least a marginal understanding of what you're getting into and how to approach it.

-Andy
javiqq
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2008 9:15 am

Re: I am lost!

Post by javiqq »

Thanks for your reply Andy that really helped. I know some SQL. I also created a dummy database and already created a form. Now I need to tackle down the select/insert/delete/update commands between PHP and MySQL and how to actually make it come alive.

I downloaded a program called PHPMaker. Have you heard of it? Is it any good? Of course I'd like to code it myself, but I just think the length of time given to me to complete the project is too small because it requires too much coding, especially for someone new like me. Am I right or am I just getting overwhelmed?
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: I am lost!

Post by Stryks »

I haven't used PHPMaker, but I would probably suggest that your time would be better spent working on your own instead of using a code generator.

I mean, from a practical standpoint, it's probably going to be pretty obvious to anyone who looks that your code is not in fact your own. Given this is your task to complete, about the best you can hope to achieve is to convince your bosses that they can replace you with a piece of software.

From a more technical standpoint, you should create your own where possible, because at any given time you might need to jump in and change something or find the source of a problem, and you just aren't going to be able to do that with someone elses code. I can quite often spend ages looking at another coders perfectly valid code and just not *get* it because the coder a different style to my own. Doing that just starting out with some code of unknown quality ... well ... that would take me more time than just writing my own.

You have a great resource in this forum though, so you aren't alone. A quick search in here should turn up all the examples you could ever need for mysql queries and data handling, and anything you don't understand can usually be quickly explained by someone here.

Stay with it and try and get a bit of code under you to keep building on and learning from. But I think the best advice I can give is to be up front with your employers. I'm not saying you should tell them you feel lost or out of your depth or anything. But I certainly wouldn't try to act like all is well and then turn in something pumped out with PHPMaker. Your bosses are far more likely to cut you some slack and let you get up to speed than they are to discard you, and I think they'll be more understanding the earlier you tell them. Far better that they should know the state of play from the outset than disappoint them later on.

And the thing is, if you're willing to dive on in and take guidance, and be open about what you don't know, then there's no reason you cant be up to speed and churning out good quality code in a relatively short period of time.

That's the way I see it anyhow. You're the best judge of your own situation of course.

Cheers.
javiqq
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2008 9:15 am

Re: I am lost!

Post by javiqq »

I'm nervous and don't think I'll have enough time to create my own code taking in consideration my little experience with database driven websites. I don't want to loose my job but like you said I don't want to act like is all well and get screw my boss and the client because that'll def get me fired.

I don't know what to tell my boss without sounding like I'm lost.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: I am lost!

Post by papa »

The first three tasks are pretty basic and is what you often learn first when start learning PHP.

However the last two, specially the order functionality is nothing that you do quickly. Do the customer require the customer to login etc or how big is this project?
javiqq
Forum Newbie
Posts: 17
Joined: Wed Oct 29, 2008 9:15 am

Re: I am lost!

Post by javiqq »

It's a pretty big project because it's going to be used by a large audience and it's expected to grow big with time. I started the form so users can enter information about the school materials and it was going fine until I noticed the sections with dynamic check boxes are missing the first option on the list from mysql. This is the script I'm using overall, but the checkbox script is highlighted in red:
<?php
include("../Connections/connect.php");

$lables = array( "first_name" => "First name",
"last_name" => "Last name",
"title" => "Title",
"affiliation" => "Affiliation",
"uni" => "Uni",
"center" => "Institution",
"street_addr" => "Address*",
"city" => "City",
"state" => "State",
"zip_code" => "Zip code",
"email" => "Email",
"entry_date" => "Date",
"prod_title" => "Product Title",
"description" => "Description",
"annotation" => "Annotation",
"topics" => "Broad Topics",
"material" => "Material",
"comp" => "Comp",
"yesorno" => "Conti",
"target" => "target",
"url_html" => "HTML Link",
"url_flash" => "Flash link",
"url_pdf" => "PDF Link",
"url_powerpoint" => "PowerPoint URL");

$query = "SELECT * from dbt_spk";
$result = mysqli_query($cnx,$query);
$row = mysqli_fetch_assoc($result);

$stquery = "SELECT * from dbt_st";
$result2 = mysqli_query($cnx,$stquery);
$row2 = mysqli_fetch_assoc($result2);

$topquery = "SELECT DISTINCT topics FROM dbt_top ORDER BY top";
$result3 = mysqli_query($cnx,$topquery);
$row3 = mysqli_fetch_assoc($result3);

$catquery = "SELECT DISTINCT material_type FROM dbt_materials ORDER BY materials";
$result4 = mysqli_query($cnx,$catquery);
$row4 = mysqli_fetch_assoc($result4);

$compquery = "SELECT DISTINCT comp_level FROM dbt_comp ORDER BY comp";
$result5 = mysqli_query($cnx,$compquery);
$row5 = mysqli_fetch_assoc($result5);

$contiquery = "SELECT DISTINCT yesorno FROM dbt_conti ORDER BY yesorno";
$result6 = mysqli_query($cnx,$contiquery);
$row6 = mysqli_fetch_assoc($result6);

$urlquery = "SELECT * FROM dbt_url";
$result7 = mysqli_query($cnx,$urlquery);
$row7 = mysqli_fetch_assoc($result7);

echo "<div align='center'>";
echo "<h3>Update resource information below</h3>";
echo "<form action='checkupdate.php?update' method='POST'><table>\n
<tr><td class='required_fields'>$lables[first_name] </td><td> <input type='text' name='first_name' value='$row[first_name]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[last_name] </td><td> <input type='text' name='last_name' value='$row[last_name]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[title] </td><td> <input type='text' name='title' value='$row[title]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[affiliation] </td><td> <input type='text' name='affiliation' value='$row[affiliation]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[uni] </td><td> <input type='text' name='uni' value='$row[uni]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[center] </td><td> <input type='text' name='center' value='$row[center]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[street_addr] </td><td> <input type='text' name='street_addr' value='$row[street_addr]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[city] </td><td> <input type='text' name='city' value='$row[city]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='required_fields'>$lables[state] </td><td> <select name'state'><option value='No database selected' selected>Select a state";

//build state list
while($row2 = mysqli_fetch_assoc($result2))
{
extract($row2);
echo "<option value'$row[states]'>$row2[states]";
}

echo "</select></td></tr>";
echo "<tr><td class='required_fields'>$lables[zip_code] </td><td> <input type='text' name='zip_code' value='$row[zip_code]' size='11' maxlength='11'> </td></tr>\n
<tr><td class='required_fields'>$lables[email] </td><td> <input type='text' name='email' value='$row[email]' size='30' maxlength='30'> </td></tr>\n
<tr><td class='body' >$lables[entry_date] </td><td>";

$monthName = array(1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$today = time(); //stores today's date
$f_today = date("M-d-Y",$today); //format today's date
#echo "Today is $f_today\n";

//selection list for month
$todayMO = date("n",$today); //get the month from $today
echo "<select name='dateMO'>\n";
for($n=1;$n<=12;$n++)
{
echo "<option value=$n\n";
if ($todayMO == $n)
{
echo " Selected";
}
echo "> $monthName[$n]\n";
}
echo "</select>\n";

//selection list for the day
$todayDay = date("d",$today);
echo "<select name='dateDay'>\n"; //get the day from $today
for($n=1;$n<31;$n++)
{
echo " <option value=$n";
if ($todayDay == $n)
{
echo " Selected";
}
echo "> $n\n";
}
echo "</select>";

//selection list for the day
$startYr = date("Y",$today); //get the year from $today
echo "<select name='dateYr'>\n";
for($n=$startYr;$n<=$startYr+3;$n++)
{
echo " <option value=$n";
if($startYr == $n)
{
echo " Selected";
}
echo "> $n\n";
}
echo "</select></td></tr>\n";

echo "<tr><td class='required_fields'>$lables[prod_title] </td><td> <input type='text' name='prod_title' value='$row[prod_title]' size='50' maxlength='100'> </td></tr>\n
<tr><td class='required_fields' valign='top'>$lables[description]</td><td><textarea name='zip_code' rows='4' cols='38'>$row[description]</textarea> </td></tr>\n
<tr><td class='required_fields'>$lables[annotation] </td><td> <input type='text' name='anotation' value='$row[annotation]' size='30' maxlength='30'> </td></tr>\n
<tr><td colspan='2'><hr></hr></td></tr>";

//building checkboxes for topics
echo "<tr><td class='required_fields' valign='top'>$lables[topics] </td><td class='checkboxes'>";

while ($row3 = mysqli_fetch_assoc($result3))
{
extract($row3);
echo "<input type='checkbox' name='$row[topics]' value='$row3[topics]'>$row3[topics]<br>\n";
}
echo "</td></tr>\n";

//building checkboxes for material
echo "<tr><td class='required_fields' valign='top'>$lables[material] </td><td class='checkboxes'>";

while ($row4 = mysqli_fetch_assoc($result4))
{
extract($row4);
echo "<input type='checkbox' name='$row[material]' value='$row4[material]'>$row4[material_type]<br>\n";
}
echo "</td></tr>\n";

//build the comp
echo "<tr><td class='required_fields' valign='top'>$lables[competency_level] </td><td class='checkboxes'>";

while ($row5 = mysqli_fetch_assoc($result5))
{
extract($row5);
echo "<input type='checkbox' name='$row[comp]' value='$row5[comp]'>$row5[comp]<br>\n";
}
echo "</td></tr>\n";

//build the conti
echo "<tr><td class='required_fields' valign='top'>$lables[conti] </td><td class='checkboxes'>";

while ($row6 = mysqli_fetch_assoc($result6))
{
extract($row6);
echo "<input type='checkbox' name='$row[yesorno]' value='$row6[yesorno]'>$row6[yesorno]<br>\n";
}
echo "</td></tr>\n";

echo "<tr><td class='required_fields'>Resource URL</td></tr><tr><td></td></tr>

<tr><td class='checkboxes' align='right'>$lables[url_html]*</td><td> <input type='text' name='$row[url_html]' value='$row7[url_html]' size='50' maxlength='255'> </td></tr>\n

<tr><td class='checkboxes' align='right'>$lables[url_pdf] </td><td> <input type='text' name='$row[url_pdf]' value='$row7[url_pdf]' size='50' maxlength='255'> </td></tr>\n

<tr><td class='checkboxes' align='right'>$lables[url_flash]</td><td> <input type='text' name='$row[url_flash]' value='$row7[url_flash]' size='50' maxlength='255'> </td></tr>\n

<tr><td class='checkboxes' align='right'>$lables[url_powerpoint]</td><td> <input type='text' name='$row[url_powerpoint]' value='$row7[url_powerpoint]' size='50' maxlength='255'> </td></tr>\n";

echo "</table></div>";
?>
It's working fine but like I said, it's not picking up the first item in the table from the db.

For now the only person login into the website is the person responsible for entering all necessary data. But eventually all users will most likely have to register and have their own logins so we can keep track of who uploaded what. Something I need help with is how to INSERT into the database all data from the form once the user clicks on submit.


papa...if you can give me suggestions on how to go about the page, i'd really appreciate it. I'm new to this so any help is very much appreciate it.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: I am lost!

Post by andyhoneycutt »

Inserting data from an end-user or any other untrusted source requires you to be cautious with your data handling. You will need to escape data that you plan on inserting to help avoid SQL-Injection attacks (where an malicious user prematurely closes your SQL statements and appends one of their own). There is a good function for doing this, but will require you to be connected to your database: mysql_real_escape_string(<string_to_escape>,<database_link>). You are able to access the values of the user's input on whichever landing page you have created as an action for your form. If you are using a "post" form, you are able to access the values of the form through php's $_POST global. If you're using an "get" action, similarly you'll use the $_GET global in your php.

I am by no means an expert when it comes to data security, but you should take some time to read up on SQL-Injection to help prevent your data (by that I mean your customer's data) from being compromised.

-Andy
Post Reply