Hi again i have tried searching google before pestering the good people of these forums again lol

(sorry guys)

But here is my problem

Basically i have a add a model form (for computers which has 3 fields manufacutere,model and comments) the variable for the dropdown menu is $manu and what i am trying to achieve is that when a user adds a model by submitting the form to the database that when it gets submitted that if for example entries DELL has a entry already PHP says that DELL already exists and no need to enter that but would still enter the details like the model number and the other fields.

The user has a drop down menu that has 3 manufacturers at the moment which are
DELL
COMPAQ
IBM
but seeing as these manufacturers have so many models available i just need the user to be able to post a model and choose a manufacturer.

i dont really know how to even start this query as i think it is more SQL statements which i am not very good with yet.

Many Thanks Pinky (p.s sorry for the looooonggg post!)

    i have attempted to work out the code for this feature and have some demo code which may shed some light onto what i am trying to do.

        <?php if (isset($update));

    $update = "INSERT INTO computers (manufacturer,type,model,comments) VALUES ('$POST[$manu]','$POST[type]','$POST[model]','$POST[comments]')";
    if (str($manu > 1)){echo "manufacturer already exists";}?>

      How are you going to keep track of which model belongs to which manufacturer if you don't record the two together or have a seperate database table for each manufacturer.

        i have 1 database named computers and 4 fields in that database named manufacturer,model,type,comments.
        The thinking behind my code i posted is that if a user inputs a already existing manufacturer then it would ignore the manufacturer part and input the rest
        or should i have a seperate database for each manufacturer ?

        Im not too sure how i go about this ?

        Am very grateful for your assistance rincewind 😃

        I wish i wasnt such a noob. lol
        THX

          i think i just worked it out if a user inputs a manufacturer php would detect which manufacturer they have entered and enter it into the relevant database so i guess that is how i would keep track of all the different models for each manufacturer?

          so having a db for each one is the way i guess?

            so the next question is how would i tell php that the user entered DELL or IBM hmmm
            <?php if (str($manu == "DELL","IBM","COMPAQ"));

              Not a database for each one BUT a table for each one, it's important to carefully think out what you want to do with the data long before you start coding, as a poorly designed DB structure will cause no end of problems when it comes to querying the database.

              If you are certain you are not going to need to change the data you have now I would suggest a table to list each manufacturer with fields for id and name at least, and think about any other data(contact info, website address) that you might add, and then a main data table with the id from the first table being a field in the second.

              This would let you join the two tables together and then run queries much easier.

                Pinkmischief wrote:

                so the next question is how would i tell php that the user entered DELL or IBM hmmm
                <?php if (str($manu == "DELL","IBM","COMPAQ"));

                No! Look at the swich() function or an if else
                like

                <?php
                if (strtoupper($manu) == 'IBM'){
                	//do something
                } elseif (strtoupper($manu) == 'DELL'){
                	//do something
                } elseif (strtoupper($manu) == 'COMPAQ'){
                	//do something
                } else // add a default condition like send to a page to add a new manufatcurer
                ?>

                  OK again thx your a star 🙂 i have designed the tables with the names compaq,dell,ibm and fields model ,type and comments

                  so i spose i could use a if statement so if the users input matches DELL it will select the correct table and insert the new models alonng with there comments :S

                  so now i have in total 4 tables a users table for obviously the users login details and 3 manufacturer tables as said above and you recommend having another with manufacturers and have fields for compaq,dell and ibm ?
                  I think that is what u explained sorry for being such a beginner at this 🙁.
                  if that is what u mean i have no idea how i would access a compaq table using a manufacturer field?

                  Thx again 😃

                    omg you make it clear to me now tytytyttytytytyttytytytytytytyty 🙂
                    I will try this out and let you know how i get on and if i can get it to work i will resolve this post.

                    Many Thanks Pinky

                      Hmm i thought i had it but it would appear not 🙁 this is the code i tried so each else statement inserts into a specific table it dont give me any errors now and it does not insert into the relevant databases when IBM or which ever is put into it :S
                      I thought it may be due to the insert into being in small letters so i tried capitalizing it on the IBM line and tried inserting a ibm test machine but it didnt work so i guess php isnt capitals sensitive ibm is the same as IBM.

                      Many Thanks for your help
                      <?php $query = mysql_select_db($database_connect, $connect);
                      if (!$query) echo "db not found!";?>
                      <?php if (isset($update));
                      if (strtoupper($manu) == 'IBM'){
                      "INSERT INTO ibm (model,type,comments) VALUES ('$POST[model]','$POST[type]','$POST[comments]'";}
                      elseif (strtoupper($manu) == 'DELL'){
                      "insert into dell (model,type,comments) values ('$
                      POST[model]','$POST[type]','$POST[comments]'";}
                      elseif (strtoupper($manu) == 'COMPAQ'){
                      "insert into Compaq (model,type,comments) values ('$POST[model]','$POST[type]','$_POST[comments]'";}
                      ?>

                        Try this

                        
                        <?php
                        error_reporting(E_ALL); //only disable this line when you have finished debugging and before it goes public
                        set_magic_quotes_runtime(0);
                        
                        $query = mysql_select_db($database_connect, $connect);
                        if (!$query) echo "db not found!".mysql_error();
                        
                        if (isset($update)); // what is this for?
                        
                        if (strtoupper($manu) == 'IBM'){
                        	$table = 'ibm';
                        }
                        elseif (strtoupper($manu) == 'DELL'){
                        	$table = 'dell';
                        }
                        elseif (strtoupper($manu) == 'COMPAQ'){
                        	$table = 'Compaq';
                        }
                        
                        $sql = sprintf("INSERT INTO ".$table." (model, type, comments) VALUES('%s', '%s', '%s')",
                        mysql_real_escape_string($_POST['model']),
                        mysql_real_escape_string($_POST['type']),
                        mysql_real_escape_string($_POST['comment']));
                        
                        $result = mysql_query($sql) or die(mysql_error());
                        if (!$result) print 'Unable to carry out the operation as requested, please try again.<br>If the problem persists please contact the webmaster';
                        ?>

                        What is this line for?

                        ?php if (isset($update));

                          Try this

                          
                          <?php
                          error_reporting(E_ALL); //only disable this line when you have finished debugging and before it goes public
                          set_magic_quotes_runtime(0);
                          
                          $query = mysql_select_db($database_connect, $connect);
                          if (!$query) echo "db not found!".mysql_error();
                          
                          if (isset($update)); // what is this for?
                          
                          if (strtoupper($manu) == 'IBM'){
                          	$table = 'ibm';
                          }
                          elseif (strtoupper($manu) == 'DELL'){
                          	$table = 'dell';
                          }
                          elseif (strtoupper($manu) == 'COMPAQ'){
                          	$table = 'Compaq';
                          }
                          
                          $sql = sprintf("INSERT INTO ".$table." (model, type, comments) VALUES('%s', '%s', '%s')",
                          mysql_real_escape_string($_POST['model']),
                          mysql_real_escape_string($_POST['type']),
                          mysql_real_escape_string($_POST['comment']));
                          
                          $result = mysql_query($sql) or die(mysql_error());
                          if (!$result) print 'Unable to carry out the operation as requested, please try again.<br>If the problem persists please contact the webmaster';
                          ?>

                          What is this line for?

                          ?php if (isset($update));

                          BTW you will have to do more checking of the incoming data for instance what happens when you have 2 entries for the same maker and model, one way to stop it would be to make the model no field in the database unique, but you would still need to check first to warn the user.

                            it is for the button which normally is submit which i changed to update so basically its for the submit button upon click of submit button do such a such or is that wrong ?

                              i Just input your code and it said this
                              Notice: Undefined variable: manu in c:\wamp\www\addnew.php on line 69

                              Notice: Undefined variable: manu in c:\wamp\www\addnew.php on line 72

                              Notice: Undefined variable: manu in c:\wamp\www\addnew.php on line 75

                              Notice: Undefined variable: table in c:\wamp\www\addnew.php on line 79

                              Notice: Undefined index: model in c:\wamp\www\addnew.php on line 80

                              Notice: Undefined index: type in c:\wamp\www\addnew.php on line 81

                              Notice: Undefined index: comment in c:\wamp\www\addnew.php on line 82
                              You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(model, type, comments) VALUES('', '', '')' at line 1

                              I think that this is too complicated for someone like myself who has basic knowledge of PHP...... 🙁 many thanks for all your help rincewind feel like im being a nuisance to you.

                                I forgot to mention i am using wamp webserver program would that make any difference?

                                I will see if i can work out what is happening with this code but thank you for your help again 😃

                                Please find below lines 69 -82

                                if (strtoupper($manu) == 'IBM'){
                                $table = 'ibm';
                                }
                                elseif (strtoupper($manu) == 'DELL'){
                                $table = 'dell';
                                }
                                elseif (strtoupper($manu) == 'COMPAQ'){
                                $table = 'Compaq';
                                }

                                $sql = sprintf("INSERT INTO ".$table." (model, type, comments) VALUES('%s', '%s', '%s')",
                                mysql_real_escape_string($POST['model']),
                                mysql_real_escape_string($
                                POST['type']),
                                mysql_real_escape_string($_POST['comment']));

                                  I noticed at the end of each mysql_real_Escape there is no ; i dunno if that was a type error or if it is meant to be that way because i thougth that each statement or function had to be ended with a ;

                                    you'll get those error/warning messages with that level of error reporting, it's nothing to worry about you just need to define the variables, why not post the whole page, then I would be able to suggest ways of removing those notices.

                                    As for the

                                    if (isset($update));

                                    it's not doing anything other than asking if it's set, it doesn't say what to do if it isn't.

                                    If I thought it was a nuisance I wouldn't answer 😃 or I would tell you so :evilgrin:

                                      Pinkmischief wrote:

                                      I noticed at the end of each mysql_real_Escape there is no ; i dunno if that was a type error or if it is meant to be that way because i thougth that each statement or function had to be ended with a ;

                                      No it's because it's a part of the sprintf() function and each argument of the function is delimited by a comma.

                                        ok i will post the whole page code
                                        for you then im sure that with your help i can crack this 😃