www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Can anyone see whats wrong with this??

  1. #1
    Join Date
    Mar 2008
    Posts
    88

    resolved [RESOLVED] Can anyone see whats wrong with this??

    Hey guys,

    All this code below used to work! I then changed troop to group and since then its not been inputing into the database! I've debugged and all the information is coming through, its just not going into my database.


    Code:
    <form id="form1" name="form1" action="final.php" method="post">
    <p>All Boxes Required</p>
    
    <label>Email: </label> 
    	<input type="text" name="email" id="textfield" />
    <label>Group: </label> 
    	<input type="text" name="group" id="textfield" /> 
    <label>Organiser Name:  </label> 
    	<input type="text" name="name" id="textfield" /> 
    <label>Telephone/Mobile:  </label> 
    	<input type="text" name="telmob" id="textfield" />
    	
    <label> Place </label><input type="text" id="place" name="place" value="<?php echo $place; ?>"  />
    
    <label> Activity</label> <input type="text" id="activity" name="activity" value="<?php echo $act; ?>" /> 
    
    <label> Date Arriving </label><input id="datepicker" name="datearriving" value="" />
    
    <label> Date Leaving</label> <input id="datepicker2" name="dateleaving" value="" />
    
    
    <button type="submit" name="submit" value="submit">Apply</button>
    
    <button type="reset">Clear</button>
    and this is final.php


    Code:
    $dbname = 'name';
    mysql_select_db($dbname);
    
    $da = $_POST ["datearriving"];
    $dl = $_POST ["dateleaving"];
    $email = $_POST["email"];
    $group = $_POST["group"];
    $name = $_POST ["name"];
    $telmob = $_POST ["telmob"];
    $place = $_POST ["place"];
    $act = $_POST["activity"];
    
    
    
    if (isset($_POST['submit'])) {
    
    	//This makes sure they did not leave any fields blank
    	if (!$_POST['datearriving'] | !$_POST['dateleaving'] | !$_POST['email'] | !$_POST['group'] | !$_POST['name'] | !$_POST['telmob'] | !$_POST['place']| !$_POST['activity']) 
    	
    	{
    		header( 'refresh: 3; url=/scouts/index.php' );
    		die('You did not complete all of the required fields! Please wait...');
    	}
    	//checks if its an email address
    	if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
    		header( 'refresh: 3; url=/book1.php' );
    		die('Invalid Email Address! Please wait...');
    	}
    	
    	// now we insert it into the database
    $insert = "INSERT INTO activities (datearriving, dateleaving, email, group, name, tel, place, activity) VALUES ('".$da."','".$dl."','".$email."','".$group."','".$name."','".$telmob."','".$place."','".$act."')";
    
    	$add_activity = mysql_query($insert);
    Thanks to anyone he helps

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,388
    Have PHP/MySQL tell you what it thinks the problem is (assuming it's the query that is failing):
    PHP Code:
    $insert "INSERT INTO activities (datearriving, dateleaving, email, group, name, tel, place, activity) VALUES ('".$da."','".$dl."','".$email."','".$group."','".$name."','".$telmob."','".$place."','".$act."')";
    $add_activity mysql_query($insert);
    if(
    $add_activity == false) {
        
    $error mysql_error();
        die(
    "<pre>".$error."\n$insert</pre>");

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2008
    Posts
    88
    Thank you for replying... The error spat out this

    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 'group, name, tel, place, activity) VALUES ('11-7-2012','11-8-2012','swl7@gm' at line 1
    INSERT INTO activities (datearriving, dateleaving, email, group, name, tel, place, activity) VALUES ('11-7-2012','11-8-2012','swl7@gmail.com','groupsev','swl7','0987654321','ash','Archery range')

    The only thing I changed were the words troop to group then it started failing lol

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,388
    Try quoting the column name with "back tick" quotes, so that MySQL knows it's an identifier and not the keyword GROUP:
    Code:
    `group`
    (Or change the column name to something like "group_name" so that there can be no confusion.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Mar 2008
    Posts
    88
    Thank you that worked!!

    So are back quotes better to use than normal quotes?

    Thank you again I think I lost some hair over this lol

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,388
    They are for different purposes. The back-quotes are for "identifiers": table names, column names, and such. Regular "straight" quotes are for string literals, so those will still be used around actual text/character values.
    Code:
    INSERT INTO `my_table` (
      `col_1`,
      `col_2`,
      `col_3`
    ) VALUES (
      1234, -- integer column
      'This is a test.
    It is only a test', -- text column
      'fubar' -- varchar column
    );
    The back-quoting is optional when there is no name clashing with reserved words and the name itself does not have spaces or other normally invalid characters in it, but it never hurts to back-quote them, so many people just quote all identifiers for consistency.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Mar 2008
    Posts
    88
    Thank you for helping me understand it.

    Case Closed

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles