getting url from db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

getting url from db

Post 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
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: getting url from db

Post 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.
jaiswarvipin
Forum Commoner
Posts: 32
Joined: Sat Sep 12, 2009 3:43 pm
Location: India

Re: getting url from db

Post 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>';
        }
Post Reply