SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Submition form

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all!

    I want to devise a simple form which will insert data into my database. However I'm experiencing problems connecting to the database. I fill in the various fields in the form and hit the submit button, however when I check that the data has actually been inserted into the database I find that nothing has been inserted at all.

    Below is the script which produces the form.

    Could somebody tell me whether there are any errors within the script?

    The name of the database is 'Music_groups'
    The name of the table 'groups'

    <HTML>
    <HEAD>
    <TITLE>Music Group admission script</TITLE>
    </HEAD>
    <BODY>

    <?php

    if ($submit == "submit") {

    mysql_connect("localhost","root","******");
    mysql_select_db("Music_groups");
    mysql_query("INSERT INTO groups SET
    Category='$Category, Group_name='$Group_name', Contact_name='$Contact_name',
    Address='$Address', City='$City', Telephone='$Telephone', E_mail='$E_mail',
    Information='$Information'");

    echo("Thanks for your submission!");

    exit();



    }

    ?>

    <form action="Submitmusic_groups.php" method="post">
    Category : <input type="text" Category="Category">
    Group_name : <input type="text" Group_name="Group_name">
    Contact_name : <input type="text" Contact_name="Contact_name">
    Address : <textarea Address="Address"></textarea>
    City : <input type="text" City="City">
    Telephone : <input type="text" Telephone="Telephone">
    E_mail : <input type="text" E_mail="E_mail">
    Information : <textarea Information="Information"></textarea>
    <input type="submit" name="submit" value="submit"

    </form>



    </BODY>
    </HTML>


    Thanx very much,

    Koncise.

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Koncise


    mysql_query("INSERT INTO groups SET
    Category='$Category, Group_name='$Group_name', Contact_name='$Contact_name',
    Address='$Address', City='$City', Telephone='$Telephone', E_mail='$E_mail',
    Information='$Information'");



    }

    You need to add in the ' after $category, so it will become:

    PHP Code:
    mysql_query("INSERT INTO groups SET 
    Category='
    $Category', Group_name='$Group_name', Contact_name='$Contact_name',
    Address='
    $Address', City='$City', Telephone='$Telephone', E_mail='$E_mail', 
    Information='
    $Information'"); 
    Hope that helps

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <form action="Submitmusic_groups.php" method="post">
    Category : <input type="text" Category="Category">
    Group_name : <input type="text" Group_name="Group_name">
    Contact_name : <input type="text" Contact_name="Contact_name">
    Address : <textarea Address="Address"></textarea>
    City : <input type="text" City="City">
    Telephone : <input type="text" Telephone="Telephone">
    E_mail : <input type="text" E_mail="E_mail">
    Information : <textarea Information="Information"></textarea>
    <input type="submit" name="submit" value="submit"

    </form>
    Additionaly, you haven't closed your last input tag:

    <input type="submit" name="submit" value="submit"

    should be

    <input type="submit" name="submit" value="submit">

    Also, within your input tags what's with the :
    Category="Category"
    Group_name="Group_name"
    Contact_name="Contact_name"

    Should this be

    name="Category"
    name="Group_name"
    name="Contact_name"

    etc, etc...

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for your help James, I corrected the script, however it still fails to successfully submit data into the database.

    I'm pulling my hair out here!

    It must be something else!

    Koncise.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh..I just noticed your reply freakysid, I'll do that right now.

    Thanx very much,

    K.

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this line:

    if ($submit == "submit") {

    Should be:

    if ($submit) {



    Try and tell me if it works!

    Peter

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pete, either one will work. I usually use your method, but the correct way would be the one he/she used.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, sorry, I didn't know, that is the way i always do them now.


    Soz...

    Pete

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey...it works now briliiant!!!!

    Below is the final script (for thos who wanna se it!);

    <HTML>
    <HEAD>
    <TITLE>Music Group admission script</TITLE>
    </HEAD>
    <BODY>

    <?php

    if ($submit == "submit") {

    mysql_connect("localhost","root","castor");
    mysql_select_db("Music_groups");
    mysql_query("INSERT INTO groups SET
    Category='$Category', Group_name='$Group_name', Contact_name='$Contact_name',
    Address='$Address', City='$City', Telephone='$Telephone', E_mail='$E_mail',
    Information='$Information'");

    echo("Thanks for your submission!");

    exit();



    }

    ?>

    <form action="Submitmusic_groups.php" method="post">
    Category : <input type="text" name="Category">
    Group_name : <input type="text" name="Group_name">
    Contact_name : <input type="text" name="Contact_name">
    Address : <textarea name="Address"></textarea>
    City : <input type="text" name="City">
    Telephone : <input type="text" name="Telephone">
    E_mail : <input type="text" name="E_mail">
    Information : <textarea name="Information"></textarea>
    <input type="submit" name="submit" value="submit">

    </form>





    </BODY>
    </HTML>


    Thanx u guys...thanx very much!

    K!

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Koncise.. you are james (from hiphopmusic's) mate, right?
    Good luck with your uni project! James is a mate from school

    Ok, well, I just wanted to say, you probably could have sorted the problem much more quickly if you had done the following:

    where you had:
    Code:
    if ($submit == "submit") { 
    
    mysql_connect("localhost","root","castor"); 
    mysql_select_db("Music_groups"); 
    mysql_query("INSERT INTO groups SET 
    Category='$Category', Group_name='$Group_name', Contact_name='$Contact_name', 
    Address='$Address', City='$City', Telephone='$Telephone', E_mail='$E_mail', 
    Information='$Information'"); 
    
    echo("Thanks for your submission!"); 
    
    exit(); 
    
    
    
    }
    It would have been better to do:
    Code:
    if ($submit == "submit") { 
    
    mysql_connect("localhost","root","castor"); 
    mysql_select_db("Music_groups"); 
    $insertdata = mysql_query("INSERT INTO groups SET 
    Category='$Category', Group_name='$Group_name', Contact_name='$Contact_name', 
    Address='$Address', City='$City', Telephone='$Telephone', E_mail='$E_mail', 
    Information='$Information'"); 
    
    
    //I WOULD PUT IN EXTRA CODE HERE
    echo("Thanks for your submission!"); 
    if (!$insertdata) { // if there is an error adding to the db
    echo("There was an error adding to the database<br>" . mysql_error() . "<br>"); //echo the error mysql found in the query
    } else {
    echo("Thanks for your submission!");
    }
    
    exit(); 
    
    
    }
    what I have done, is assigned the query to a variable.
    Then, using an if statement, i check to see if the query executed properly, basically!
    Much better for debugging.. yeah?

    -AJ

  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How ya doin' AJ, yes I'm Koncise from hiphopmusic!

    Thanx for the additional script, I'll be sure to try it out very soon!

    So u know James? What a guy he is!!!

    Thanx again for the help,



    Koncise.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •