Jump to content

how to add hyperlink in either text at a time?


mark103

Recommended Posts

Hi guys,

 

I have added a column in a database, I know how to read the information from the database but I don't know how to check with the column name called "public" whether if the cell has text called enabled or disabled, then add the href link in enabled or disabled text in my php. I need it to allow the clients to control on their own account.

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'myusername');
    define('DB_PASSWORD', 'mypass');
    define('DB_DATABASE', 'mydbtable');
       
    $errmsg_arr = array();
    $errflag = false;

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
  die('Failed to connect to server: ' . mysql_error());
    }

    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
  die("Unable to select database");
    }

   function clean($var){

return mysql_real_escape_string(strip_tags($var));
    }
  
    $username = clean($_GET['user']);
    $password = clean($_GET['pass']);
    if($username == '') {
  $errmsg_arr[] = 'username ID missing';
  $errflag = true;
    }
    if($password == '') {
  $errmsg_arr[] = 'PASSWORD ID missing';
  $errflag = true;
    }

    if($errflag) {
  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  echo implode('<br />',$errmsg_arr);
   }
   else {
  $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'";
  $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error());


if(mysql_num_rows($result) > 0) {
  $qrytable1="SELECT images, id, public FROM members WHERE username='$username'";
  $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());

  while ($row = mysql_fetch_array($result1)) {  
     echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="http://' .  $row["links"] . '">Link</a> </td> | <a href="delete.php?id='.$row['id'].'">Delete</a> </td> | Enabled | Disabled';
  }
}
}
?>

 

What I am trying to achieve is to check the column name called "public" whether if it has text that stored in the database (it could be enabled or disabled) then add the hyperlink in that text of enabled or disabled in the php page so it would allow the user to click one of the link to allow the hyperlink to switch over from enabled to disabled.

 

E.G: A user is going to click the enabled text with the hyperlink to change the text in the database from enabled to disabled and remove the hyperlink in the php page from enabled to add the hyperlink in the disabled text.

 

Do anyone know how to do this?

 

Any advice would be much appreciated.

 

Thanks in advance.

Link to comment
Share on other sites

First I must say great job explaining your problem; seems like many guys just say "I cant do this, help". What you need to have first, is a php page that updates the database row based on which link was clicked, like "changepublic.php" or whatever. It would take a $_GET variable and modify the user's 'public' value based on the $_GET value. then here's the code you could have:

 

note: I fixed your html code because you didn't seem to put an opening <td> tag in your while loop

 

while ($row = mysql_fetch_array($result1)) {  
     echo '<td><p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td>
              <td><a href="http://' .  $row["links"] . '">Link</a> </td>
              <td><a href="delete.php?id='.$row['id'].'">Delete</a> </td>
              <td>Public: ';  
              if($row['public'] == "disabled") echo "<a href=changepublic.php?changeto=enabled>Click to Enable</a>"; 
              else echo "Enabled"; 
              echo ' | ';  
              if($row['public'] == "enabled") echo "<a href=changepublic.php?changeto=disabled>Click to Disable</a>"; 
              else echo "Disabled"; 
              echo '</td>';
  }

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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