Jump to content

PHP Database Application


lightnb

Recommended Posts

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


Link to comment
Share on other sites

[!--quoteo(post=346608:date=Feb 16 2006, 08:24 PM:name=lightnb)--][div class=\'quotetop\']QUOTE(lightnb @ Feb 16 2006, 08:24 PM) [snapback]346608[/snapback][/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) [snapback]346608[/snapback][/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.
Link to comment
Share on other sites

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


Link to comment
Share on other sites

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.

[code]<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>[/code]

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.
Link to comment
Share on other sites

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:

[code]
<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>[/code]

In hopes that it would be that simple, but it seems that the syntax is different for the second line?
Link to comment
Share on other sites

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:

[code]
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]
[/code]

and this is what I'd like to do:

[code]
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]

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


Link to comment
Share on other sites

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
Link to comment
Share on other sites

-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
Link to comment
Share on other sites

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)
[code]
$select = "SELECT <fieldname> FROM $table";
$select_query($select, $mysql_link)
     or die("Couldn't select <fieldname>".mysql_error() );
$id = mysql_num_rows($select_query);
[/code]

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
Link to comment
Share on other sites

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

<?

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



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


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

[/code]



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
Link to comment
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.