SitePoint Sponsor

User Tag List

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

    First off, let me thank everyone who has helped me over the last few months regarding this area, thanx to you guys I have made alot of progress with my project!

    After reading Kevin's article on seesion management, I decided to include an if statement which will look to see if any of the required feilds in my submission form have been filled in, if they have not then the user asked to fill the form in again, pretty simple I know, but it seems I've made a 'simple' error with my code somewhere, I would appreciate if anybody could point out my error(s), here is the code:

    <?php

    /* This script will display a html form that allows new groups to be inserted into the 'Groups' table, which exists within the database 'Love_to_sing'. */

    if ($user_name=="" or $password=="" or $group_name=="") or $city=="") {
    error("One or more required fields were left blank.\\n".
    "Please fill them in and try again.");
    }

    if ($submit == "submit") {

    mysql_connect("localhost","root","castor");
    mysql_select_db("Love_to_sing");
    mysql_query("INSERT INTO groups SET
    ID='$ID', user_name='$user_name', password='$password',
    category='$category', group_name='$group_name', contact_name='$contact_name',
    region='$region', address='$address', post_Code='post_Code', city='$city',
    telephone='$telephone', fax='$fax', homepage='$homepage', email='$email', group_Information='$group_Information',
    conditions_of_joining='$conditions_of_joining'");

    echo "Thanx for your submission!";

    exit();





    }

    ?>

    The error message points to line '5'.

    Thanx very much!


    Koncise.

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simple:

    PHP Code:
    <?php 

    /* This script will display a html form that allows new groups to be inserted into the 'Groups' table, which exists within the database 'Love_to_sing'. */ 

    if ($user_name=="" or $password=="" or $group_name=="" or $city=="") { 
    error("One or more required fields were left blank.\\n"
    "Please fill them in and try again."); 


    if (
    $submit == "submit") { 

    mysql_connect("localhost","root","castor"); 
    mysql_select_db("Love_to_sing"); 
    mysql_query("INSERT INTO groups SET 
    ID='
    $ID', user_name='$user_name', password='$password', 
    category='
    $category', group_name='$group_name', contact_name='$contact_name', 
    region='
    $region', address='$address', post_Code='post_Code', city='$city', 
    telephone='
    $telephone', fax='$fax', homepage='$homepage', email='$email', group_Information='$group_Information', 
    conditions_of_joining='
    $conditions_of_joining'"); 

    echo 
    "Thanx for your submission!"

    exit(); 





    }
    You had a parenethasees (spelling?) where it ought not to have been in your IF statement.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx very much exbabylon, I entered the corrected code, yet it did not seem to solve the problem, after pressing the submit button I am presented with the following error message:

    Fatal error: Call to undefined function: error() in C:\phpdev2\www/Submit_love.php on line 6

    This again points to the if statement which ckecks for the required fields.

    Surely there must be an explanation for this?!?!


    Koncise!

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this.. just a thought:

    PHP Code:
    <?php 

    /* This script will display a html form that allows new groups to be inserted into the 'Groups' table, which exists within the database 'Love_to_sing'. */ 

    if ($user_name=="" or $password=="" or $group_name=="" or $city=="") { 
    echo(
    "One or more required fields were left blank. Please fill them in and try again."); 


    if (
    $submit == "submit") { 

    mysql_connect("localhost","root","castor"); 
    mysql_select_db("Love_to_sing"); 
    mysql_query("INSERT INTO groups SET 
    ID='
    $ID', user_name='$user_name', password='$password', 
    category='
    $category', group_name='$group_name', contact_name='$contact_name', 
    region='
    $region', address='$address', post_Code='post_Code', city='$city', 
    telephone='
    $telephone', fax='$fax', homepage='$homepage', email='$email', group_Information='$group_Information', 
    conditions_of_joining='
    $conditions_of_joining'"); 

    echo 
    "Thanx for your submission!"

    exit(); 





    }
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx again exbabylon.

    I noticed that you have left out the closing '?>' tag at the end of the script. Was this deliberate?

    I'll try out the code anyhow!

    Thank you!


    Koncise.

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have just tried the code!

    Now the if statement has been recocgnised, however it still allows the submition to go through despite the required feilds been left blank. I pressed 'submit' on the form and this it what it said:

    'One or more required fields were left blank. Please fill them in and try again.Thanx for your submission!'

    I checked the database and the submition had been made.
    Should I post up my original submition form? Perhaps there is some error there.


    thanx for helping,


    Koncise.

  7. #7
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no need... here's your problem-- You need to use an else statement.

    PHP Code:
    <?php 

    /* This script will display a html form that allows new groups to be inserted into the 'Groups' table, which exists within the database 'Love_to_sing'. */ 



    if ($submit == "submit") { 

    if (
    $user_name=="" or $password=="" or $group_name=="" or $city=="") { 
    echo(
    "One or more required fields were left blank. Please fill them in and try again."); 

    } else {
     
    mysql_connect("localhost","root","castor"); 
    mysql_select_db("Love_to_sing"); 
    mysql_query("INSERT INTO groups SET 
    ID='
    $ID', user_name='$user_name', password='$password', 
    category='
    $category', group_name='$group_name', contact_name='$contact_name', 
    region='
    $region', address='$address', post_Code='post_Code', city='$city', 
    telephone='
    $telephone', fax='$fax', homepage='$homepage', email='$email', group_Information='$group_Information', 
    conditions_of_joining='
    $conditions_of_joining'"); 

    echo 
    "Thanx for your submission!"
    }

    } else {
    echo(
    "No Action Specified.");
    }
    ?>
    That should do it! This is my preffered method, that way it can run with the rest of your pages with out exiting... and screwing up your code.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

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

    Much graditude exbabylon for taking the time to help me!

    However now I get an error message which says:

    Parse error: parse error, expecting `','' or `';'' in C:\phpdev2\www/Submit_love.php on line 24

    This is near the else statement nearer to the end of the script!!

    Koncise!!

  9. #9
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops... my bad... I'm not doing very good today am I?

    Oh well... here's the error... you need a semi-colon after the last echo:

    PHP Code:

    <?php 

    /* This script will display a html form that allows new groups to be inserted into the 'Groups' table, which exists within the database 'Love_to_sing'. */ 



    if ($submit == "submit") { 

    if (
    $user_name=="" or $password=="" or $group_name=="" or $city=="") { 
    echo(
    "One or more required fields were left blank. Please fill them in and try again."); 

    } else {
     
    mysql_connect("localhost","root","castor"); 
    mysql_select_db("Love_to_sing"); 
    mysql_query("INSERT INTO groups SET 
    ID='
    $ID', user_name='$user_name', password='$password', 
    category='
    $category', group_name='$group_name', contact_name='$contact_name', 
    region='
    $region', address='$address', post_Code='post_Code', city='$city', 
    telephone='
    $telephone', fax='$fax', homepage='$homepage', email='$email', group_Information='$group_Information', 
    conditions_of_joining='
    $conditions_of_joining'"); 

    echo(
    "Thanx for your submission!");
    }

    } else {
    echo(
    "No Action Specified.");
    }
    ?>
    there ye are!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

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

    I'll try that, hopefully it will work, I'll report back right away!!

    Koncise!

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

    The code works!!

    It successfully recognises any required fields where are left blank, pauses the submition and warns the user!!

    I intend to use this form as and registration + submition form all in one, this is because the user will have to enter values in the user name and password feilds within the form before they can make a submition!!!

    Thank you so much exbabylon.

    Eternal blessings to you and your loved ones....


    Koncise!

  12. #12
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not a problem... glad to be able to help someone like myself.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  13. #13
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    For the record, the reason the error() function was not working is that you did not include the definition of this function in your code, as described in my article.

    As defined there, the error() function will pop up the error message in a JavaScript pop-up window before automatically returning the user to the form so that he or she can correct the mistake.

    It's a nice little effect that you can make use of if you return to the article and obtain the code for the error() function.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  14. #14
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx Kevin,

    However could sombody tell me what is wrong with this simple SELECT statement please, because it's drivin' me mad!

    It's a select statement which shows all the groups within the region of North England.

    Here it is:

    <?php

    /* This script whill will select and display all the groups within the region of Bristol.

    This is done by:

    1) Connect to a database server
    2) Select a database
    3) Select a table and run a select query on it!

    The results are neatly presented in a table according to column and field names! */


    echo "Below are all the music groups within the Region of North Endland";
    echo "<p>";
    echo "The date is ";
    echo ( date("F dS Y.") );
    echo "<p>";

    //CONNECT TO DATABASE
    mysql_connect( "localhost", "root", "***") or die ("Couldn't connect to server");

    //SELECT DATABASE
    mysql_select_db( "Love_to_sing") or die ("Couldn't select database");

    //SELECT EVERYTHING IN Love_to_sing, ORDERED ALPHABETICALLY BY Category
    $result = mysql_query("SELECT group_name from Groups where region like North England") or die ("Couldn't execute query");


    //Start results formatting
    echo "<TABLE BORDER=8>";

    echo "<tr><th>group name</th></tr>";


    //PUT THE ROWS OF THE RESULT INTO AN ARRAY, THEN GO THROUGH ROW BY ROW, ECHOING WHAT IS IN EACH ONE
    while ($row = mysql_fetch_array($result) ) {


    $group_name = $row["group_name"];
    echo "<tr><td>$group_name</td></tr>";

    }

    echo "</TABLE>";

    ?>

    The error is definantly pointing to the SELECT staement, but I do not know what is actually wrong with it....I spent a long time yesterday going over it, I can't believe I still can't figure it out. I really did not want to bother u guys with such a simple query problem but I did'nt know what else to do!!

    Thank you very much.


    Koncise.

  15. #15
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_query("SELECT group_name from Groups where region like North England")

    North England is a string so enclose it in quote marks:

    mysql_query("SELECT group_name from Groups where region like 'North England' ")

  16. #16
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry sid didn't see your post till after mine.

    This line

    PHP Code:
    $result mysql_query("SELECT group_name from Groups where region like North England") or die ("Couldn't execute query"); 
    should be

    PHP Code:
    $result mysql_query("SELECT group_name from Groups where region like '%North England%'") or die ("Couldn't execute query"); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  17. #17
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    np freddy. As usual you come up with an improvement

    '%North*England%'

  18. #18
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx very much guys....1nce again!

    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
  •