SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Whats wrong with this SQL query?

    Here is the PHP page that I am having problems with. What I would like to do is have the user fill out the form and it will be added to the table 'waybills' within the database called 'globemaster'.

    PHP Code:
    <?php
    include ('config.php');
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "[url="http://www.w3.org/TR/html4/loose.dtd"]http://www.w3.org/TR/html4/loose.dtd[/url]">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" media="all" href="admin.css" />
    </head>
    <body>
    <?PHP
     
    if (isset($_POST['submit'])):
     
    //bill added
     //using form below
    $dbcnx = @mysql_connect("$host""$user""$pass");
    if (!
    $dbcnx) {
     echo( 
    '<p>Unable to connect to the ' 
       
    'database server at this time.</p>' );
      exit();
     }
    $billnum $_POST['billnum'];
    $route $_POST['route'];
    $arrivaldate $_POST['year'] . "-" $_POST['month'] . "-" $_POST['day']; 
    $weight $_POST['weight'];
    $units $_POST['units'];
    $comments $_POST['comments'];
    $status "None";
    $sql "INSERT INTO waybills SET
      billnum='
    $billnum',
      route='
    $route',
      arrivaldate='
    $arrivaldate',
      status='
    $status',
      units='
    $units',
      weight='
    $weight',
      comments='
    $comments'";
     if (
    mysql_query($sql)) {
      echo (
    '<p>Waybill Added</p>');
     } else {
      echo (
    '<p>Error adding waybill: ' .
       
    mysql_error() . '</p>');
     }
    ?>
    <?PHP
     
    else: // allow user to enter waybill
    ?>
    <table id="maintable">
      <tr>
        <td><table id="bodytable">
          <tr>
            <td class="blank">&nbsp;</td>
            <td><div id="head">Globemaster Cargo Management System</div></td>
          </tr>
          <tr>
            <td class="adminnav"><table class="adminnavtable">
              <tr>
                <td id="navheadbg"><div id="navhead">Flight Management</div> </td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="viewbills.php">View Waybills</a></li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="addbill.php">Add Waybill </a></li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="editbills.php">Change Waybill Status</a> </li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="deletebill.php">Delete Waybill</a> </li>
                </ul></td>
              </tr>
            </table></td>
            <td><div id="welcome">Enter Waybill Information:</div>
        <table id="viewbills">
      <tr>
        <td><form action="<?=$_SERVER['PHP_SELF']?>" method="post">
          <table class="addtable">
            <tr>
              <td width="109" class="addleftcell">Waybill Number: </td>
              <td colspan="3"><input type="text" name="billnum" class="textfield"></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Route:</td>
              <td colspan="3"><input type="text" name="route" class="textfield"> 
                Example: Edmonton to Fort St. John </td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Arrival Date: </td>
              <td width="101"><select name="month" class="listmenu">
                <option selected>Month</option>
                <option value="01">January</option>
                <option value="02">February</option>
                <option value="03">March</option>
                <option value="04">April</option>
                <option value="05">May</option>
                <option value="06">June</option>
                <option value="07">July</option>
                <option value="08">August</option>
                <option value="09">September</option>
                <option value="10">October</option>
                <option value="11">November</option>
                <option value="12">December</option>
              </select></td>
              <td width="70"><select name="day" class="listmenu">
                <option selected>Day</option>
                <option value="01">01</option>
                <option value="02">02</option>
                <option value="03">03</option>
                <option value="04">04</option>
                <option value="05">05</option>
                <option value="06">06</option>
                <option value="07">07</option>
                <option value="08">08</option>
                <option value="09">09</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15">15</option>
                <option value="16">16</option>
                <option value="17">17</option>
                <option value="18">18</option>
                <option value="19">19</option>
                <option value="20">20</option>
                <option value="21">21</option>
                <option value="22">22</option>
                <option value="23">23</option>
                <option value="24">24</option>
                <option value="25">25</option>
                <option value="26">26</option>
                <option value="27">27</option>
                <option value="28">28</option>
                <option value="29">29</option>
                <option value="30">30</option>
                <option value="31">31</option>
              </select></td>
              <td width="184"><select name="year" class="listmenu">
                <option value="2004" selected>2004</option>
                <option value="2005">2005</option>
                <option value="2006">2006</option>
              </select></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Weight:</td>
              <td colspan="3"><input name="weight" type="text" class="textfield" size="7" maxlength="7"> 
                kg</td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Units:</td>
              <td colspan="3"><select name="units" class="listmenu">
                <option value="1" selected>1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
              </select> 
                Number of units on this waybill </td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Comments:</td>
              <td colspan="3"><textarea name="comments" cols="50" rows="4" class="textfield"></textarea></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3"><input type="submit" name="Submit" value="Add Waybill"></td>
            </tr>
          </table>
        </form></td>
      </tr>
    </table>
              </td>
          </tr>
        </table></td>
      </tr>
    </table>
    <table id="copyright">
      <tr>
        <td>Content Management system created by <a href="[email="sputza@shaw.ca"]mailto:sputza@shaw.ca">Steven[/email] Watkins</a>.</td>
      </tr>
    </table>
    <?PHP endif; ?>
    </body>
    </html>
    However, when the user submits the form nothing happens... the page just reloads and when I check the database there is no change.

    Please help. Thanks in advance.
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would help if you included a dump for your table. Other users can the try your code an identify the problem. Whilst your code looks ok if this for is for public submission I would add escaping of certain chars to certain fields just in case.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    I think I just spotted your error. You have no $_POST['submit'] field. Even if you did it would be better to give it a value also. Try the code below. Form now has hidden field with value equal to auth. I hav'nt tried this but should work now. Any further probs please post table dump.



    PHP Code:
    if ((isset($_POST["submit"])) && ($_POST["submit"] == "auth")) {
    //bill added
    //using form below
    $dbcnx = @mysql_connect("$host""$user""$pass");
    if (!
    $dbcnx) {
    echo( 
    '<p>Unable to connect to the ' 
       
    'database server at this time.</p>' );
      exit();
    }
    $billnum $_POST['billnum'];
    $route $_POST['route'];
    $arrivaldate $_POST['year'] . "-" $_POST['month'] . "-" $_POST['day']; 
    $weight $_POST['weight'];
    $units $_POST['units'];
    $comments $_POST['comments'];
    $status "None";
    $sql "INSERT INTO waybills SET
      billnum='
    $billnum',
      route='
    $route',
      arrivaldate='
    $arrivaldate',
      status='
    $status',
      units='
    $units',
      weight='
    $weight',
      comments='
    $comments'";
    if (
    mysql_query($sql)) {
      echo (
    '<p>Waybill Added</p>');
    } else {
      echo (
    '<p>Error adding waybill: ' .
       
    mysql_error() . '</p>');
    }
    ?> 
    PHP Code:
    <?PHP
    else: // allow user to enter waybill
    ?>
    <table id="maintable">
      <tr>
        <td><table id="bodytable">
          <tr>
            <td class="blank">&nbsp;</td>
            <td><div id="head">Globemaster Cargo Management System</div></td>
          </tr>
          <tr>
            <td class="adminnav"><table class="adminnavtable">
              <tr>
                <td id="navheadbg"><div id="navhead">Flight Management</div> </td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="viewbills.php">View Waybills</a></li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="addbill.php">Add Waybill </a></li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="editbills.php">Change Waybill Status</a> </li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="deletebill.php">Delete Waybill</a> </li>
                </ul></td>
              </tr>
            </table></td>
            <td><div id="welcome">Enter Waybill Information:</div>
        <table id="viewbills">
      <tr>
        <td><form action="<?=$_SERVER['PHP_SELF']?>" method="post">
          <table class="addtable">
            <tr>
              <td width="109" class="addleftcell">Waybill Number: </td>
              <td colspan="3"><input type="text" name="billnum" class="textfield"></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Route:</td>
              <td colspan="3"><input type="text" name="route" class="textfield"> 
                Example: Edmonton to Fort St. John </td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Arrival Date: </td>
              <td width="101"><select name="month" class="listmenu">
                <option selected>Month</option>
                <option value="01">January</option>
                <option value="02">February</option>
                <option value="03">March</option>
                <option value="04">April</option>
                <option value="05">May</option>
                <option value="06">June</option>
                <option value="07">July</option>
                <option value="08">August</option>
                <option value="09">September</option>
                <option value="10">October</option>
                <option value="11">November</option>
                <option value="12">December</option>
              </select></td>
              <td width="70"><select name="day" class="listmenu">
                <option selected>Day</option>
                <option value="01">01</option>
                <option value="02">02</option>
                <option value="03">03</option>
                <option value="04">04</option>
                <option value="05">05</option>
                <option value="06">06</option>
                <option value="07">07</option>
                <option value="08">08</option>
                <option value="09">09</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15">15</option>
                <option value="16">16</option>
                <option value="17">17</option>
                <option value="18">18</option>
                <option value="19">19</option>
                <option value="20">20</option>
                <option value="21">21</option>
                <option value="22">22</option>
                <option value="23">23</option>
                <option value="24">24</option>
                <option value="25">25</option>
                <option value="26">26</option>
                <option value="27">27</option>
                <option value="28">28</option>
                <option value="29">29</option>
                <option value="30">30</option>
                <option value="31">31</option>
              </select></td>
              <td width="184"><select name="year" class="listmenu">
                <option value="2004" selected>2004</option>
                <option value="2005">2005</option>
                <option value="2006">2006</option>
              </select></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Weight:</td>
              <td colspan="3"><input name="weight" type="text" class="textfield" size="7" maxlength="7"> 
                kg</td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Units:</td>
              <td colspan="3"><select name="units" class="listmenu">
                <option value="1" selected>1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
              </select> 
                Number of units on this waybill </td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Comments:</td>
              <td colspan="3"><textarea name="comments" cols="50" rows="4" class="textfield"></textarea></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell"><input type="hidden" value="auth">td>
              <td colspan="3"><input type="submit" name="Submit" value="Add Waybill"></td>
            </tr>
          </table>
        </form></td>
      </tr>
    </table>
              </td>
          </tr>
        </table></td>
      </tr>
    </table>
    <table id="copyright">
      <tr>
        <td>Content Management system created by <a href="mailto:sputza@shaw.ca">Steven Watkins</a>.</td>
      </tr>
    </table>
    <?PHP endif; ?>
    </body>
    </html>

  4. #4
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I will try it when I get back to my Dev pc. Thanks again.
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  5. #5
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I tried it and this is the error I got:
    Parse error: parse error, unexpected T_ELSE in c:\program files\apache group\apache\htdocs\globemaster\admin\addbill.php on line 55
    What does this mean and how can I fix it? Thanks!
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post you table dump.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo ('<p>Error adding waybill: ' 
    The syntax error is here on line 55 as it says.
    Try

    PHP Code:
    echo ('<p>Error adding waybill:</p>'); 

  8. #8
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that and it didnt work. This is the line that SQL says is causing the problem"

    PHP Code:
      else: // allow user to enter waybill 
    Thanks for the help so far.
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if (mysql_query($sql)) {
    echo ('<p>Waybill Added</p>');
    } else {
    echo ('<p>Error adding waybill: </p>');
    mysql_error()
    }
    ?>

    This forum appear to have altered code from copy and paste. This is correct. It would help if you posted tables then I could try locally on my machine. Im unwilling to sit a make the database and tables. Rplace the last few lines with that above.

  10. #10
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have made a few changes. Here is the code again. I will also have the sql table below:

    PHP Code:
     <?PHP
    if ((isset($_POST["submit"])) && ($_POST["submit"] == "auth")) { 
     
    //bill added
     //using form below
    $dbcnx = @mysql_connect("$host""$user""$pass");
    if (!
    $dbcnx) {
     echo( 
    '<p>Unable to connect to the ' 
       
    'database server at this time.</p>' );
      exit();
     }
    $billnum $_POST['billnum'];
    $route $_POST['route'];
    $arrivaldate $_POST['year'] . "-" $_POST['month'] . "-" $_POST['day']; 
    $weight $_POST['weight'];
    $units $_POST['units'];
    $comments $_POST['comments'];
    $status "None";
    $sql "INSERT INTO waybills SET
      billnum='
    $billnum',
      route='
    $route',
      arrivaldate='
    $arrivaldate',
      status='
    $status',
      units='
    $units',
      weight='
    $weight',
      comments='
    $comments'";
     if (
    mysql_query($sql)) {
      echo (
    '<p>Waybill Added</p>');
     } else {
      echo (
    '<p>Error adding waybill: ' mysql_error() . '</p>');
     }
     else: 
    // allow user to enter waybill
    ?>
    Code:
     +-------------+---------------+------+-----+------------+----------------+
    | Field	   | Type		  | Null | Key | Default	| Extra		  |
    +-------------+---------------+------+-----+------------+----------------+
    | id		  | int(11)	   |	  | PRI | NULL	   | auto_increment |
    | billnum	 | varchar(100)  |	  |	 |			|				|
    | route	   | longtext	  |	  |	 |			|				|
    | arrivaldate | date		  |	  |	 | 0000-00-00 |				|
    | status	  | varchar(100)  |	  |	 |			|				|
    | units	   | int(11)	   |	  |	 | 0		  |				|
    | weight	  | decimal(10,0) |	  |	 | 0		  |				|
    | comments	| varchar(100)  |	  |	 |			|				|
    +-------------+---------------+------+-----+------------+----------------+
    Thanks for being such a big help so far
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  11. #11
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post dump from phpmyadmin/ then I can quicly dump the tables. Command is US to me.

  12. #12
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    # Host: localhost
    # Database: globemaster
    # Table: 'waybills'
    # 
    CREATE TABLE `waybills` (
    `id` int(11) NOT NULL auto_increment,
    `billnum` varchar(100) NOT NULL default '',
    `route` longtext NOT NULL,
    `arrivaldate` date NOT NULL default '0000-00-00',
    `status` varchar(100) NOT NULL default '',
    `units` int(11) NOT NULL default '0',
    `weight` decimal(10,0) NOT NULL default '0',
    `comments` varchar(100) NOT NULL default '',
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM;
    Just create a database called globemaster. I didnt have phpmyadmin installed. Thanks!
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  13. #13
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php require_once('yourconn.php'); ?>
    <?php
    function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
                
    $theValue = ($theValue != "") ? "'" date("Y-m-d",strtotime($theValue)) . "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["postform"])) && ($_POST["postform"] == "auth")) {
      
    $insertSQL sprintf("INSERT INTO waybills (billnum, route, units, arrivaldate, weight, comments) VALUES (%s, %s, %s, %s, %s)",
                           
    GetSQLValueString($_POST['billnum'], "text"),
                           
    GetSQLValueString($_POST['route'], "text"),
                           
    GetSQLValueString($_POST['units'], "text"),
                           
    GetSQLValueString($_POST['month']"-"$_POST['day']"-"$_POST['year'], "text"),
                           
    GetSQLValueString($_POST['weight'], "text"),
                           
    GetSQLValueString($_POST['comments'], "text"));

      
    mysql_select_db($database_conn$conn);
      
    $Result1 mysql_query($insertSQL$conn) or die(mysql_error());
       
      }
    echo 
    "<p>Waybill Added</p>"

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>

     
    <table id="maintable"> 
      <tr> 
        <td><table id="bodytable"> 
          <tr> 
            <td class="blank">&nbsp;</td> 
            <td><div id="head">Globemaster Cargo Management System</div></td> 
          </tr> 
          <tr> 
            <td class="adminnav"><table class="adminnavtable"> 
              <tr> 
                <td id="navheadbg"><div id="navhead">Flight Management</div> </td> 
              </tr> 
              <tr> 
                <td class="navbg"><ul> 
                  <li class="navoptions"><a href="viewbills.php">View Waybills</a></li> 
                </ul></td> 
              </tr> 
              <tr> 
                <td class="navbg"><ul> 
                  <li class="navoptions"><a href="addbill.php">Add Waybill </a></li> 
                </ul></td> 
              </tr> 
              <tr> 
                <td class="navbg"><ul> 
                  <li class="navoptions"><a href="editbills.php">Change Waybill Status</a> </li> 
                </ul></td> 
              </tr> 
              <tr> 
                <td class="navbg"><ul> 
                  <li class="navoptions"><a href="deletebill.php">Delete Waybill</a> </li> 
                </ul></td> 
              </tr> 
            </table></td> 
            <td><div id="welcome">Enter Waybill Information:</div> 
        <table id="viewbills"> 
      <tr> 
        <td><form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1"> 
          <table class="addtable"> 
            <tr> 
              <td width="109" class="addleftcell">Waybill Number: </td> 
              <td colspan="3"><input type="text" name="billnum" class="textfield" /></td> 
            </tr> 
            <tr> 
              <td class="addleftcell">&nbsp;</td> 
              <td colspan="3">&nbsp;</td> 
            </tr> 
            <tr> 
              <td class="addleftcell">Route:</td> 
              <td colspan="3"><input type="text" name="route" class="textfield" /> 
                Example: Edmonton to Fort St. John </td> 
            </tr> 
            <tr> 
              <td class="addleftcell">&nbsp;</td> 
              <td colspan="3">&nbsp;</td> 
            </tr> 
            <tr> 
              <td class="addleftcell">Arrival Date: </td> 
              <td width="101"><select name="month" class="listmenu"> 
                <option selected="selected">Month</option> 
                <option value="01">January</option> 
                <option value="02">February</option> 
                <option value="03">March</option> 
                <option value="04">April</option> 
                <option value="05">May</option> 
                <option value="06">June</option> 
                <option value="07">July</option> 
                <option value="08">August</option> 
                <option value="09">September</option> 
                <option value="10">October</option> 
                <option value="11">November</option> 
                <option value="12">December</option> 
              </select></td> 
              <td width="70"><select name="day" class="listmenu"> 
                <option selected="selected">Day</option> 
                <option value="01">01</option> 
                <option value="02">02</option> 
                <option value="03">03</option> 
                <option value="04">04</option> 
                <option value="05">05</option> 
                <option value="06">06</option> 
                <option value="07">07</option> 
                <option value="08">08</option> 
                <option value="09">09</option> 
                <option value="10">10</option> 
                <option value="11">11</option> 
                <option value="12">12</option> 
                <option value="13">13</option> 
                <option value="14">14</option> 
                <option value="15">15</option> 
                <option value="16">16</option> 
                <option value="17">17</option> 
                <option value="18">18</option> 
                <option value="19">19</option> 
                <option value="20">20</option> 
                <option value="21">21</option> 
                <option value="22">22</option> 
                <option value="23">23</option> 
                <option value="24">24</option> 
                <option value="25">25</option> 
                <option value="26">26</option> 
                <option value="27">27</option> 
                <option value="28">28</option> 
                <option value="29">29</option> 
                <option value="30">30</option> 
                <option value="31">31</option> 
              </select></td> 
              <td width="184"><select name="year" class="listmenu"> 
                <option value="2004" selected="selected">2004</option> 
                <option value="2005">2005</option> 
                <option value="2006">2006</option> 
              </select></td> 
            </tr> 
            <tr> 
              <td class="addleftcell">&nbsp;</td> 
              <td colspan="3">&nbsp;</td> 
            </tr> 
            <tr> 
              <td class="addleftcell">Weight:</td> 
              <td colspan="3"><input name="weight" type="text" class="textfield" size="7" maxlength="7" /> 
                kg</td> 
            </tr> 
            <tr> 
              <td class="addleftcell">&nbsp;</td> 
              <td colspan="3">&nbsp;</td> 
            </tr> 
            <tr> 
              <td class="addleftcell">Units:</td> 
              <td colspan="3"><select name="units" class="listmenu"> 
                <option value="1" selected="selected">1</option> 
                <option value="2">2</option> 
                <option value="3">3</option> 
                <option value="4">4</option> 
                <option value="5">5</option> 
                <option value="6">6</option> 
                <option value="7">7</option> 
                <option value="8">8</option> 
                <option value="9">9</option> 
              </select> 
                Number of units on this waybill </td> 
            </tr> 
            <tr> 
              <td class="addleftcell">&nbsp;</td> 
              <td colspan="3">&nbsp;</td> 
            </tr> 
            <tr> 
              <td class="addleftcell">Comments:</td> 
              <td colspan="3"><textarea name="comments" cols="50" rows="4" class="textfield"></textarea></td> 
            </tr> 
            <tr> 
              <td class="addleftcell">&nbsp;</td> 
              <td colspan="3"><span class="addleftcell">
                <input name="postform" type="hidden" value="auth" />
              </span></td> 
            </tr> 
            <tr> 
              <td class="addleftcell">          </td>
              <td colspan="3"><input type="submit" name="Submit" value="Add Waybill" /></td> 
            </tr> 
          </table> 
          <input type="hidden" name="MM_insert" value="form1" />
        </form></td> 
      </tr> 
    </table> 
              </td> 
          </tr> 
        </table></td> 
      </tr> 
    </table> 
    <table id="copyright"> 
      <tr> 
        <td>Content Management system created by <a href="mailto:sputza@shaw.ca">Steven Watkins</a>.</td> 
      </tr> 
    </table> 

    </body> 
    </html>

  14. #14
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would now add some validation to the form elements to ensure details are entered correctly.

  15. #15
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Holy! Is that the best way to do this? Im scared!

    Thanks man. Is this 100% ready to copy and paste?
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  16. #16
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would be on yourconn.php? Im lost. Sorry for being dumb at this... Im still fresh.

    Any more help would be great!
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  17. #17
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just change conn to your connection in these lines.

    PHP Code:
    mysql_select_db($database_conn$conn); 
     
    $Result1 mysql_query($insertSQL$conn) or die(mysql_error()); 
    And use the include link at the top of the page to link to your connection.

  18. #18
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Query help needed ASAP! Thanks!

    Im so very lost. Here is my most up-to-date code:
    PHP Code:
     <?php
    include ('config.php');
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "[url="http://www.w3.org/TR/html4/loose.dtd"]http://www.w3.org/TR/html4/loose.dtd[/url]">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title><? $addbilltitle ?></title>
    <link rel="stylesheet" type="text/css" media="all" href="admin.css" />
    </head>
    <body>
    <?PHP
    $dbcnx 
    = @mysql_connect("$host""$user""$pass");
    if (!
    $dbcnx) {
     echo( 
    '<p>Unable to connect to the ' 
       
    'database server at this time.</p>' );
      exit();
     }
    if ((isset(
    $_POST["submit"])) && ($_POST["submit"] == "auth")) { 
     
    //bill added
     //using form below
     
    $billnum $_POST['billnum'];
    $route $_POST['route'];
    $arrivaldate $_POST['year'] . "-" $_POST['month'] . "-" $_POST['day']; 
    $weight $_POST['weight'];
    $units $_POST['units'];
    $comments $_POST['comments'];
    $status "None";
    $sql "INSERT INTO waybills SET
      billnum='
    $billnum',
      route='
    $route',
      arrivaldate='
    $arrivaldate',
      status='
    $status',
      units='
    $units',
      weight='
    $weight',
      comments='
    $comments'";
     if (
    mysql_query($sql)) {
      echo (
    '<p>Waybill Added</p>');
     } else {
      echo (
    '<p>Error adding waybill: ' mysql_error() . '</p>');
     }
     else: 
    // allow user to enter waybill
    ?>
    <table id="maintable">
      <tr>
        <td><table id="bodytable">
          <tr>
            <td class="blank">&nbsp;</td>
            <td><div id="head">Globemaster Cargo Management System</div></td>
          </tr>
          <tr>
            <td class="adminnav"><table class="adminnavtable">
              <tr>
                <td id="navheadbg"><div id="navhead">Flight Management</div> </td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="viewbills.php">View Waybills</a></li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="addbill.php">Add Waybill </a></li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="editbills.php">Change Waybill Status</a> </li>
                </ul></td>
              </tr>
              <tr>
                <td class="navbg"><ul>
                  <li class="navoptions"><a href="deletebill.php">Delete Waybill</a> </li>
                </ul></td>
              </tr>
            </table></td>
            <td><div id="welcome">Enter Waybill Information:</div>
        <table id="viewbills">
      <tr>
        <td><form action="<?=$_SERVER['PHP_SELF']?>" method="post">
          <table class="addtable">
            <tr>
              <td width="109" class="addleftcell">Waybill Number: </td>
              <td colspan="3"><input type="text" name="billnum" class="textfield"></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Route:</td>
              <td colspan="3"><input type="text" name="route" class="textfield"> 
                Example: Edmonton to Fort St. John </td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Arrival Date: </td>
              <td width="101"><select name="month" class="listmenu">
                <option selected>Month</option>
                <option value="01">January</option>
                <option value="02">February</option>
                <option value="03">March</option>
                <option value="04">April</option>
                <option value="05">May</option>
                <option value="06">June</option>
                <option value="07">July</option>
                <option value="08">August</option>
                <option value="09">September</option>
                <option value="10">October</option>
                <option value="11">November</option>
                <option value="12">December</option>
              </select></td>
              <td width="70"><select name="day" class="listmenu">
                <option selected>Day</option>
                <option value="01">01</option>
                <option value="02">02</option>
                <option value="03">03</option>
                <option value="04">04</option>
                <option value="05">05</option>
                <option value="06">06</option>
                <option value="07">07</option>
                <option value="08">08</option>
                <option value="09">09</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15">15</option>
                <option value="16">16</option>
                <option value="17">17</option>
                <option value="18">18</option>
                <option value="19">19</option>
                <option value="20">20</option>
                <option value="21">21</option>
                <option value="22">22</option>
                <option value="23">23</option>
                <option value="24">24</option>
                <option value="25">25</option>
                <option value="26">26</option>
                <option value="27">27</option>
                <option value="28">28</option>
                <option value="29">29</option>
                <option value="30">30</option>
                <option value="31">31</option>
              </select></td>
              <td width="184"><select name="year" class="listmenu">
                <option value="2004" selected>2004</option>
                <option value="2005">2005</option>
                <option value="2006">2006</option>
              </select></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Weight:</td>
              <td colspan="3"><input name="weight" type="text" class="textfield" size="7" maxlength="7"> 
                kg</td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Units:</td>
              <td colspan="3"><select name="units" class="listmenu">
                <option value="1" selected>1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
              </select> 
                Number of units on this waybill </td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">Comments:</td>
              <td colspan="3"><textarea name="comments" cols="50" rows="4" class="textfield"></textarea></td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td class="addleftcell">&nbsp;</td>
              <td colspan="3"><input type="submit" name="Submit" value="Add Waybill"></td>
            </tr>
          </table>
        </form></td>
      </tr>
    </table>
              </td>
          </tr>
        </table></td>
      </tr>
    </table>
    <table id="copyright">
      <tr>
        <td>Content Management system created by <a href="[email="sputza@shaw.ca"]mailto:sputza@shaw.ca">Steven[/email] Watkins</a>.</td>
      </tr>
    </table>
    <?PHP endif; ?>
    </body>
    </html>
    What happens when the code is ran is mysql produces an error:
    Parse error: parse error, unexpected T_ELSE in c:\program files\apache group\apache\htdocs\globemaster\admin\addbill.php on line 51
    It looks like the else statement is causing the problem. My code is just a modified version on Kevin Yank's code from his book "Build you own datebase driven website using PHP & MySQL" 2nd edition on page 98 and 99. If anyone knows how to get this to work that would be great. Thanks so much to all who have helped me so far and to those who help in the future.

    PS: Sorry for the large amounts of code... I just post it all cause the SQL error isnt accurate on the error line number half the time.
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  19. #19
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here you have to add the closing curly brace, since it's missing:
    PHP Code:
    //-- [...]
    if ((isset($_POST["submit"])) && ($_POST["submit"] == "auth"))

        //-- [...]
     
        if (mysql_query($sql))
        {
            echo ('<p>Waybill Added</p>');
        } 
        else
        {
            echo ('<p>Error adding waybill: ' . mysql_error() . '</p>');
        }
    //-- here it's missing
    }
    //-- and now get rid of that darn old way of writing using : and ;
    //-- or use it throughout your script and don't mix it!!!
    else // allow user to enter waybill
    {
        //-- [...]
     
    <?PHP ?>
    </body>
    </html>
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  20. #20
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to add another closing brace in the line above
    PHP Code:
    else: // allow user to enter waybill 
    Make sure all your brackets are properly closed...

  21. #21
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my edited version:

    PHP Code:
    //-- [...]
    <?PHP
    $dbcnx 
    = @mysql_connect("$host""$user""$pass");
    if (!
    $dbcnx) {
     echo( 
    '<p>Unable to connect to the ' 
       
    'database server at this time.</p>' );
      exit();
     }
    if ((isset(
    $_POST["submit"])) && ($_POST["submit"] == "auth")) 

     
    //bill added
     //using form below
     
    $billnum $_POST['billnum'];
    $route $_POST['route'];
    $arrivaldate $_POST['year'] . "-" $_POST['month'] . "-" $_POST['day']; 
    $weight $_POST['weight'];
    $units $_POST['units'];
    $comments $_POST['comments'];
    $status "None";
    $sql "INSERT INTO waybills SET
      billnum='
    $billnum',
      route='
    $route',
      arrivaldate='
    $arrivaldate',
      status='
    $status',
      units='
    $units',
      weight='
    $weight',
      comments='
    $comments'";
     if (
    mysql_query($sql)) {
      echo (
    '<p>Waybill Added</p>');
     } else {
      echo (
    '<p>Error adding waybill: ' mysql_error() . '</p>');
     } 
     else 
    // allow user to enter waybill
     
    {
    //-- [HTML user input after this point...]
    ?>
     
    <?PHP ?>
    It still give me the same error:
    Parse error: parse error, unexpected T_ELSE in c:\program files\apache group\apache\htdocs\globemaster\admin\addbill.php on line 52
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  22. #22
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please read what has been written:
    You have to add another curly brace:

    PHP Code:
    //-- [...]
    <?PHP
    $dbcnx 
    = @mysql_connect("$host""$user""$pass");
    if (!
    $dbcnx)
    {
        echo( 
    '<p>Unable to connect to the ' 
        
    'database server at this time.</p>' );
        exit();
    }
     
    if ((isset(
    $_POST["submit"])) && ($_POST["submit"] == "auth")) 

        
    //bill added
        //using form below
     
        
    $billnum $_POST['billnum'];
        
    //-- [...]
     
        
    if (mysql_query($sql))
        {
            echo (
    '<p>Waybill Added</p>');
        }
        else
        {
            echo (
    '<p>Error adding waybill: ' mysql_error() . '</p>');
        }
    //-- here you add this brace:

    else 
    // allow user to enter waybill
    {
    //-- [HTML user input after this point...]
    ?>
     
    <?PHP ?>
    if you would format the source it eg i've done it you'd immediately see what's cooking...
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  23. #23
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Everyone! The page is now displaying fine.

    I still have a problem though, When the user enters the info and clicks submit the page reloads without adding anything to the database. Why would it do this? I have copied Kevin Yanks book to a tee and yet doesnt work. Any ideas?
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca


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
  •