سؤال

Okay so, I've posted this already but still haven't found a solution. I can't seem make my form stay on the same page and I've basically tried EVERYTHING I could possibly think of.

    <?php include("inc\incfiles\header.inc.php"); ?>
    <?php
      $reg = @$_POST['reg'];
       //declaring variables to prevent errors 
         $fn = $ln = $un = $em = $em2 = $pswd = $pswd2 = $d = $u_check = ""; 

       /*$fn = ""; //First Name
         $ln = ""; //Last Name
         $un = ""; //Username
         $em = ""; //Email
         $em2 = ""; //Email 2
         $pawd = ""; //:Password
         $pawd2 = ""; //Password 2
         $d = ""; //Sign up Date
         $u_check = ""; //Check if username exists*/
         //registration form
         $fn = mysql_real_escape_string(@$_POST['fname']);
         $ln = mysql_real_escape_string(@$_POST['lname']); 
         $un = mysql_real_escape_string(@$_POST['username']); 
         $em = mysql_real_escape_string(@$_POST['email']); 
         $em2 = mysql_real_escape_string(@$_POST['email2']); 
         $pswd = mysql_real_escape_string(@$_POST['password']); 
         $pswd2 = mysql_real_escape_string(@$_POST['password2']); 
         $d = date("Y-m-d"); //Year - Month - Day 

       if ($reg) 
       { 
       //check all of the fields have been filled in
       if ($fn && $ln && $un && $em && $em2 && $pswd && $pswd2) {

       }
       else{
       echo "please fill in all fields...";
        }
        }
        ?>

       <table class="homepageTable">
        <tr>

    <td width="60%" valign="top">
    <center><h2>Join the community today!</h2></center>
<center><img src="images/photo.png" width="500"></center>
 <form>
</td>
<td width="40%" valign="top">
<h2>Get started below...</h2>  
<form action="#" method="post">
      <input type="text" size="25" name="firstname" placeholder="First Name" value="<?php echo $fn; ?>"/>
      <input type="text" size="25" name="lastname" placeholder="Last Name" value="<?php echo $ln; ?>"/>
      <input type="text" size="25" name="username" placeholder="Username" value="<?php echo $un; ?>"/>
      <input type="text" size="25" name="email" placeholder="Email" value="<?php echo $em; ?>">
      <input type="text" size="25" name="email2" placeholder="Repeat Email" value="<?php echo $em2; ?>"/>
      <input type="password" size="32" name="password" placeholder="Password"/>
      <input type="password" size="32" name="password2" placeholder="Repeat Password"/><br />
      <input type="submit" name="reg" value="Sign Up!"/>

      </form>
      </td>
        </tr>

        </table>

My biggest problem is with the:

<form action="#" method="post">
      <input type="text" size="25" name="firstname" placeholder="First Name" value="<?php echo $fn; ?>"/>
      <input type="text" size="25" name="lastname" placeholder="Last Name" value="<?php echo $ln; ?>"/>
      <input type="text" size="25" name="username" placeholder="Username" value="<?php echo $un; ?>"/>
      <input type="text" size="25" name="email" placeholder="Email" value="<?php echo $em; ?>">
      <input type="text" size="25" name="email2" placeholder="Repeat Email" value="<?php echo $em2; ?>"/>
      <input type="password" size="32" name="password" placeholder="Password"/>
      <input type="password" size="32" name="password2" placeholder="Repeat Password"/><br />
      <input type="submit" name="reg" value="Sign Up!"/>

      </form>

I want to be able to press the submit button and have it stay on the same page. I've tried leaving the blank I've tried a few other suggestions but I keep coming up with nothing. I've been trying to figure it out for 2 days now and it just won't budge. When pressing the submit button on my site in xampp, it just takes me to another page that says OBJECT NOT FOUND...etc.

If anyone can help, it would be greatly appreciated! I really don't want to have to start all over with my coding just because of one mistake.

Header.inc.php

<?php 
include("inc/scripts/mysql_connect.inc.php"); 
?> 
<html>
<head>
<link href="css\main.css" rel="stylesheet" type="text/css"> 
<title>website</title>
</head>
<body>
<div class="headerMenu">
 <div id="wrapper">
      <div class="logo">
          <img src="images/Logo.png">
      </div>
      <div class="search_box">
            <form method="GET" action="search.php" id="search">
            <input name="q" type="text" size="60" placeholder="Search..."
            </form>
      </div>
      <div id="menu">
        <a href="#">Home</a>
        <a href="#">About</a>
        <a href="#">Sign Up</a>
        <a href="#">Log in</a>
     </div>
</div>
<br />
<br />
<br />
<br />
هل كانت مفيدة؟

المحلول 3

Your problem is this line in your inc\incfiles\header.inc.php

<input name="q" type="text" size="60" placeholder="Search..."

You are missing the closing bracket -

<input name="q" type="text" size="60" placeholder="Search..." />
                                                              ^^

because of that, the closing form tag on the next line is not beinging parsed, so your form in index.php is being nestled inside the <form method="GET" action="search.php" id="search">

نصائح أخرى

By staying on the same page , I think you mean you want to submit the page , refresh & send data. if you mean that , so you may use this as your tag :

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" >

However , if you want your page not to be refreshed , you need to work with Jquery , JavaScript etc.

Instead of form action="#" write form action="" Notice there are 2 ticks with nothing in between.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top