Connecting Tech Pros Worldwide Forums | Help | Site Map

passing the value from a text box to a varible

Newbie
 
Join Date: Jan 2007
Posts: 3
#1: Jan 15 '07
Hi, this is probably a stupid question.

Im trying to declare a varible to have the value of that in a text box

when i declare the varible is there a way to give it the value in a text box called area.

i was trying the way below but it puts the word username in the database

$userName = 'username';

then in the form i used

<p><b>User Name:</b> <input type="text" name="userName" size="10" maxlength="20" value="<?php ($_post['$userName']) ?>" /></p>

doesnt seem to work thought
any ideas

Newbie
 
Join Date: Jan 2007
Posts: 3
#2: Jan 15 '07

re: passing the value from a text box to a varible


this is all the code

<html>
<body>
<link rel=stylesheet href="Stylesheet.css" type="text/css">
</body>

<?
//declar varibles

//$userName = ;
$userName=$_POST['userName'];
$title=$_POST['title'];
//$tel=$_POST['tel'];




$conn = mysql_connect("localhost", "root", "") or die('could not connect to mysql' .mysql_error());

mysql_select_db('customer', $conn) or die('could not connect to DB' .mysql_error());

// Make the query.
//$query = "INSERT INTO customerdetails (userName, password, title, custFirstName, custLastName, email) VALUES ('$userName', '$password', '$title' '$custFirstName', '$custLastName', '$email')";

$query = "INSERT INTO `customerdetails` ( `custID` , `userName` , `password` , `title` , `custFirstName` , `custLastName` , `email` , `address1` , `address2` , `address3` , `country` , `telephone` )

VALUES (NULL , '$userName', '$password', '$title', '$custFirstName', '$custLastName', '$email', '312 daneswell road', '2glasnevin', '2dublin 9', '2ireland', '21800 111 111')";


$result = @mysql_query ($query); // Run the query.

//echo '<p><b>You have been registered!</b></p>';

mysql_close(); // Close the database connection.


?>

<form action="registered.php" method="post"><fieldset>
<legend>Enter your information in the form below:</legend>

<p><b>User Name:</b> <input type="text" name="userName" id ="userName" size="10" maxlength="20" value="<?php ($_post['$userName']) ?>" /></p>

<p><b>Password:</b> <input type="password" name="password" id ="password" size="20" maxlength="20" value ="<?php if (isset($_POST['password'])) echo $_POST['password']; ?>"/></p>

<p><b>Title:</b> <input type="text" name="title" id ="title" size="15" maxlength="15" value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" /></p>

<p><b>First Name:</b> <input type="text" name="custFirstName" size="15" maxlength="15" value="<?php if (isset($_POST['custFirstName'])) echo $_POST['custFirstName']; ?>" /></p>

<p><b>Last Name:</b> <input type="text" name="custLastName" size="30" maxlength="30" value="<?php if (isset($_POST['custLastName'])) echo $_POST['custLastName']; ?>" /></p>

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>



</fieldset>

<div align="center"><input type="submit" name="submit" value="Register" /></div>

</form>

</html>
cassbiz's Avatar
Familiar Sight
 
Join Date: Oct 2006
Location: Florida
Posts: 204
#3: Jan 15 '07

re: passing the value from a text box to a varible


Quote:

Originally Posted by Aido82

this is all the code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <link rel=stylesheet href="Stylesheet.css" type="text/css">
  4. </body>
  5.  
  6. <?        
  7. //declar varibles
  8.  
  9. //$userName = ;
  10. $userName=$_POST['userName'];
  11. $title=$_POST['title'];
  12. //$tel=$_POST['tel']; 
  13.  
  14.  
  15.  
  16.  
  17. $conn = mysql_connect("localhost", "root", "") or die('could not connect to mysql' .mysql_error()); 
  18.  
  19.         mysql_select_db('customer', $conn) or die('could not connect to DB' .mysql_error());
  20.  
  21.         // Make the query.
  22.             //$query = "INSERT INTO customerdetails (userName, password, title, custFirstName, custLastName, email) VALUES ('$userName', '$password', '$title' '$custFirstName', '$custLastName', '$email')";    
  23.  
  24.             $query = "INSERT INTO `customerdetails` ( `custID` , `userName` , `password` , `title` , `custFirstName` , `custLastName` , `email` , `address1` , `address2` , `address3` , `country` , `telephone` ) 
  25.  
  26.             VALUES (NULL , '$userName', '$password', '$title', '$custFirstName', '$custLastName', '$email', '312 daneswell road', '2glasnevin', '2dublin 9', '2ireland', '21800 111 111')";
  27.  
  28.  
  29.             $result = @mysql_query ($query); // Run the query.
  30.  
  31.                 //echo '<p><b>You have been registered!</b></p>';
  32.  
  33.         mysql_close(); // Close the database connection.
  34.  
  35.  
  36. ?>
  37.  
  38. <form action="registered.php" method="post"><fieldset>
  39. <legend>Enter your information in the form below:</legend>
  40.  
  41. <p><b>User Name:</b> <input type="text" name="userName" id ="userName" size="10" maxlength="20" value="<?php ($_post['$userName']) ?>" /></p>
  42.  
  43. <p><b>Password:</b> <input type="password" name="password" id ="password" size="20" maxlength="20" value ="<?php if (isset($_POST['password'])) echo $_POST['password']; ?>"/></p>
  44.  
  45. <p><b>Title:</b> <input type="text" name="title" id ="title" size="15" maxlength="15" value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" /></p>
  46.  
  47. <p><b>First Name:</b> <input type="text" name="custFirstName" size="15" maxlength="15" value="<?php if (isset($_POST['custFirstName'])) echo $_POST['custFirstName']; ?>" /></p>
  48.  
  49. <p><b>Last Name:</b> <input type="text" name="custLastName" size="30" maxlength="30" value="<?php if (isset($_POST['custLastName'])) echo $_POST['custLastName']; ?>" /></p>
  50.  
  51. <p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>
  52.  
  53.  
  54.  
  55. </fieldset>
  56.  
  57. <div align="center"><input type="submit" name="submit" value="Register" /></div>
  58.  
  59. </form>
  60.  
  61. </html>
  62.  


you are already defining $_POST['$userName']; in the beginning

Expand|Select|Wrap|Line Numbers
  1. <p><b>User Name:</b> <input type="text" name="userName" id ="userName" size="10" maxlength="20" value="<?php $userName ?>" /></p>
Reply