passing the value from a text box to a varible | Newbie | | Join Date: Jan 2007
Posts: 3
| | |
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
| | | 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>
|  | Familiar Sight | | Join Date: Oct 2006 Location: Florida
Posts: 204
| | | re: passing the value from a text box to a varible Quote:
Originally Posted by Aido82 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>
-
you are already defining $_POST['$userName']; in the beginning - <p><b>User Name:</b> <input type="text" name="userName" id ="userName" size="10" maxlength="20" value="<?php $userName ?>" /></p>
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|