Jump to content

Drop Boxes, Input To Database?


KYKK

Recommended Posts

I have a page that is for input drop box, and text boxes...

<?phpsession_start();require_once 'db.php';if (isset($_SESSION['user_id'])){$sql = "SELECT * FROM `users` WHERE `name` = '{$_SESSION['user_name']}'";$result = mysql_query($sql);while($row = mysql_fetch_array($result)){$name = $row['name'];}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><script type="text/javascript">            da = [31,28,31,30,31,30,31,31,30,31,30,31];            function set_days () {                var d;                var date;                var opt_str = "";                var m = Months.options[Months.selectedIndex].value;                var y = Years.options[Years.selectedIndex].value;                if (m != 1) {                    d = da[m];                } else {                    date = new Date("February 29, " + y);                    d = date.getMonth() == 1 ? 29: 28; // IT'S A LEAP YEAR                }                empty_select (Days);                for (var i = 1; i <= d; i++) {                    j = i.toString();                    insertOption (Days, j, j)                }            }            function insertOption (s, t, v) {                var y = document.createElement('option');                y.text = t;                y.value = v;                try {                    s.add (y, null); // standards compliant                } catch (ex) {                    s.add (y); // IE only                }            }            function empty_select (s) {                while (s.length > 0) {                    s.remove(s.length-1);                }            }            function init () {                Months = document.getElementById("months");                Years = document.getElementById("years");                Days = document.getElementById("days");                Months.onchange = set_days;                Years.onchange = set_days;            }            window.onload = init;        </script></head>  <body>    Hello, <?php echo $_SESSION['user_name']; ?>, <?php$sql = "SELECT * FROM `users` WHERE `name` = '{$_SESSION['user_name']}'";$result2 = mysql_query($sql);while($row = mysql_fetch_array($result2)){echo $row['webtitle<br>'];echo $row['name<br>'];echo $row['themecontent<br>'];}?>    <form action="index.php?page=updateblog" method="post">    <input type="hidden" name="page_mode" value="">	  <select id="months">                <option value="0">January</option>                <option value="1">February</option>                <option value="2">March</option>                <option value="3">April</option>                <option value="4">May</option>                <option value="5">June</option>                <option value="6">July</option>                <option value="7">August</option>                <option value="8">September</option>                <option value="9">October</option>                <option value="10">November</option>                <option value="11">December</option>            </select>            <select id="days">                <option value="1">1</option>                <option value="2">2</option>                <option value="3">3</option>                <option value="4">4</option>                <option value="5">5</option>                <option value="6">6</option>                <option value="7">7</option>                <option value="8">8</option>                <option value="9">9</option>                <option value="10">10</option>                <option value="11">11</option>                <option value="12">12</option>                <option value="13">13</option>                <option value="14">14</option>                <option value="15">15</option>                <option value="16">16</option>                <option value="17">17</option>                <option value="18">18</option>                <option value="19">19</option>                <option value="20">20</option>                <option value="21">21</option>                <option value="22">22</option>                <option value="23">23</option>                <option value="24">24</option>                <option value="25">25</option>                <option value="26">26</option>                <option value="27">27</option>                <option value="28">28</option>                <option value="29">29</option>                <option value="30">30</option>                <option value="31">31</option>            </select>            <select id="years">                <option value="2008">2008</option>                <option value="2009">2009</option>            </select>    <div class="left_box">subcontent</div>    <div class="right_box"><input type="text" name="subcontent" size="30" maxlength="255" value=""></div>        <div class="left_box">content</div>    <div class="right_box"><textarea name='content' rows='15' cols='40'></textarea></div>    <div class="left_box"> </div>    <div class="right_box"><input type="submit" value="update" size="30"></div>    <br><br>    <a href="logout.php">Log out</a>    <?php    }    else    {    ?>    Click <a href="register.php">here</a> to register or click <a href="login.php">here</a> to log in.    <?php    }    ?>   </body></html>

and it will go to updateblog.php to update...

<?phprequire_once 'db.php';$sql = "SELECT * FROM `users` WHERE `name` = '{$_SESSION['user_name']}'";$result = mysql_query($sql);while($row = mysql_fetch_array($result)){$name = $row['name'];}$date = $_POST['date'];$content = $_POST['content'];$subcontent = $_POST['subcontent'];$days = $_POST['days'];$months = $_POST['months'];$years = $_POST['years'];if (isset($_SESSION['user_id'])){if ($_POST['date'] != ''){mysql_query("INSERT INTO blog (name, date, day, months, years, subcontent, content) VALUES ('$name', '$date', '$days', '$months', '$years', '$subcontent', '$content')");}	if ($_POST['days'] == '')	{	echo "there nothing in day box<br>";	}	if ($_POST['months'] == '')	{	echo "there nothing in month box<br>";	}	if ($_POST['years'] == '')	{	echo "there nothing in year box<br>";	}	if ($_POST['subcontent'] == '')	{	echo "there nothing in subcontent box<br>";	}if ($_POST['content'] == ''){echo "there nothing in content box<br>";}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><body>    <a href="index.php">Update Index</a>	<a href="blog.php">Update Blog</a>    <a href="logout.php">Log out</a>	    <?php    }    else    {    ?>    Click <a href="register.php">here</a> to register or click <a href="login.php">here</a> to log in.    <?php    }    ?>

but some how it say there nothing in day boxthere nothing in month boxthere nothing in year boxso $_POST['days']$_POST['months]$_POST['years']have no data, but i did$days = $_POST['days'];$months = $_POST['months'];$years = $_POST['years'];and do that mean drop box don't use $_POST[''] ?

Link to comment
Share on other sites

I think it work, but there some problem with my login, register system...this my register page

<?phprequire_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'register'){  $email = trim($_POST['email']); // trim to remove whitespace  $name = trim($_POST['name']); // trim to remove whitespace  $password = $_POST['password'];  $conf_password = $_POST['conf_password'];  if (!isValidEmail($email))    $error_string .= 'Please enter a valid email address.<br>';  if ($name == '')    $error_string .= 'Please enter your name.<br>';  if (strlen(trim($password)) < 6)    $error_string .= 'You must enter a password of at least 6 characters.<br>';  if ($password != $conf_password)    $error_string .= 'The password and confirmation password do not match.<br>';  if ($error_string == '')  {    $result = db_query("SELECT id FROM users WHERE email='" . mysql_real_escape_string($email) . "'");    if (mysql_num_rows($result) > 0)      $error_string .= 'That email address is already registerd.<br>';    else    {      $email = mysql_real_escape_string($email); // protect against SQL attacks      $name = mysql_real_escape_string($name);      $password = sha1($password); // hash password            db_query("INSERT INTO users (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");      header('Location: thankyou.php');      exit();    }  }}function isValidEmail($email = ''){    return preg_match("/^[\d\w\/+!=#|$?%{^&}*`'~-][\d\w\/\.+!=#|$?%{^&}*`'~-]*@[A-Z0-9][A-Z0-9.-]{1,61}[A-Z0-9]\.[A-Z]{2,6}$/ix",$email);}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>  <body>    <div class="error_text"><?php echo $error_string; ?></div>    <form action="index.php?page=register" method="post">    <input type="hidden" name="page_mode" value="register">    <div class="left_box">Email address</div>    <div class="right_box"><input type="text" name="email" size="30" maxlength="255" value="<?php if (isset($email)) echo $email; ?>"></div>    <div class="left_box">Name</div>    <div class="right_box"><input type="text" name="name" size="30" maxlength="255" value="<?php if (isset($name)) echo $name; ?>"></div>    <div class="left_box">Password</div>    <div class="right_box"><input type="password" name="password" size="30"></div>    <div class="left_box">Confirm Password</div>    <div class="right_box"><input type="password" name="conf_password" size="30"></div>    <div class="left_box"> </div>    <div class="right_box"><input type="submit" value="Register" size="30"></div>    </form>

it keep saying Please enter a valid email address. i check the codes, but I don't see any error... (of course i did put in a valid email address)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...