Jump to content

Help With Display


ChompGator

Recommended Posts

We don't write scripts for people.  We help them work out bugs in their scripts.  I will point you in the right direction and say that you need to:

 

-Query your db for the info

-Make your form tag and your dropdown tag and then right after that, make a loop that echoes your option tags, with the value being the current iteration of your query's result array. Then after the loop, close out your form elements and tags etc.. and you're good to go.

 

Now that you have a plan, get to it.  If you have issues with making your code work, post it and ask away.

Link to comment
Share on other sites

<?php

$host="**"; // Host name

$username="**"; // Mysql username

$password="**"; // Mysql password

$db_name="***"; // Database name

$tbl_name="**"; // Table name

 

mysql_connect($host, $username, $password)or die("cannot connect to server ");

mysql_select_db("$db_name")or die("cannot select DB");

 

$result = @mysql_query("select * users");

if (mysql_num_rows($result) > 0) {

  print "<select name=\"select_name\">";

  while ($row = mysql_fetch_array($result)) {

    print "<option value=\"" . $row['table_field1'] . "\">" . $row['table_field2'] . "</option>\n";

  }

  print "</select>";

}

mysql_free_result($result); 

?>

 

Thats what I got so far

Link to comment
Share on other sites

well the field names are

uid

and

first

 

so I changed those - but now, its giving me this error

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\site2\login\exec\new.php on line 12

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\site2\login\exec\new.php on line 19

Link to comment
Share on other sites

This means that either:

 

1) Your database connection wasn't made

2) There was an error in your mysql syntax, resulting in no result from your query.

 

It's almost definitely point two, as you missed the word 'from'. On that note, you really shouldn't use the '@' symbol, pretty much ever. It masks errors, which means that you miss problems like this. Change your query to read like this:

 

$result = mysql_query("select * from users") or die(mysql_error()); 

 

although I personally would use:

 

$result = mysql_query("select uid from users") or die(mysql_error()); 

 

As selecting '*' is inefficient, and in some cases can present a security issue.

Link to comment
Share on other sites

Hey, awesome the drop down shows now, but it doesn't show anything in the drop down...

 

What kind of security issue's does it create using the *?

 

did you change your $row['...'] 's to your actual column names?

 

* is inefficient because you are quering for more information than you need.  It selects every piece of data from every row and column of your table.  That takes more processing time and memory use.  It's a waste.  It's potentially dangerous because if someone manages to hack your scripts to dump all your variables in memory, well, for instance, your table could have a name and password column and then mr. hacker now has everybody's name and password.  Or credit card info, or whatever else your table might contain.

Link to comment
Share on other sites

Hey, awesome the drop down shows now, but it doesn't show anything in the drop down...

 

What kind of security issue's does it create using the *?

 

did you change your $row['...'] 's to your actual column names?

 

* is inefficient because you are quering for more information than you need.  It selects every piece of data from every row and column of your table.  That takes more processing time and memory use.  It's a waste.  It's potentially dangerous because if someone manages to hack your scripts to dump all your variables in memory, well, for instance, your table could have a name and password column and then mr. hacker now has everybody's name and password.  Or credit card info, or whatever else your table might contain.

 

Wow, I did not know that at all...Thank you for the tip!

 

I changed my field names yep, this is how it looks now

$result = mysql_query("select uid from users") or die(mysql_error());  
if (mysql_num_rows($result) > 0) { 
  print "<select name=\"select_name\">"; 
  while ($row = mysql_fetch_array($result)) { 
    print "<option value=\"" . $row['uid'] . "\">" . $row['first'] . "</option>\n"; 
  } 
  print "</select>"; 
} 
mysql_free_result($result);  
?>

Link to comment
Share on other sites

If you look at this code:

print "<option value=\"" . $row['uid'] . "\">" . $row['first'] . "</option>\n";

 

You are calling $row['uid'] and $row['first'], but you have only extracted 'uid' from the database. Since you haven't extracted 'first', all of the names will be empty in the drop down list, although the values will be there.

 

So you need to change your database query to this:

 

"select uid, first from users"

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.