Page 1 of 1

getting url from db

Posted: Mon May 03, 2010 7:34 pm
by nite4000
hey all.

I have a table in a db and i have id,name,url and url is the website location of the name.

here is my drop box code

Code: Select all

<select name="box" class="textbox" id="box">
                <?php $r=mysql_query("select * from table WHERE status='On'")or die(mysql_error());
							 while($row = mysql_fetch_array($r,MYSQL_ASSOC)) {
							 echo '<option value="'.$row['name'].'">'.$row['name'].'</option>';
							 }
							 ?>
I have it saving the name to another table however I want to also save teh url to that same table
here is my insert code

Code: Select all

 $q = mysql_query("INSERT INTO members(id,box,box_url)VALUES(null,'$box','$box_url')")or die( mysql_error() );
IT dont save anything in the box_url field in members and I cant figure out why

Please help

Re: getting url from db

Posted: Mon May 03, 2010 11:00 pm
by a94060
Are these both in the same script? If so, you should put the second query into the same loop.You can then just use the $row array to hold your elements. Also,I dont see where $box/$box_url are being declared.

Re: getting url from db

Posted: Tue May 04, 2010 9:10 am
by jaiswarvipin
as per my understanding you need once the drop down ist get loded same time the your "box_url" filed get inserted by "url" filed ofsource table and "box" with "name" respactively.

so please refer the below code

Code: Select all

<select name="box" class="textbox" id="box">
<?php $r=mysql_query("select * from table WHERE status='On'")or die(mysql_error());
         while($row = mysql_fetch_array($r,MYSQL_ASSOC)) 
         {
               box_url = str_replace("'","'",$row['url']);
               box = str_replace("'","'",$row['name']);
                $q = mysql_query("INSERT INTO members(id,box,box_url)VALUES(null,'".$box."','".$box_url."')")or die( mysql_error() );
               echo '<option value="'.$row['name'].'">'.$row['name'].'</option>';
        }