Jump to content

Trying to make a drop down menu


adamjones

Recommended Posts

Hey,

So I have this code, and it's function is to show which domains belong to a certain user;

<?php
require_once('config.php');
$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");
}

$sql="SELECT domain FROM domains WHERE user=".$_SESSION['user'].""; 
$result=mysql_query($sql); 

    echo "<select name=\"name\">"; 
    echo "<option size =30 selected>Choose A Domain</option>";
    if(mysql_num_rows($sql_result)) 
    { 
    while($row = mysql_fetch_assoc($sql_result)) 
    { 
    echo "<option>$row[domain]</option>"; 
    } 

    }  
    ?>

...But it's just showing a blank dropdown. Any ideas?

My database structure is attached.

Thanks!

 

[attachment deleted by admin]

Link to comment
Share on other sites

These lines:

if(mysql_num_rows($sql_result)) 
    { 
    while($row = mysql_fetch_assoc($sql_result)) 

 

should be:

 

if(mysql_num_rows($result)) 
    { 
    while($row = mysql_fetch_assoc($result)) 

 

Because you dont have $sql_result...

 

Hi, thanks. So I've change my code to;

<?php
require_once('config.php');
$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");
}

$sql="SELECT domain FROM domains WHERE user=".$_SESSION['user'].""; 
$result=mysql_query($sql); 

    echo "<select name=\"name\">"; 
    echo "<option size =30 selected>Select</option>";
    if(mysql_num_rows($result)) 
    { 
    while($row = mysql_fetch_assoc($result))  
    { 
    echo "<option>$row[domain]</option>"; 
    } 

    } 
    ?>

But it's still not working?

Link to comment
Share on other sites

$result=mysql_query($sql) or die (mysql_error());
echo $sql;

 

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@live.com' at line 1"

 

Hmm, usernames are e-mail addresses, I'm guessing that's a problem somehow?

Link to comment
Share on other sites

} $sql="SELECT domain FROM domains WHERE user=".$_SESSION['user']."";

 

change it to :

 

} $sql="SELECT domain FROM domains WHERE user='".$_SESSION['user']."'";

 

(mark the extra single quotes that are added, it will give (i.e.):

SELECT domain FROM domains WHERE user='someone@example.com';

Link to comment
Share on other sites

Just another quick question;

I added a button, and when pressed, it links to 'check.php'. How would I echo the option that was selected on the check.php page??

 

<form class="table" action="check.php" method="post">
				<div class="inner-form">
					<div class="msg msg-info">
                        <p>Please select which domain you wish to edit.</p>
                        </div>
					<?php
require_once('config.php');
$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");
}

$sql="SELECT domain FROM domains WHERE user='$_SESSION[user]'"; 
$result=mysql_query($sql) or die (mysql_error());

    echo "<select name=\"name\">"; 
    echo "<option size =30 selected>Select a domain</option>";
    if(mysql_num_rows($result)) 
    { 
    while($row = mysql_fetch_assoc($result))  
    { 
    echo "<option>$row[domain]</option>"; 
    } 

    } 
    ?></div>
    </select>
<input type="submit" VALUE="Edit">
			</form>

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.