Jump to content

alpine

Members
  • Posts

    759
  • Joined

  • Last visited

Posts posted by alpine

  1. No, that's fairly easy - detect based on if the title is present or not in the adress bar:

    
    <?php
    
    if(!empty($_GET['title'])){ // title is present - do search
    
    $dropdown = htmlspecialchars($_GET['title'],ENT_QUOTES);
    $sql = mysql_query("SELECT * FROM recipes WHERE title='$title'");
    
    while($row = mysql_fetch_array($sql)){
    echo <<<_HTML
      <h4>
       {$row['title']}<br />
       {$row['ingredients']}<br />
       {$row['method']}<br />
      </h4>
    _HTML
    }
    }
    else // title is absent or empty - show dropdown
    {
    echo <<<_HTML
    <form action="this.php" method="get">
    <select name="title">
    _HTML;
    
    $query = mysql_query("SELECT title FROM recipes");
    
    while($dropdown = mysql_fetch_array($query)){
      echo "<option value=\"".$dropdown['title']."\">".$dropdown['title']."</option>";
    }
    
    echo <<<_HTML
    </select>
    <input type="submit" name="Submit" value="Submit" />
    _HTML;
    }
    
    ?>
    
    

    Should do it...

  2. Look at the colored part,

    the variable is just written outside any definition or echo and it misses the mandatory ;

     

     

    if ($artist_fn != "") {

    $artist_fullname = trim("$artist_fn $artist_ln");

     

    //************ error is in here - else - ? ***************

    $artist_fullname; } else {

    $artist_fullname = trim("$artist_ln");

    }

    //************************************************

     

     

    
    Look at this
    <?php
    
    if ($artist_fn != "") {
    $artist_fullname = trim("$artist_fn $artist_ln");
    }
    else {
    $artist_fullname = trim("$artist_ln");
    }
    
    if ($date_acq == "0000-00-00") {
    $date_acq = "[unknown]";
    
    $display_block .= "<P><strong>$title</strong> on $rec_label,
    by $artist_fullname<br>
    $my_notes <em>(acquired:$date_acq, format:$format)</em></P>";
    }
    
    ?>
    
    

     

    FYI: I was only fixing your problem, not made any other improvements or changes.

  3. Do you mean how to "read" the id from the adress-bar and how to use it ?

     

    Example with mysql:

    
    <?php
    
    if(!empty($_GET['member_id'])){
      $member_id = $_GET['member_id'];
      $sql = mysql_query("SELECT * FROM members_table WHERE id='$member_id'");
      if(mysql_num_rows($sql)==1){
        $col = mysql_fetch_array($sql);
        echo "User ".$col['name']." has ID ".$col['id'];
      }
      else{
        echo "No user found with ID ".$member_id;
      }
    }
    
    ?>
    
    

     

    But it boils down to how your existing members page is constructed, but $_GET['whatever'] wil get 'whatever' from the adress bar.

  4. You cannot have any whitespace, lines or other output to the browser before the php start-tag

     

    OK:

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

    <?php

    session_start();

     

     

    ERROR:

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

     

    <?php

    session_start();

     

     

     

    Means it's ok to put session_start() 'anyhwhere' as long as no output is done before it.

  5. In your linking part, try this:

    
    <?php
    
    echo '<li><h3>';
    echo $upload;
    
    if(isset($upload)){
      echo '<a href="individualarticle.php?f=1&blog_id=' .$blog_id. '">';
    }
    else{
      echo '<a href="individualarticle.php?f=0&blog_id=' .$blog_id. '">';
    }
    
    echo $title .'</a>';
    
    if(isset($upload)){
      echo '<img src="pin.gif" />';
    }
    
    echo <<<_HTML
    </h3>
    <p style="color: red; display: inline;">written by {$author} on {$date} Posted in <a href="categorypage.php?category_id={$cat}">{$cat1}</a></p>
    <p>{$body}</p>
    </li>
    <p><a href="individualarticle.php?blog_id={$blog_id}">read on...</a></p>
    _HTML;
    
    ?>
    
    

  6. The problem is that you are constantly overwriting the $sql variable while the loop is running

     

    Try something like this:

    
    <?php
    include("check.php");
    include("include.php");
    if($_SESSION['auth']) {
    $query = mysql_query("SELECT id, title, category, status FROM software");
    echo "<table align='center' cellpadding='2' cellspacing='2' width='100%'>
    	<tr bgcolor='#1469A2'>
    	<td width='50%'><b>Software Title</b></td>
    	<td width='20%'><b>Category</b></td>
    	<td width='15%'><b>Status</b></td>
    	<td width='15%'><b>Check Out?</b></td>
    	</tr>";
    while ($data = mysql_fetch_array($query)) {
    
    	echo "<tr bgcolor='#003C64'>
    		<td width='50%'>".$data['title']."</td>
    		<td width='20%'>".$data['category']."</td>
    		<td width='15%'>".$data['status']."</td>
    		<td width='15%'>";
    	if ($data['status'] == "Available") {
    		echo "<form method='POST' style='margin:0px;'>
                                    <input type='hidden' name='id' value='$data['id']'>
    			<input type='submit' name='checkout' style='border:1px #1469A2 solid;' value='Check Out'>
    			</form>";
    	}
    	else {
    		echo "<i>Not Available</i>";
    	}
    	echo "</td></tr>";
    }
    echo "</table>";
    if(isset($_POST['checkout'])) {
            $date = date("Y/m/d");
            $username = $_COOKIE['cis_username'];
            $id = $_POST['id'];
            $sql = "UPDATE `software` SET `status` = 'Checked Out', `by` = '$username', `date` = '$date' WHERE `id` = '$id'";
    mysql_query("$sql") or die (mysql_error());
    echo "You have checked out <b>".$title."</b> successfully";
    }
    }
    else {
    echo "You need to login to view this page! <a href='index.php?page=login'>Login here</a>";
    }
    ?>
    
    

  7. Here is part of a newsletter thing i wrote a while ago, i'm sure you can adjust it to your needs.

    Read comments

    
    <?php
    
    // prepare to save a html version of news.php
    // make sure you already have a blank html page to duplicate from
    $source_html_doc = "../newsletter/archive/blank.html";
    $today = date(dmY);
    $new_blank_html_doc = "../newsletter/archive/news_".$today."html";
    copy($source_html_doc, $new_blank_html_doc)or die('Could not copy required file');
    
    // start getting the generated contents of news.php
    ob_start();
    require("news.php"); // or run php contents here instead
    $body_news = ob_get_contents();
    
    // write a html version of it as archive
    $html_change = fopen ($new_blank_html_doc, 'w');
    fwrite ($html_change, $body_news);
    fclose ($html_change);
    
    // END ob_start
    ob_end_clean();
    
    ?>
    
    

  8. Dunno if this is what you are looking for, but it checks whether the required one is present and walks throug all - included optional ones

    Not tested.

    
    <?php
    
    //the variables
    /*
    $line[0] is the address
    $line[1] is a port (required)
    $line[2] is a port (optional)
    $line[3] is a port (optional)
    $line[4] is a port (optional)
    */
    
    $check = array_slice($line, 1);
    if(!empty($line) && !empty($check)){
    foreach($check as $port){
    
    $fp = fsockopen ($line[0],$port, $errno, $errstr, 10);
        if (!$fp) {
        echo "<br><b>Checking $line[0]...</b><br>\n";
        echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Down, Domain: $line[0], Port: $port</td>\n";
        echo "</tr>\n<tr>\n";
        echo "</tr></table>\n";
        }
        else {
        echo "<br><b>Checking $line[0]...</b><br>\n";
        echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Up, Domain: $line[0], Port: {$port}$a</td>\n";
        echo "</tr>\n<tr>\n";
        echo "</tr></table>\n";
        }
    fclose($fp);
    }
    }
    else{
      echo "Required port is not selected";
    }
    
    ?>
    
    

  9. Here is one, note that its php5 dependant due to str_split()

    
    <?php
    
    $string = "kfgak*suh@hd#t";
    
    $invalid = array();
    $filtered = array_values(str_replace(array_merge(range(a,z),range(A,Z),range(0,9),array('.')),'',str_split($string)));
    foreach(str_split($string) as $char){
      if(in_array($char,$filtered,true)){
        $invalid[] = $char;
      }
    }
    
    if(!empty($invalid)){
      $string = str_replace(array("@","#"), array("_AT_","_SHARP_"), $string);
      $string = str_replace(array_values(str_replace(array_merge(range(a,z),range(A,Z),range(0,9),array('-','.','_')),'',str_split($string))),'_ILLEGAL_',$string);
      echo "<p>Following chars was not accepted:</p><ul><li>";
      echo implode($invalid,'</li><li>');
      echo "</li></ul>";
      echo "String was translated to: $string";
    }
    else{
      echo "No illegal chars found";
    }
    
    ?>
    
    

     

    This example prints out:

    
    Following chars was not accepted:
    
        * *
        * @
        * #
    
    String was translated to: kfgak_ILLEGAL_suh_AT_hd_SHARP_t
    
    

     

    No regex though...

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