Jump to content


Photo

PHP Database Application


  • Please log in to reply
14 replies to this topic

#1 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 17 February 2006 - 01:24 AM

I want to add a database application to my site, but don't know where to start.

Here's what i want it to do:

I want people to be able to submit via a form interface, information about a particular item. For example:

Name: my item
Make: My Manufacturer
Model: My Model
Color: blue
Length: 5"
Height: 7'
Width: 2 miles

And so on.

The fields would be specific based on the type of item submitted, ie.. The form would have a pull down box to select the type of item.

For example if the type is "microphone",

Then the form changes to reflect the type of properties a microphone has:

Manufacturer: Shure
Model: SM58
Pickup pattern: cardiod


The items in the "type" pull down box would be pre-created, as with their associated fields.

Once the form is submitted, the system needs to check:

(1) If all required fields are complete
(2) If the item specified is already in the database

Next, it should post the new item to SQL for storage.



To retrieve items, the user can search for all "microphones" whose manufacturer= "shure", (using a form) and it will return all entries who match the search criteria on a results page.

if the user clicks on the title link on the results page, a new page should be dynamically generated that looks very much like a "myspace" profile for the item. it lists, in a predefined layout, all of the states and statistics of the item, as well as includes a picture and links to additional pictures.


Is there an application that does this? How hard would this be for me to write?

Thanks,

Nick




#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 February 2006 - 03:12 AM

