Announcement

Collapse
No announcement yet.

Having php output show up in an html form

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Having php output show up in an html form

    is there a way to have something you put in a php form output into a chosen html form? I'm trying to echo it but it doesn't seem to take.
    HTML Code:
    <input id="input" type="text"  value= "<?php echo $sitename;?>">
    is what i'm putting into my html form. it doesn't seem to work. any ideas? i don't think it should be as hard as i think it is

    PHP Code:
    <html>
    <head>
    </head>
    <body>



    <form action="insertsiteform.php" method="post">
    Site: <input type="text" name="sitename"><br/>
    <input type="submit" name="submit">

    </form>


    <?php
    if (isset($_POST['submit'])) {


    $con mysql_connect("localhost","DATABASE","PASSWORD");
    if (!
    $con) {
    die (
    "can't connect" mysql_error());
    }

    mysql_select_db("DATABASE"$con);

    $sql "INSERT INTO search (site) VALUES ('$_POST[sitename]')";


    mysql_query($sql,$con);




    mysql_close($con);
    }
    ?>



    <?php



    $con 
    mysql_connect("localhost","DATABASE","PASSWORD");
    if (!
    $con) {
    die (
    "can't connect" mysql_error());
    }

    mysql_select_db("DATABASE",$con);

    $sql "SELECT * FROM search";
    $myData mysql_query($sql,$con);
    while(
    $record mysql_fetch_array($myData)){
    echo 
    $record['site'] ;

    ;
    echo 
    "<br />";

    }
    mysql_close($con);

    ?>


    </body>
    </html>
    Last edited by rubecuber; 04-24-2016, 05:06 PM.

  • #2
    I would lay the code out this way, it just flows better
    PHP Code:
    <?php
    if (isset($_POST['submit'])) {


    $con mysql_connect("localhost","USER","PASSWORD");
    if (!
    $con) {
    die (
    "can't connect" mysql_error());
    }

    mysql_select_db("DATABASE"$con);

    $sql "INSERT INTO search (site) VALUES ('{$_POST["sitename"]}')";


    mysql_query($sql,$con);
    }
    ?>

    <html>
    <head>
    </head>
    <body>



    <form action="insertsiteform.php" method="post">
    Site: <input type="text" name="sitename"><br/>
    <input type="submit" name="submit">

    </form>


    <?php


    $sql 
    "SELECT site FROM search";
    $myData mysql_query($sql,$con);
    while(
    $record mysql_fetch_array($myData)){
    echo 
    $record['site'];
    echo 
    "<br />";

    }
    mysql_close($con);

    ?>


    </body>
    </html>
    Can you verify that the site is getting into the database? Do you see any errors? Also not sure if it was a typo but I change DATABASE to USER in your connection string.
    Last edited by scoutt; 05-03-2016, 08:30 AM.
    Have a Script or Snippet you want to share?

    WWW Standards: HTML 4.01,
    HTML 5, CSS2.1, CSS3, XHTML 1.0
    PHP Standards: PHP Standards

    Comment


    • #3
      hey, thanks, yep the database instead of user was a typo, thank you.

      Comment

      Working...
      X