Jump to content

aftab_jii

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Posts posted by aftab_jii

  1. Hi,

    I am trying to customize a script that shows random images..

    i am obviously doing something wrong because the script does not show any images

    can someone help me?

     

     

    
    <?php
    //this is the file for all the function
    
    function getRandomImage($dir,$type='random')
    {
    global $errors,$seed;
    
      if (is_dir($dir)) {
    
      $fd = opendir($dir);
      $images = array();
    
          while (($part = @readdir($fd)) == true) {
    
              if ( @eregi("(gif|jpg|png|jpeg)$",$part) ) {
                  $images[] = $part;
              }
          }
    
        // adding this in case you want to return the image array
        if ($type == 'all') return $images;
    
        if ($seed !== true) {
          mt_srand ((double) microtime() * 1000000);
          $seed = true;
        }
    
          $key = mt_rand (0,sizeof($images)-1);
    
        return $dir . $images[$key];
    
      } else {
          $errors[] = $dir.' is not a directory';
          return false;
      }
    }
    
    
    $query = "SELECT * FROM images WHERE is_published=1";
    $result = mysql_query ($query); // Run the query
    
    while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
    $image_id = $row['image_id'];
    
    $image_filename = "uploaded_images/" . $image_id . ".jpg";
    
    
    $image = getRandomImage($image_filename);
    echo 'The value of image is: ' . $image . '<br \>';
    
    echo "<img src='$image_filename' width='519' height='353' border='0' usemap='#Map' \>";
    }
    ?>
    
    

     

     

     

  2. i want to show last two posts where posts with category About Me and Our Services are skipped.

    i managed to do it with the query below, but it only returns one post if the next post has category About Me or Our Services.

    i want the sql to skip the two categories and show two posts

     

    $sql = "SELECT article_id FROM articles WHERE is_published=1 AND category <> 'About Me' AND category <> 'Our Services' ORDER BY date_published DESC LIMIT 0,2";
    $sql_result = mysql_query($sql)
    			or die('Could not run query; ' . mysql_error());
    

     

    i tried with SKIP (category = 'About Me') but got an error

  3. okey..managed to solve it..

    here is how:

     

    //compose.php
    [b]<h2>Compose Article</h2>
    
    <form method="post" action="transact-article.php?category=" . <?php echo $row['article_category']; ?> \>
    
    <?php
    
    if ($row['category'] != "") {
    ?>
    <p><br> Article curretly published in <font color='red'><?php echo $category;?></font> </p></br>
    <?php
    } else {
    echo "";
     }
    
      $sql = "SELECT * FROM article_category WHERE status = '1' ORDER BY article_category ASC";
      $result = mysql_query($sql)
        or die('Could not list access levels; ' . mysql_error());
      while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
      $c = $row['article_category'];
    echo '<input type="radio" name="category" value="' . $c . '" checked \>';
    echo ' ' . $c;
    echo '   ';
    }
    [/b]?>
    
    <p>
      Title:<br>
      <input type="text" class="title" name="title" maxlength="255"
        value="<?php echo htmlspecialchars($title); ?>">
    </p>
    <p>
      Body:<br>
      <textarea class="body" name="body" rows="10" cols="60"><?php
        echo htmlspecialchars($body); ?></textarea>
    </p>
    <p>
    <?php
    echo '<input type="hidden" name="article" value="' .
         $article . "\">\n";
    
    if ($_SESSION['access_lvl'] < 2) {
      echo '<input type="hidden" name="authorid" value="' .
           $authorid . "\">\n";
    }
    
    if ($article) {
      echo '<input type="submit" class="btn" name="action" ' .
           "value=\"Save Changes\">\n";
    } else {
      echo '<input type="submit" class="btn" name="action" ' .
           "value=\"Submit New Article\">\n";
    }
    ?>
    </p>
    </form>
    

     

    and the changes in transact-aticle.php

     

    case 'Submit New Article':
          if ([b]isset($_POST['category'])[/b]
              and isset($_POST['title'])
              and isset($_POST['body'])
              and isset($_SESSION['user_id']))
          {
            $sql = "INSERT INTO articles " .
                   "(category, title, body, author_id, date_submitted) " .
                   "VALUES ('" . [b]$_POST['category'][/b] .
                   "','" . $_POST['title'] .
                   "','" . $_POST['body'] .
                   "'," . $_SESSION['user_id'] . ",'" .
                   date("Y-m-d H:i:s", time()) . "')";
    
            mysql_query($sql, $mylink)
              or die('Could not submit article; ' . mysql_error());
          }
          redirect('cpl.php');
          break;
    

  4. Hi,

    I am having a little bit of trouble passing the value of radio-button into a mySQL database.

    The script below (compose.php) reads the value of article_category from table article_category

    But the values does not pass on to mySQL table..the column category in table articles (transact-article.php) remains empty.

    Can anyone tell me what i am missing?

    <?php
    //compose.php
    require_once ('files/configure_impressions.php');
    
    $title = '';
    $body = '';
    $article = '';
    $authorid = '';
    if (isset($_GET['a'])
        and $_GET['a'] == 'edit'
        and isset($_GET['article'])
        and $_GET['article']) {
      $sql = "SELECT category,title,body,author_id FROM articles " .
             "WHERE article_id=" . $_GET['article'];
      $result = mysql_query($sql, $mylink)
        or die('Could not retrieve article data; ' . mysql_error());
    
      $row = mysql_fetch_array($result);
    
      $title = $row['title'];
      $body = $row['body'];
      $article = $_GET['article'];
      $authorid = $row['author_id'];
    
    }
    ?>
    
    
    
    <h2>Compose Article</h2>
    
    <?php
    
      $sql = "SELECT * FROM article_category ORDER BY article_category ASC";
      $result = mysql_query($sql)
        or die('Could not list access levels; ' . mysql_error());
      while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
    
    echo '<input type="radio" name="category" value="' . $row['article_category'] . '">';
    echo ' ' . $row['article_category'];
    echo '   ';
    }
    
    ?>
    
    <form method="post" action="transact-article.php?category="<?php echo $row['article_category']; ?>" \>
    <p>
      Title:<br>
      <input type="text" class="title" name="title" maxlength="255"
        value="<?php echo htmlspecialchars($title); ?>">
    </p>
    <p>
      Body:<br>
      <textarea class="body" name="body" rows="10" cols="60"><?php
        echo htmlspecialchars($body); ?></textarea>
    </p>
    <p>
    <?php
    echo '<input type="hidden" name="article" value="' .
         $article . "\">\n";
    
    if ($_SESSION['access_lvl'] < 2) {
      echo '<input type="hidden" name="authorid" value="' .
           $authorid . "\">\n";
    }
    
    if ($article) {
      echo '<input type="submit" class="submit" name="action" ' .
           "value=\"Save Changes\">\n";
    } else {
      echo '<input type="submit" class="submit" name="action" ' .
           "value=\"Submit New Article\">\n";
    }
    ?>
    </p>
    </form>
    

     

    <?php
    .
    .
    .
    .
    .
    //transact-article.php
    case 'Submit New Article':
          if (isset($_GET['article_category'])
              and isset($_POST['title'])
              and isset($_POST['body'])
              and isset($_SESSION['user_id']))
          {
            $sql = "INSERT INTO articles " .
                   "(category, title, body, author_id, date_submitted) " .
                   "VALUES ('" . $_GET['article_category'] .
                   "','" . $_POST['title'] .
                   "','" . $_POST['body'] .
                   "'," . $_SESSION['user_id'] . ",'" .
                   date("Y-m-d H:i:s", time()) . "')";
    
            mysql_query($sql, $mylink)
              or die('Could not submit article; ' . mysql_error());
          }
          //redirect('cpl.php');
          break;
    .
    .
    .
    .
    ?>
    

  5. im working with a PHP form that reads values from a database and an AJAX code that autocompletes the values..

    what i am having problem with is that each felt reads all the values from all the columns in the database..

    take a look at the screen shoot

     

    1.JPG

     

    The values RAPE110 and ABC Stal are from one table but two differnt columns

     

    2.JPG

     

    3.JPG

     

    I need help to sort out what i ha ve to do so that the textfields get/shows values that belong to the column

    The PHP code where i define the column look like:

     

    <td id="text">Mal artikkel:</td>
         <td>
         <input type="text" name="malartikkel" size="20" maxlength="40" value="<?php if (isset($_REQUEST['malartikkel'])) echo $_REQUEST['malartikkel']; ?>" />
    	 <div id="hint"></div>
    	 		 	<script type="text/javascript">
    	 		 		new Ajax.Autocompleter("malartikkel","hint","server.php");
            </script>
    	 </td>
         </tr>
    
    
    <tr>
    	<td id="text">Leverandørens navn:</td>
    	  <td>
    	  <input type="text" name="leverandorsnavn" size="40" maxlength="40" value="<?php if (isset($_REQUEST['leverandorsnavn'])) echo $_REQUEST['leverandorsnavn']; ?>" />
          <div id="hint"></div>
    	 		 	<script type="text/javascript">
    	 		 		new Ajax.Autocompleter("leverandorsnavn","hint","server.php");
            </script>
    	  </td>

     

    and the sql (which is defined in server.php) looks like:

     

    $sql = "SELECT malartikkel, leverandorsnavn FROM varebest WHERE malartikkel LIKE '%" . $_POST['search'] . "%'" . " AND leverandorsnavn LIKE '%" . $_POST['search'] . "%'";
    $rs = mysql_query($sql);
    
    ?>
    
    <ul>
    
    <? while($data = mysql_fetch_assoc($rs)){ ?>
        <? //echo stripslashes($data['malartikkel']);
             echo stripslashes($data['produktbeskrivelse']);
             echo stripslashes($data['malartikkel']);
    ?>
    <? } ?>
    
    </ul>

     

  6. can anyone help me with this...

    i have set up mail($email, $subject, $message) on a windows 2000 server but i dont get any mail at all..

    what sort of properties should i change in php.ini file?

    we are using LotusNotes and it has a serveraddress that looks like: abcserver/abc/com

     

  7. i have trid to install PHP on a windows 2000 server but i dont get it to work...

    the tutorial i have followed is: http://forums.kayako.com/showthread.php?t=4066

    i have trid both: This is how you set the website to use PHP as CGI.

    and

    To change from CGI to ISAPI

    saprately but the page: http://localhost/test.php (which is a phpinfo() ) does not show up and neiter does anyother php pages...

     

    can anyone help..

    the browser shows me the dafault error page saying that the page im looking for does not exists..

     

     

     

  8. can someone please help me creating a check for the following drop-down:

     

    <tr>

      <td id="text">Salesman: *</td>

      <td>

      <select name="Salesman">

      <option selected>Choose a salesman</option>

      <option value="leanardo@gmail.com">Leanardo</option>

      <option value="cane@gmail.com">Cane</option>

      <option value="josef@gmail.com">Cane</option>

      </select></td>

              </tr>

     

    i have tried something like this:

     

    if (isset($_REQUEST['salesman'])="Choose a salesman") {

    $error = 'Please choose the appropriate salesman.<br>';

    } else {

    $salesman =  ($_REQUEST['salesman']);

    }

     

    but its not seem to be working

  9. okey..

    i have a really complex query..

    the reason im asking this is to save my time..

    i have two mysql databases..herezz the structure..

     

    Database A (old):

    It has about 150 users with permissions to about 5 to 10 application

    Every application can be given and denied permission to a function within the application by setting 0 and 1..the data for the users looks something like this:

     

    Username  Application Name  Function1  Function2  Function3  Function4  Function5  Function6

    --------------------------------------------------------------------------------------------

    XYZ          Sales                      1          0                0          1              1            1

    ABC          Sales                      1            1                1          0              0              0 

     

    Database B (new):

    In this database the users are assigned groups and the rest of the table is the same:

     

    Username  Group  Application Name  Function1  Function2  Function3  Function4  Function5  Function6

    ---------------------------------------------------------------------------------------------------

    XYZ          Logistics    Sales                      1          0                0          1              1            1

    ABC          Logistics    Sales                      1            1                1          0              0              0 

     

    Now what i want to do is to copy the data for each function from Database A into Database B so that

    the permissions in the Database B would be same as Database A...since the only differnce is that in Database B the users are assigned groups..

     

    can anyone help me please

  10. do you guys see anything missing in this code..i am unable to send the SESSION variables to the next page:

     

    <?php

    //ob_start();

    include('files/authenticate.php');

    if (isset($_POST['submit'])) { // Check if the form has been submitted.

    include('files/config.php'); // Connect to the database.

     

    if (empty($_POST['email'])) { // Validate the username.

    $email = FALSE;

    echo '<font color="red">You forgot to enter your username!</font><br>';

    } else {

    $email = $_POST['email'];

    }

     

    if (empty($_POST['passwd'])) { // Validate the password.

    $password = FALSE;

    echo '<font color="red">You forgot to enter your password!</font><br>';

    } else {

    $password = $_POST['passwd'];

    }

     

    if ($email && $password) { // If everything OK.

        // Query the database.

    $query = "SELECT user_id, access_lvl, name " .

                  "FROM users " .

                  "WHERE email='" . $_POST['email'] . "' " .

                  "AND passwd=PASSWORD('" . $_POST['passwd'] . "')";

    $row = mysql_query ($query);

     

    if ($row) { // A match was made.

    //Start the session, register the values & redirect.

    session_start();

    $row = mysql_fetch_assoc($row);

    $_SESSION['user_id'] = $row['user_id'];

    $_SESSION['access_lvl'] = $row['access_lvl'];

            $_SESSION['name'] = $row['name'];

    //ob_end_clean(); // Delete the buffer.

    header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedinn.php");

    //exit();

    //ob_end_clean(); // Delete the buffer.

    } else { // No match was made.

    echo '<font color="red">The username and password entered do not match those on file.</font><br>';

    }

    mysql_close(); // Close the database connection.

    } else { // If everything wasn OK.

    echo '<font color="red">Please try again.</font><br>';

    }

     

    } // End of SUBMIT conditional.

    //ob_end_flush();

    ?>

    <form action="login.php" method="post">

    <p>E-mail address:<br>

      <input type="text" name="email" maxlength="255" value="">

    </p>

    <p>Password:<br>

      <input type="password" name="passwd" maxlength="99">

    </p>

    <p>

      <input type="submit" name="submit" value="Login">

    </p>

    </form>

    <p></p>

  11. how can i break this up?

    i think there is something wrong with my login.php cuz when i type wrong password i dont get prompted but send ro notallowed.php

     

    <?php

    if ((isset($_SESSION['user_id']) && $_SESSION['user_id']) != "" ||

    (isset($_SESSION['access_lvl']) && $_SESSION['access_lvl'] != "")) {

    $redirect = $_SERVER['PHP_SELF'];

    } else {

    header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/notallowed.php");

    //die();

    }

     

    ?

     

  12. im working on a login schema and having a little trouble..

    i have three files:

     

    login.php

    loggedinn.php

    notallowed.php

    authenticate.php

     

    login.php is the schema

    loggedin.php is the page the user see after successful logginn

    not allowed is the page visitor see if he tries to access a page that is password proteced like: compose an article (which is only accessable to users)

    authenticate.php is a script that controlls the session started in login.php

     

    somehow, no matter what i try, i always end up on notallowed.php..meaning either i try to enter the right password, wrong password or types the location that is password protected...it doesnot even promt when i type wrong password; just jumps to notallowed.php

     

    here are the files..i need help..

     

    ----- login.php ---

    <?php

    //ob_start();

    if (isset($_POST['submit'])) { // Check if the form has been submitted.

    require_once ('files/config.php'); // Connect to the database.

     

    if (empty($_POST['email'])) { // Validate the username.

    $email = FALSE;

    echo '<font color="red">You forgot to enter your username!</font><br>';

    } else {

    $email = $_POST['email'];

    }

     

    if (empty($_POST['passwd'])) { // Validate the password.

    $password = FALSE;

    echo '<font color="red">You forgot to enter your password!</font><br>';

    } else {

    $password = $_POST['passwd'];

    }

     

    if ($email && $password) { // If everything OK.

    // Query the database.

    $query = "SELECT user_id, access_lvl,name " .

    "FROM users " .

    "WHERE email='" . $_POST['email'] . "' " .

    "AND passwd=PASSWORD('" . $_POST['passwd'] . "')";

    $row = mysql_query ($query);

    //$row = mysql_fetch_array ($result, MYSQL_NUM);

     

    if ($row) { // A match was made.

    //Start the session, register the values & redirect.

    session_start();

    $_SESSION['user_id'] = $row['user_id'];

    $_SESSION['access_lvl'] = $row['access_lvl'];

    $_SESSION['name'] = $row['name'];

    ob_end_clean(); // Delete the buffer.

    header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedinn.php");

    exit();

    //ob_end_clean(); // Delete the buffer.

    } else { // No match was made.

    echo '<font color="red">The username and password entered do not match those on file.</font><br>';

    }

    mysql_close(); // Close the database connection.

    } else { // If everything wasn OK.

    echo '<font color="red">Please try again.</font><br>';

    }

     

    } // End of SUBMIT conditional.

    ob_end_flush();

    ?>

    <form action="login.php" method="post">

    <p>E-mail address:<br>

    <input type="text" name="email" maxlength="255" value="">

    </p>

    <p>Password:<br>

    <input type="password" name="passwd" maxlength="50">

    </p>

    <p>

    <input type="submit" name="submit" value="Login">

    </p>

    </form>

    <p></p>

    -------- login.php ends here ------

     

    here is the loggedinn.php

     

    ---start ---

    <?php

    session_start();

    include('files/config.php');

    include('files/authenticate.php');

    if ((isset($_SESSION['user_id']) && $_SESSION['user_id'] != "") ||

    (isset($_SESSION['access_lvl']) && $_SESSION['access_lvl'] != "")) {

    echo ' | <a href="links.php?action=funkey">Links</a>';

    echo ' | <a href="published.php">Articles</a>';

    echo ' | <a href="compose.php">Compose</a>';

    echo ' | <a href="banadmin.php">Blocked List</a>';

    if ($_SESSION['access_lvl'] > 1) {

    echo ' | <a href="cpl.php">Control panel</a>';

    }

     

    //echo ' | <a href="links.php">Control Panel</a>';

    echo ' | <a href="logout.php?action=Logout">Logout</a> |';

    //}else{

     

    // echo ' | <a href="login.php?action=login">Login</a> |';

    }

    ?>

    ------ ends here ----

     

    here is notallowed.php

     

    ---start----

    <?php

    echo "you are not allowd to access this page without right previllages";

    ?>

    --- ends here----

     

    here is the authenticate page...

     

    ---- authenticate.php ---

    <?php

    if ((isset($_SESSION['user_id']) &&

    $_SESSION['user_id']) != "" ||

    (isset($_SESSION['access_lvl']) &&

    $_SESSION['access_lvl'] != "")) {

    $redirect = $_SERVER['PHP_SELF'];

    } else {

    header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/notallowed.php");

    //die();

    }

     

    ?

    ------ ends here ------

     

    i did the following echos in loggedinn.php:

     

    echo "user_id: " . $_SESSION['user_id'];

    echo "access level" . $_SESSION['access_lvl'];

     

    and it returned nothing

     

  13. im working on a blog/online diary and want to sort published articles according to months and year just like on blog pages and i need help with the table and code..

    my sql-table for the articles look like:

     

    CREATE TABLE `articles` (

      `article_id` int(11) NOT NULL auto_increment,

      `category` varchar(100) NOT NULL default '',

      `author_id` int(11) NOT NULL default '0',

      `is_published` tinyint(1) NOT NULL default '0',

      `date_submitted` datetime NOT NULL default '0000-00-00 00:00:00',

      `date_published` datetime NOT NULL default '0000-00-00 00:00:00',

      `title` varchar(255) NOT NULL default '',

      `body` mediumtext NOT NULL,

      PRIMARY KEY  (`article_id`),

      KEY `IdxArticle` (`author_id`,`date_submitted`),

      FULLTEXT KEY `IdxText` (`title`,`body`)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=165 ;

     

    do i need to create a new table , do changes in the current table or do i have to write new code in PHP for the article.php ?

     

    are there any code examples on the net you peope can refer me to?

  14. i am trying to create a poop-up window but keep getting parse error:

    [quote]echo " <tr>
    <td align=\"center\"><a href="/news.php?uid={$row['id']}" OnClick='window.open('/news.php?uid={$row['id']}','News','toolbar=no,width=600 height=400,menubar=no,scrollbars=no,resizable=no')'>VIEW</a></td>
    <td align=\"center\">{$row['first_name']}</td>
    <td align=\"center\">{$row['last_name']}</td>
    <td align=\"center\">{$row['email']}</td>
    <td align=\"center\">{$row['city']}</td>
    <td align=\"center\">" . ($row['problem']) ."</td>
    <td align=\"center\">{$row['d']}</td>

    [/quote]

    help
×
×
  • 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.