GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Aug-2006, 15:11
mrjameer mrjameer is offline
New Member
 
Join Date: Aug 2006
Posts: 19
mrjameer is on a distinguished road
Question

php/mysql getting column values from db into textbox on a form


iam storing a variable in db as follows
$str='<html><b>ABCD</b></html>';
by using insert query,i put it in mysql db.

in my second program iam creating one textbox and inserting it in db as follows
$textbox1='name<input type="text" name="t1" value="<?php echo $str;?>">';
by using insert query iam storing it in db....

finally i have written a third program to retrieve these textboxes with $str values from db;but iam getting textbox with <?php echo $str;?> value.but i want to get <html><b>ABCD</b></html> in that textbox.please tell me how to do it.

mrjameer
  #2  
Old 18-Aug-2006, 15:28
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: php/mysql getting column values from db into textbox on a form


you can't put in code like you would to run it inside an HTML page. you to fully construct the string via concatenation...

PHP Code:

$textbox1 = "name<input type=\"text\" name=\"t1\" value=\"" . $str ."\">"; 


__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
  #3  
Old 21-Aug-2006, 06:00
mrjameer mrjameer is offline
New Member
 
Join Date: Aug 2006
Posts: 19
mrjameer is on a distinguished road
Smile

Re: php/mysql getting column values from db into textbox on a form


here is the code and help me where i was wrong
//program for storing html code in db
PHP Code:

<?php
$var1='<html><b>ABCD</b></html>';
$var2='<html><h3>EFGH</h3></html>';
$var3='<html><b>IJKL</b></html>';
$var4='<html><b>MNOP</b></html>';

$conn4=mysql_connect("localhost","","");
mysql_select_db("mrj",$conn4);
function escape_quotes( $html ) 
{ 
if ( get_magic_quotes_gpc() ) 
{ 
return( $html ); 
} 
else 
{ 
return( addslashes( $html ) ); 
} 
} 

$var1 = escape_quotes( $var1 ); 
$var2 = escape_quotes( $var2 ); 
$var3 = escape_quotes( $var3 ); 
$var4= escape_quotes( $var4 ); 
$sql="INSERT INTO mak VALUES('$var1','$var2','$var3','$var4')";
$result=mysql_query($sql,$conn4);
echo "record inserted";
?>


//program for storing textboxes with some values in db
PHP Code:

<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("mrj",$conn4);

$va1='variable1<input  type="text" name="vars1" size="35" value ="' .$var1.'"><br>';
$va2='variable2<input type="text" name="vars2" size="35" value ="' .$var2.'"><br>';
$va3='variable3<input type="text" name="vars3" size="35" value ="' .$var3.'"><br>';

$va4='variable4<input type="text" name="vars4" size="35" value ="' .$var4.'"><br>';$updates='<input type="submit" value="update" onclick="this.form.action=\'upd.php\'"><br>';

function escape_quotes( $html ) 
{ 
if ( get_magic_quotes_gpc() ) 
{ 
return( $html ); 
} 
else 
{ 
return( addslashes( $html ) ); 
} 
} 

$va1 = escape_quotes( $va1 ); 
$va2 = escape_quotes( $va2 ); 
$va3 = escape_quotes( $va3 ); 
$va4 = escape_quotes( $va4 ); 
$updates = escape_quotes( $updates ); 

$sql="INSERT INTO sampl1 VALUES('$va1','$va2','$va3','$va4','$updates')";
$result=mysql_query($sql,$conn4) or die (mysql_error());
echo "record inserted";
?>


//program for retriving the textboxes with the values from db (the values which i stored in db by writing first program)
PHP Code:

<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("mrj",$conn4);
$sql="SELECT * FROM sampl1";
$result=mysql_query($sql,$conn4);
while($newarray=mysql_fetch_array($result))
{
$va1=$newarray['va1'];
$va2=$newarray['va2'];
$va3=$newarray['va3'];
$va4=$newarray['va4'];
$updates=$newarray['updates'];
echo $va1."".$va2."".$va3."".$va4."".$updates;
}
?>



iam getting blank textboxes or getting some value like <?php $var1;?>
help me i was strucked.
Last edited by LuciWiz : 21-Aug-2006 at 06:44. Reason: Please insert your Php code between [php] & [/php] tags
  #4  
Old 22-Aug-2006, 09:08
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: php/mysql getting column values from db into textbox on a form


In your second script above... print out the values for $var1, $var2, $var3, and $var4... or use a tool like phpmyadmin to see what these values are in the database.

I wouldn't think that they are being stored properly (if the scripts are actually broken into sections like you have displayed). You would need a SELECT query in the second script to retrieve the variables.

