passing the value from a text box to a varible

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aido82
    New Member
    • Jan 2007
    • 3

    passing the value from a text box to a varible

    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
  • Aido82
    New Member
    • Jan 2007
    • 3

    #2
    this is all the code

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

    <?
    //declar varibles

    //$userName = ;
    $userName=$_POS T['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 `customerdetail s` ( `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="registe red.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="custFirst Name" size="15" maxlength="15" value="<?php if (isset($_POST['custFirstName'])) echo $_POST['custFirstName']; ?>" /></p>

    <p><b>Last Name:</b> <input type="text" name="custLastN ame" 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>

    Comment

    • cassbiz
      New Member
      • Oct 2006
      • 202

      #3
      Originally posted by Aido82
      this is all the code

      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

      Code:
      <p><b>User Name:</b> <input type="text" name="userName" id ="userName" size="10" maxlength="20" value="<?php $userName ?>" /></p>

      Comment

      Working...