Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

link to url from button


  • Please log in to reply
1 reply to this topic

#1 12Strings

12Strings

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:06:31 PM

Posted 20 February 2017 - 07:42 PM

Hi, my code successfully creates a dropdown menu from a database and upon selecting a "target", displays the record in the form of a table including a radio button. My objective is to click the button to link to the "target". The "target" fields are
email addresses or URLs. Any pointers? Thanks in advance.

The code follows:
 

<!DOCTYPE><html><head><title>test menu create</title></head>
<body><center>
<form name="form" method="post" action="">
<?php
$con=mysqli_connect("localhost","root","password","DB");
//============== check connection
if(mysqli_errno($con))
{ echo "Can't Connect to mySQL:".mysqli_connect_error(); }
else
{ echo "Connected to DB</br>"; }
//This creates the drop down box
echo "<select name= 'target'>";
echo '<option value="">'.'--- Select account ---'.'</option>';
$query = mysqli_query($con,"SELECT target FROM testbl");
$query_display = mysqli_query($con,"SELECT * FROM testbl");
while($row=mysqli_fetch_array($query))
{echo "<option value='". $row['target']."'>".$row['target']
.'</option>';}
echo '</select>';
?>
<input type="submit" name="submit" value="Submit"/>
</form></body></html>

<!DOCTYPE><html><head><title>test menu display</title></head>
<body><center>

<?php
$con=mysqli_connect("localhost","root","password","DB");
if(mysqli_errno($con))
{echo "Can't Connect to mySQL:".mysqli_connect_error();}
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT target, thingamajig FROM testbl WHERE target = '".$name."'";
$result = mysqli_query($con,$fetch);
if(!$result)
{ echo "Error:".(mysqli_error($con)); }

//display the table
echo '<table border="1">'.'<tr>'.'<td bgcolor="#ccffff align="center">'. 'test menu'. '</td>'.'</tr>';
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
<td bgcolor="#CFB53B align="center">'.'target'.'</td>'.'
<td bgcolor="#ccffff align="center">'.'thingamajig'.'</td>'.'
</tr>';
while($data=mysqli_fetch_row($result))
{ echo ("<tr><td>$data[0]</td><td>$data[1]</td></tr>"); }
echo '</table>'.'</td>'.'</tr>'.'</table>';
}
?>
</form></body></html>

 



BC AdBot (Login to Remove)

 


#2 newage

newage

  • Members
  • 21 posts
  • OFFLINE
  •  

Posted 08 March 2017 - 07:25 AM

A few things to note. If that's all 1 script you don't need to re-declare $con. You're making the connection twice essentially. I usually make a functions.php file to declare my connections. Also, watch the asterisk (*). That can potentially use up more memory than what is really necessary in a shared web host environment.

 

Your issue is with the "mysqli_fetch_row()" function. You aren't using the $con. So it goes like this... "mysqli_fetch_row($con, $result)".


Edited by newage, 08 March 2017 - 07:52 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users