Code:
<?php $conn4=mysql_connect("localhost","",""); mysql_select_db("mrj",$conn4); //-----------------------// //This is the added code // //-----------------------// $sql="SELECT * FROM mak"; $result=mysql_query($sql,$conn4); $row = mysql_fetch_array($result); //-----------------------// $va1='variable1<input type="text" name="vars1" size="35" value ="' . $row['var1'] . '"><br>'; $va2='variable2<input type="text" name="vars2" size="35" value ="' . $row['var2'] . '"><br>'; $va3='variable3<input type="text" name="vars3" size="35" value ="' . $row['var3'] . '"><br>'; $va4='variable4<input type="text" name="vars4" size="35" value ="' . $row['var4'] . '"><br>'; $updates='<input type="submit" value="update" onclick="this.form.action=\'upd.php\'"><br>'; //....

See if that fixes it... if not, let me know, and we can keep at it.

PS: Sorry about the formatting... if I put the code in the PHP tags, it would show all of the code on 1 line for some reason... so, I just put it in the generic CODE tag.
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
  #5  
Old 23-Aug-2006, 04:36
mrjameer mrjameer is offline
New Member
 
Join Date: Aug 2006
Posts: 19
mrjameer is on a distinguished road
Question

Re: php/mysql getting column values from db into textbox on a form


treyAU21

thanks a lot.i got the result with your code.i want to know that iam using the following code for storing a variable in db,is it correct or not

for storing in db:
$var11='<b>ABCD</b>';
$var1 = htmlentities($var11);

iam retriving the variable from db and passing it through html_entity_decode(variable name):
$v1 = html_entity_decode($var1);

if i use above format then iam getting the correct output what i want.is it correct or i have to follow some other.please tell me.

my second question is that i want to create a horizontal menu in which one end is asusual but the other end should be like cross cut means like following format.

|------------------------------------\
|-------------------------------------\

mrjameer
  #6  
Old 23-Aug-2006, 06:39
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 889
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: php/mysql getting column values from db into textbox on a form


Quote:
Originally Posted by TreyAU21
PS: Sorry about the formatting... if I put the code in the PHP tags, it would show all of the code on 1 line for some reason... so, I just put it in the generic CODE tag.

Hello, Trey.

I wanted to edit your post, and when I hit "Preview Changes", the code looked all right to me (see bellow). If that is not what it looked like to you, please let me know, and I will pass it to the admin.

PHP Code:

<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("mrj",$conn4);

//-----------------------//
//This is the added code //
//-----------------------//
$sql="SELECT * FROM mak";
$result=mysql_query($sql,$conn4);
$row = mysql_fetch_array($result);
//-----------------------//

$va1='variable1<input  type="text" name="vars1" size="35" value ="' . $row['var1'] . '"><br>';
$va2='variable2<input type="text" name="vars2" size="35" value ="' . $row['var2'] . '"><br>';
$va3='variable3<input type="text" name="vars3" size="35" value ="' . $row['var3'] . '"><br>';
$va4='variable4<input type="text" name="vars4" size="35" value ="' . $row['var4'] . '"><br>';
$updates='<input type="submit" value="update" onclick="this.form.action=\'upd.php\'"><br>';

//....


Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #7  
Old 23-Aug-2006, 08:21
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: php/mysql getting column values from db into textbox on a form


Hey Lucian,

No matter what I did, it sould strip out all of the line breaks. The code would appear in one line. I edited it several times... going through and and manually hitting enter after every line... copying to notepad and copying it back... and others.

Looks like it's working in this post below vvvvv... so maybe it was a fluke?

PHP Code:

<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("mrj",$conn4);

//-----------------------//
//This is the added code //
//-----------------------//
$sql="SELECT * FROM mak";
$result=mysql_query($sql,$conn4);
$row = mysql_fetch_array($result);
//-----------------------//

$va1='variable1<input  type="text" name="vars1" size="35" value ="' . $row['var1'] . '"><br>';
$va2='variable2<input type="text" name="vars2" size="35" value ="' . $row['var2'] . '"><br>';
$va3='variable3<input type="text" name="vars3" size="35" value ="' . $row['var3'] . '"><br>';
$va4='variable4<input type="text" name="vars4" size="35" value ="' . $row['var4'] . '"><br>';
$updates='<input type="submit" value="update" onclick="this.form.action=\'upd.php\'"><br>';

//....

__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/MySQL coding issue cmarti MySQL / PHP Forum 3 26-Jul-2004 08:01
help with form orbitel MySQL / PHP Forum 11 21-Jan-2004 15:29

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:31.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.