Current location: Hot Scripts Forums » Programming Languages » PHP » Can anyone help me ? (problem using php variables in html db insert code)


Can anyone help me ? (problem using php variables in html db insert code)

Reply
  #1 (permalink)  
Old 06-13-04, 09:24 AM
chronic_ chronic_ is offline
Newbie Coder
 
Join Date: May 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Can anyone help me ? (problem using php variables in html db insert code)

can anyone help me, i've developed a secure login, admin panel, and user cp, but I want the user to be able to update their details when logged in, i've done a page where the user can update using a form if logged in and i've created the processing page, but i need php to add the form variables $email, and $website into a some html stored in a variable to be added to the database. The code has a problem on linea 7 and 8, the $emailcode and $websitecode lines, can you help me with how to add the php variables into the html code ?
here is the code:

userupdateprocess.php
===============

<?php
session_start();
$email = $_POST['email'];
$location = $_POST['location'];
$website = $_POST['website'];

$emailcode = print"<a href="mailto:"'.$email.'">"'.$email.'"</a>";
$websitecode = print"<a href="'.$website.'">"'.$website.'"</a>";

include("config.php"); //include config file
mysql_connect ($dbhost, $dbuser, $dbpass) or die ('My SQL Error: ' . mysql_error());
mysql_select_db ($dbname);
$query = "INSERT INTO users (email, location, website) VALUES ('$emailcode', '$location', '$websitecode') WHERE username='".$_SESSION['username]'."' AND password='".$_SESSION['password']."'");
mysql_query($query) or die ('update failed, please try again...');
echo("update successfull...");
?>



updateuser.php (php code only)
====================
<?php
session_start();?>

if(isset($_SESSION['username']) && isset($_SESSION['password'])){
print "Welcome to your personal control panel, ";
echo "<br>";
print $_SESSION['username'];
?> : <a href="logout.php">logout</a>
<form name="updateuser" action="userupdateprocess.php" method="post">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="ff6600">
+</font><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="ffa200">email:</font>
<input name="email" type="text">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="ff6600">+</font><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="ffa200">location:</font>
<input name="location" type="text"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="ff6600">
+</font><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="ffa200">website:</font>
<input name="website" type="text"><br><input name="submit" type="submit" id="submit" value="update"></form>
<?
}else{
print "<center>";
print "Welcome, you are not logged in,";
print "<br>";
print "please login below";
print "<br>";
print "to access personal control panel:";
print "</center>";
print "<br>";
include ("loginform.php");

?>
</font><font color="FFA200" size="1" face="Verdana, Arial, Helvetica, sans-serif"><?
}
?>


any ideas on how to fix the code:

$emailcode = print"<a href="mailto:"'.$email.'">"'.$email.'"</a>";
$websitecode = print"<a href="'.$website.'">"'.$website.'"</a>";

would be really appreciated....

thanks, chronic_
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-13-04, 10:44 AM
the_mole001's Avatar
the_mole001 the_mole001 is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Australia
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Hey There,

Looks like the only major problem i can see is before each bit u've written 'print'. You can't put this inside a varible and then try putting it into a mysql db (or at least not from my experience). Perhaps try just:

$emailcode = "<a href="mailto:"'.$email.'">"'.$email.'"</a>";
$websitecode = "<a href="'.$website.'">"'.$website.'"</a>";

Hope that helps,

-Peter
__________________
Current Project: GGAC Website
Project Link: http://peter.5gigs.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-13-04, 12:19 PM
chronic_ chronic_ is offline
Newbie Coder
 
Join Date: May 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
thanks mole001...

thanks mole001,

that didn't fix it but i resolved the problem earlier, i just inserted the plain text from $_POST into thedb and pulled it using:

----------------------------------------------------------------------------<?php
include("config.php"); //include config file
$db = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("cannot connect to database"); //create database connection variable, called 'db'

mysql_select_db($dbname,$db); //select the database, specify database name, then connect

$query = mysql_query ("SELECT * FROM `users` WHERE username='".$_SESSION['username']."' AND password='".$_SESSION['password']."'");
while ($myrow = mysql_fetch_array($query)){
?>
username:
<?php
print $myrow["username"];
?><br>
user id:
<?php
print $myrow["id"];
?><br>
e-mail:
<?php
print $myrow["email"];
?>


location:
<?php
print $myrow["location"];
?><br>
website: <a href="
<?php
print $myrow["website"];
?>
">
<?php
print $myrow["website"];
?>
</a>
<?php
}
}else{
print "<center>";
print "Welcome, you are not logged in,";
print "<br>";
print "please login below";
print "<br>";
print "to access personal control panel:";
print "</center>";
print "<br>";
include ("loginform.php");
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 04:06 AM
Form -> text file -> php variables Bonzo PHP 1 06-16-04 08:37 AM
PHP code on a remote file tonniar .rm PHP 2 05-24-04 03:32 AM
PHP Code Help matt001 PHP 2 05-23-04 12:26 AM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 01:10 PM


All times are GMT -5. The time now is 11:04 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.