Jump to content

webguync

Members
  • Posts

    951
  • Joined

  • Last visited

Posts posted by webguync

  1. Hi, I am trying to create we table by copying and pasting the following into PHPMyAdmin. Not sure why, but I get a MySQL error.

     

    //Comments Table
    CREATE TABLE comments
    (
    com_id INT PRIMARY KEY AUTO_INCREMENT,
    com_name VARCHAR(100),
    com_email VARCHAR(100),
    com_dis TEXT,
    post_id_fk INT,
    FOREIGN KEY(post_id_fk) REFERENCES posts(post_id)
    );
    

     

    anyone know why?

  2. so after reading these responses I believe this is what the form and if/else code should look like?

     

                	<form method="post" <?php echo filter_var($_SERVER['PHP_SELF'], FILTER_SANITIZE_STRING);?>
    Enter Zip Code:<input type="text" size="12" maxlength="12" name="zip"><br /> 
    <input id="submit" type="submit" name="Submit" value="Enter Zip"/>
    
    </form>
    <?php
    $zip = $_POST['zip'];
    echo $zip;
    /* check to see if its set, if its numeric, if it has proper length  etc etc */
    /* if the above check produce and error message ie $error_mess = some content */
    /* then send back to form */
    if (!isset($_POST['zip'])) {
        echo "please fill in a zip code value";
    }
    else{
    include ('weather.php');
    }
    ?>
    

     

     

  3. I have a small script on the bottom of all my pages on my site which list the date and time the page was modified. I want to make the script an include and just put that on the page, but as it is now scripted that won't work since you have to change the page name for every page. Is there a way to change this so it can be an include?

    $last_modified = filemtime("pagename.php");
    print("Last Modified ");
    print(date("m/j/y h:i", $last_modified));?>
    

  4. Hi, I am testing out some simple code while trying out PHP OOP to connect to the MySQL DB. I am getting an undefined variable error, but not sure why.

     

    the test code is:

    <?PHP
    error_reporting(E_ALL);
     include('includes/db.php');
     $db = new db();
    
    
     $db->query("SELECT title FROM blog_posts WHERE id = '7'");
     if($sql)
     {
    	  while($r = mysql_fetch_array($sql))
    	  {
    		   echo $r['title'];
    		   
    	  }
     }
    ?>
    

     

    and the code to connect to the DB is:

    <?PHP
    class db
    {
     private $hostname;
     private $username;
     private $password;
     private $database;
     private $connect;
     private $select_db;
    
     public function db()
     {
    	  $this->hostname = "";
    	  $this->username = "";
    	  $this->password = "";
    	  $this->database = "";
     }
    
     public function open_connection()
     {
    	  try
    	  {
    		   $this->connect = mysql_connect($this->hostname,$this->username,$this->password);
    		   $this->select_db = mysql_select_db($this->database);
    	  }
    	  catch(exception $e)
    	  {
    		   return $e;
    	  }
     }
    
     public function close_connection()
     {
    	  try
    	  {
    		   mysql_close($this->connect);
    	  }
    	  catch(exception $e)
    	  {
    		   return $e;
    	  }
     }
    
     public function query($sql)
     {
    	  try
    	  {
    		   $this->open_connection();
    		   $sql = mysql_query($sql);
    	  }
    	  catch(exception $e)
    	  {
    		   return $e;
    	  }
    	  $this->close_connection();
    	  return $sql;
     }
    }
    ?>
    
    
    

     

    the specific error is...

     

    Undefined variable: sql in E:\DBTest.php on line 9
    

  5. thanks, is this the way to do the variable check? I ask b/c it doesn't seem to be working. I don't get the included code.

    <form method="post" action="<?php echo $PHP_SELF;?>">
    Enter Zip Code:<input type="text" size="12" maxlength="12" name="zip"><br /> 
    <input id="submit" type="submit" name="Submit" value="Enter Zip"/>
    
    </form>
    <?php
    $zip = $_POST['zip'];
    
    /* check to see if its set, if its numeric, if it has proper length  etc etc */
    /* if the above check produce and error message ie $error_mess = some content */
    /* then send back to form */
    if (!isset($zip)) {
        echo "please fill in a zip code value";
    }
    else{
    include ('weather_report.php');
    }
    ?>
    

     

  6. Hi, I only want to display some included PHP code only if a value is displayed from  form input. The value is a zip code which is used to display weather information, but the app produces an error when you first enter the page, because their is no value for the zip variable. I know I need an if/else statement, but not sure what to put in it.

     

    The form code is this

    <h3>Enter your zip code to receive weather info.</h3>
                	<form method="post" action="<?php echo $PHP_SELF;?>">
    Enter Zip Code:<input type="text" size="12" maxlength="12" name="zip"><br /> 
    <input id="submit" type="submit" name="Submit" value="Enter Zip"/>
    
    </form>
    
    <?php
    
    
    // this is how we bring in the weather file
    
    include 'weather_report.php' 
    
    ?>
    

     

    the zip variable is set-up in the weather_report.php file as follows

    $zip = $_POST["zip"];
    

     

    but like I said until that value is set, an error is thrown by the weather app code.

     

     

  7. Hi, I have a weather app, coded which creates weather based on a set zip code. I want to create a form which when the user fills out their local code and clicks the send button that will change the zip code variable. Currently it is set up like this

    $zip = '90210'; //change to your zipcode
    

     

    need help with getting started with this. Thanks!

  8. shouldn't this work? or is sendmail() the same as mail()?

     

    function sendmail($to, $subject, $message, $from) {
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= "webguync@inspired-evolution.com" . "\r\n";
    
    
    $result = sendmail($to,$subject,$message,$headers);
    
    if ($result) return 1;
    else return 0;
    }
    

  9. do you mean in the function?

    function mail($to, $subject, $message, $from) {
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";
    
    $result = mail($to,$subject,$message,$headers);
    
    if ($result) return 1;
    else return 0;
    }
    

     

    not really sure I am understanding what to change. I added the error reporting, and not getting any errors.

  10. hmm, what is wrong with this code?

    <?php
    $to = 'myemail@gmail.com'
    $subject = 'this is a test'
    $message = 'I rock at the phps'
    mail($to, $subject, $message);
    ?>
    

     

    getting a 'Parse error: syntax error, unexpected T_VARIABLE in \test.php on line 3'

     

     

  11. sorry, I just get the else echo, not a PHP error

    else echo 'Sorry, unexpected error. Please try again later';
    

     

    how would I set the simple script to go to a  specific email, because I think the email I have through the hosting company is not one that I typically use.

     

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.