Problems with isset

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JaymzM
Forum Newbie
Posts: 2
Joined: Sun Jun 28, 2009 9:09 pm

Problems with isset

Post 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>
 
 
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: Problems with isset

Post 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
JaymzM
Forum Newbie
Posts: 2
Joined: Sun Jun 28, 2009 9:09 pm

Re: Problems with isset

Post 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
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: Problems with isset

Post by a94060 »

of course,you are welcome. Sometimes a fresh pair of eyes are needed to find the mistake.
Post Reply