using variables in another page


Posted on 16th Feb 2014 07:03 pm by admin

I have a test database set up on localhost. I have a form that I can type a name into, hit the button and it puts the name into the database and into a list on my page. it works fine. Now, I wanted to make a drop down list with all the names so that you could select one to remove that name from the database. So I did this

Code: [Select]<form>
<select>
<option><?php echo $name ?></option>
</select>
</form>

What that did was list the very last name in the list. What I thought it would do was list all the names based on the loop that I have set up to read all the names from the database. which is this

Code: [Select]$mysql = new mysqli('localhost', 'myusername', 'mypass', 'mydatabase') or die('not working');

$result = $mysql->query("SELECT * FROM myTable") or die($mysql->error);

if($result)
{
while($row = $result->fetch_object())
{
$name = $row->names;
echo $name . "<br />";
}
}

Now the while loop is in a file I called results and it is included in the index page with an include. I thought this would give me access to the $name variable and allow me to use it the same way it's being used in the loop. of course I was wrong, so how do I use it the same way?

No comments posted yet

Your Answer:

Login to answer
232 Like 38 Dislike
Previous forums Next forums
Other forums

IS Retail & Manufacturing
Hi

Can IS Retail and Manufacturing activities be done in same instance ie. in same client

Multiple includes losing variables
Hey all,

just starting out w php and ran into a problem pretty quickly. I'm
including seve

PHP & Java
Hello,

can PHP code be used inside java code?

Code: [Select]<SCRIPT LANGUAGE=&q

Detail Expenses Report by Cost Center
I would like to obtain a report out of SAP that shows a list of expenses by cost center that shows t

Multiple Pages
Hi. Im very new to php. I'm trying to create a basic login/registration page.

So I have a bas

regex for quoted text within a string
I am still getting the hang of regex expressions, but I cant seem to figure out how I would escape q

empty() error
Why does

Code: empty($USER_ID = $_SESSION["USER_ID"])
create this error...

New to Arrays
Hi I am new to PHP (a week and a half now) and I am just beginning to read about arrays. I understan

Why is my row count 0?
Here's the MySQL query i'm running. It basically pulls data from 2 tables based on some data passed.

query based on 2 conditions
I want to select if the doc_type is either s OR f but this doesn't work:

Code: [Select]$query

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash