Page 1 of 1

Problems with isset

Posted: Sun Jun 28, 2009 9:57 pm
by JaymzM
Hey Guys

Does anyone see anything wrong with the way I've put this together???

The $sqlInsert seem to stop working when I try to put this into play
Line 29-- if(isset($function) && $function=="add"){ --
If I slash that line out the $sqlInsert function works
I'm fairly new to php and thought I would challenge myself some, however with challenges comes defeat, any help would appreciated.

Code: Select all

 
 
<?php
 
    include("../../../connections/mysql_connect.php");
    
    mysql_select_db("$database") or die ("Unable to Connect to the Database");
    
    $table = "company_z";
    if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$table."'")))
    {
        //print("Found Table.Ready to Proceed!");
    }else{
        print("Table was not found, I will create it now.<br>");
        
        $sql = "CREATE TABLE `company_z` (
                `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                `company` VARCHAR( 64 ) NOT NULL ,
                `address` VARCHAR( 64 ) NOT NULL ,
                `postal_code` VARCHAR( 12 ) NOT NULL ,
                `phone` VARCHAR( 16 ) NOT NULL ,
                `email` VARCHAR( 32 ) NOT NULL ,
                `region` VARCHAR( 12 ) NOT NULL)  " ; 
 
        mysql_query($sql) or die(mysql_error()) ;   
        print("Table Creation Complete. . .<br>");
    }
    
    if(isset($function) && $function=="add"){
        $sqlInsert =    "INSERT INTO `company_z` (
                        `company`,
                        `address`,
                        `postal_code`,
                        `phone`,
                        `email`,
                        `region`)
                        VALUES ('Some Company', 'some address', 'postal', '555-555-5555', 'me@here.ca', 4 )";
 
        //print("$sqlInsert<br>");
        mysql_query($sqlInsert) or die(mysql_error());
        
    }
    
    $regSQL = "SELECT `regionName`,`regionNumber` FROM regions";
    $resultQuery = mysql_query($regSQL) or die(mysql_error()) ;
    
?>
 
<!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=utf-8" />
<title>PHP/MySQL Programming Course Part 2</title>
</head>
 
<body>
<table width="42%" height="145" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td align="center" valign="top"><p>Add your clients shipping information here<br />
            </p>
              <table width="289" height="114" border="0" cellpadding="0" cellspacing="0">
                <form id="enterForm" name="dataEnter" method="post" action="index.php?function=add">
                  <tr>
                    <td width="100" height="25" align="left" valign="middle" class="style26">Company</td>
                    <td width="168" height="25" align="left" valign="middle"><input type="text" name="company" id="company" /></td>
                  </tr>
                  <tr>
                    <td width="100" height="25" align="left" valign="middle" class="style26">Address</td>
                    <td width="168" height="25" align="left" valign="middle"><input type="text" name="address" id="address" /></td>
                  </tr>
                  <tr>
                    <td width="100" height="25" align="left" valign="middle" class="style26">Postal Code</td>
                    <td width="168" height="25" align="left" valign="middle"><input type="text" name="postal" id="postal" /></td>
                  </tr>
                  <tr>
                    <td width="100" height="25" align="left" valign="middle" class="style26">Phone</td>
                    <td width="168" height="25" align="left" valign="middle"><input type="text" name="phone" id="phone" /></td>
                  </tr>
                  <tr>
                    <td width="100" height="25" align="left" valign="middle" class="style26">Email</td>
                    <td width="168" height="25" align="left" valign="middle"><input type="text" name="email" id="email" /></td>
                  </tr>
                  <tr>
                    <td width="100" height="25" align="left" valign="middle" class="style26">Region</td>
                    <td width="168" height="25" align="left" valign="middle"><select name="regionNumber" id="regionNumber">
                        <? while ( $myrow = mysql_fetch_array($resultQuery) ) { ?>
  
                            <option value="<? echo $myrow['regionNumber']; ?>"><? echo $myrow['regionNumber'] ."-". $myrow['regionName']; ?></option>
  
                        <? } ?>
                      </select>
                    </td>
                  </tr>
                  <tr>
                    <td height="25" colspan="2" align="left" valign="middle" class="style26"><div align="center">
                      <input type="submit" name="addData" id="addData" value="Submit" />
                    </div></td>
                  </tr>
                </form>
              </table>
            <p></p></td>
        </tr>
      </table>
 
 

Re: Problems with isset

Posted: Sun Jun 28, 2009 10:25 pm
by a94060
where is $function given a value?

Code: Select all

<form id="enterForm" name="dataEnter" method="post" action="index.php?function=add">
the value function=add is passed via GET,rather than post so you must retrieve that value.
do this by assigning the passed value to a variable $function. Something like :

Code: Select all

 
$function=$_GET['function'];
 
at the beginning of the script

Re: Problems with isset

Posted: Sun Jun 28, 2009 11:42 pm
by JaymzM
*BIG disappointing sigh while hanging my head in shame*

Oh crap, that was it....
Thank you ever so much for the help, sometimes it's the simplest things that we over look isn't it.
My new motto KISS "Keep It Simple Stupid"...lol

Cheers

Re: Problems with isset

Posted: Mon Jun 29, 2009 7:39 am
by a94060
of course,you are welcome. Sometimes a fresh pair of eyes are needed to find the mistake.