[!--quoteo(post=346608:date=Feb 16 2006, 08:24 PM:name=lightnb)--][div class=\'quotetop\']QUOTE(lightnb @ Feb 16 2006, 08:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Is there an application that does this?
[/quote]

What your asking for is pretty specific, so, probably not.

[!--quoteo(post=346608:date=Feb 16 2006, 08:24 PM:name=lightnb)--][div class=\'quotetop\']QUOTE(lightnb @ Feb 16 2006, 08:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How hard would this be for me to write?
[/quote]

Not very. You have some options for showing the specific input fields based on which type of item is selected...

You could use javascript and write all of the form fields out, then just change the content of a div based on the selected item.

Or, if you are concerned about your users having to download a massive form (cause all of them would have to be on that page at the same time, just hidden, execpt for the one they selected), you could use ajax to go up to the server and retrieve the inputs.

Or, you could make it a two step process. Step one (page one), get the item type. Step two (page two), based on the item type, display a certain page.

The last one would be easiest. All it takes is a little html and very little php. The second is probably hardest because of the ajax and most people's fear of it.

No, I won't write it for you, but if you need help with your code, I'll offer advice for what you post in the forum.

#3 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 17 February 2006 - 08:54 PM

Ok, so I guess the first step would be for me to create an input form, and get it to post correctly to SQL.

I've seen some sites before where options can be added dynamically, for example when you choose "united States" it adds a field for "state".

What language should i script in?

Do I build the form in HTML? or do I have to use something else?

Thanks,

nick




#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 February 2006 - 09:07 PM

Yes, build the form in html.

When it displays a field based on another selection...like you described with selecting US and displaying an input for State...it is controlled by Javascript.

<script type="text/javascript">
function showinput(country) {
  if (country == 1) {
    document.getElementById('addfield').innerHTML = 'State: <input type="text" name="state">';
  } else if (country == 2) {
    document.getElementById('addfield').innerHTML = 'Province: <input type="text" name="prov">';
  }
}
</script>

<form>
<select name="country" id="country" onchange="javascript: showinput(document.getElementById('country').selectedIndex)">
<option></option>
<option>US</option>
<option>Canada</option>
</select>
<div id="addfield"></div>
</form>

That's not perfect code by any means, but you get the idea. If you know what the values are, then you can set up catches so that certain things are displayed or not displayed when the user makes a choice.

#5 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 17 February 2006 - 09:19 PM

Ok, i get how that works. what if i want to add more than one action as the result of a choice?

ie. if the user chooses "US" it asks for state, city and zip code, in three seperate fields?


changing the code to read:

<script type="text/javascript">
function showinput(country) {
  if (country == 1) {
    document.getElementById('addfield').innerHTML = 'State: <input type="text" name="state">';
  } else if (country == 2) {
    document.getElementById('addfield').innerHTML = 'Province: <input type="text" name="prov">';
    document.getElementById('addfield').innerHTML = 'State: <input type="text" name="state">';
    
  }
}
</script>

<form>
<select name="country" id="country" onchange="javascript: showinput(document.getElementById('country').selectedIndex)">
<option></option>
<option>US</option>
<option>Canada</option>
</select>
<div id="addfield"></div>
</form>

In hopes that it would be that simple, but it seems that the syntax is different for the second line?

#6 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 February 2006 - 10:25 PM

Add the additional html inside of the single quotes for that value:
document.getElementById('addfield').innerHTML = 'State: <input type="text" name="state"><br />Zip: <input type="text" name="zip">';


#7 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 19 February 2006 - 01:07 AM

I am currently working on building the form in Java/HTML.

I noticed that if the HTML thats in the ' ' marks isn't all one long line, then it ceases to function.

This makes coding extremely difficult, since its all one big clump of code. Is there any way to make it work using multiple lines?

for examle, this is what I'm doing that works:

if (geartype == 0) {
    document.getElementById('addfield').innerHTML = 'Make: <input class="pink" type="text" size="3" name="make"><br>Model: <input type="text"  size="3" name="model"><br>Type: <select name="mictype size="5" id="mictype"><option>Hand Held Vocal</option><option>Instrument</option><option>Body Mic (clip on, over ear, etc.)</option><option>PCM/PZM/Border Mic</option><option>Shotgun</option><option>Other Type/Specialty</option></select><br>Transducer Type: <select name="transducertype" id="transducertype"><option>Dynamic</option><option>Condeser</option><option>Piezo-Electric</option><option>Carbon</option><option>Other or Specialty</option></select><BR>Polar Pattern: <select name="polarpattern" id="polarpattern"><option>Omni-directional</option><option>Bi-Directional</option><option>Cardiod</option><option>Super 
Cardiod</option><option>Hyper Cardiod</option><option>User Selectable</option><option>Other/Specialty</option></select><br>Frequency Response: <input type="text" name="minfr"> Min. <input type="text" size="3" name="maxfr"> Max <br>Max SPL: <input type="text" size="3" name="Max SPL">Db<br><input class="red" type="Submit" Value="submit">';[code][quote]

and this is what I'd like to do:

if (geartype == 0) {
    document.getElementById('addfield').innerHTML = 'Make: 

<input class="pink" type="text" size="3" name="make"><br>

Model: <input type="text"  size="3" name="model"><br>

Type: <select name="mictype size="5" id="mictype">
<option>Hand Held Vocal</option>
<option>Instrument</option>
<option>Body Mic (clip on, over ear, etc.)</option>
<option>PCM/PZM/Border Mic</option>
<option>Shotgun</option>
<option>Other Type/Specialty</option></select><br>

Transducer Type: <select name="transducertype" id="transducertype">
<option>Dynamic</option>
<option>Condeser</option>
<option>Piezo-Electric</option>
<option>Carbon</option>
<option>Other or Specialty</option></select><BR>

Polar Pattern: <select name="polarpattern" id="polarpattern">
<option>Omni-directional</option>
<option>Bi-Directional</option>
<option>Cardiod</option>
<option>Super Cardiod</option>
<option>Hyper Cardiod</option>
<option>User Selectable</option>
<option>Other/Specialty</option></select><br>

Frequency Response: <input type="text" name="minfr"> Min
input type="text" size="3" name="maxfr"> Max <br>

Max SPL: <input type="text" size="3" name="Max SPL">Db<br>

<input class="red" type="Submit" Value="submit">';

But the second option doesn't work. aparently having carage returns makes it cease to function.

are there any tricks to get around this?

Thanks,

Nick




#8 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 20 February 2006 - 10:43 PM

Ok, I have my HTML table done.

When the user clicks "submit" it needs to check all fields to make sure they are there, and then print the results on a confirmation page, where the user can verify the information and then actually submit it.

First, how do I check to make sure the fields are completed, and second, how do I make the confirmation page work?


Thanks,

Nick

#9 birdie

birdie
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationBirmingham UK

Posted 20 February 2006 - 10:59 PM

i recommend php which would also help the sql input at the end.

do something like

<?
$input = $_POST['input'];
if($input == "hello")
{
//valid
}
else
{
exit("Not valid");
}
?>


#10 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 20 February 2006 - 11:03 PM

Where would that go? as part of the submit button? or on the next page?

the form is on a .php page.

#11 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 26 February 2006 - 08:43 AM

-And also, how do i make it somewhat inteligent? some fields, such as max SPL should be a number and contain no letters, some should be letters only, some should be both.

It should also assign a number to the entry, that the user does not see. the number should be the next unused number, and is used to identify the item even if the name changes.

thanks,

Nick

#12 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 26 February 2006 - 10:15 PM

hi lightnb

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Where would that go? as part of the submit button? or on the next page?

the form is on a .php page.[/quote]

since your form page is on a .php page and (im assuming) your varification page is also .php, you can have it on either, I would probably do it on the form page myself, but that's just me.

use empty() to see if the field is empty
ereg() to see if they're all numbers
!ereg() to make sure there are no numbers

and as for the id number, you can use this (Im assuming you're entering these into a database)
$select = "SELECT <fieldname> FROM $table";
$select_query($select, $mysql_link)
     or die("Couldn't select <fieldname>".mysql_error() );
$id = mysql_num_rows($select_query);

you can use any field as long as there is any entry for every row and
since id numbers start at 0, and mysql_num_rows starts at 1, you don't have to add one

hope it helps
got a problem? Google helps many of those in need

#13 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 01 March 2006 - 08:06 PM



Thanks.

How do you tell it to execute the code, when the submit button is pushed?

#14 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 01 March 2006 - 08:20 PM

I put this at the bottom of the form page, after the footer:

<?

if($transducertype != empty())
{
//valid
}
else
{
exit("Not valid");
}



if($polarpattern != empty())
{
//valid
}
else
{
exit("Not valid");
}


if($minfr == ereg())
{
//valid
}
else
{
exit("Not valid");
}
?>




I'm not sure how to make it execute when the button is pushed, how to post the data to itself?, and whether or not my syntax is correct.




Thanks,

Nick

#15 lightnb

lightnb
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 26 March 2006 - 11:32 PM

bump





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users