0

Hi,
This is my first post.I just starting php Hope everyone reply me as possible as.
I have signup problem.When i filled the form and click sign up button then it nothing show any result i mean its not home.php "welcome" message and also not store date in my mysql bd.
here is the code:

<html>
<head>this is sign up page</head>
<body>
<form action="jhome.php" method="POST"><center>
Username:
<input type="text" name="username" id="username"/><br /><br />
Password:
<input type="password" name="password" id="password"/><br /><br />
Email:
<input type="text" name="email" id="email"/><br /><br />
<input type="submit" name="submit" value="Sign Up"/>

</center>
</form>

</body>

</html>


<?php
$connect=mysql_connect('localhost','root','');
$mysql_db=mysql_select_db('my_database',$con) or die(mysql_error());

if(isset($_POST['submit'])){

    $name=$_POST['username'];    **row name:username**
    $password=$_POST['password'];  **row name:password**
    $email=$_POST['email'];               **rowname:email**

    if($name=='')
    {
        echo "<script>alart('Please Enter your name')</script>";
    }

    if($password=='')
    {
        echo "<script>alart('Please Enter your password')</script>";
    }

    if($email=='')
    {
        echo "<script>alart('Please Enter your Email')</script>";
    }
    else 
{

$query="insert into 'user_reg'(username,password,email) values('$name','$password','$email')";
if(mysql_query($query)){

echo "<script>window.php('jhom.php','_self')</script>";

}
}
}
?>
2
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by rjony321
0

Quite a number of errors here. I've tidied them up as much as I could:

$output = "";
$username="";
$password="";
$email="";

$connect=mysql_connect('localhost','root','');
$mysql_db=mysql_select_db('daniweb',$connect) or die(mysql_error());

if(isset($_POST['submit'])){

    $name       = mysql_real_escape_string($_POST['username']);    
    $password   = mysql_real_escape_string($_POST['password']);  
    $email      = mysql_real_escape_string($_POST['email']);              

    if($name=='')$error[] = 'Please Enter your name';
    if($password=='')$error[] = 'Please Enter your password';
    if($email=='')$error[] = 'Please Enter your Email';

    if(isset($error)){
        $output = implode("<br />",$error);  
    }else{
        $result = mysql_query("INSERT INTO 'user_reg'(username,password,email) VALUES ('$name','$password','$email')");
        if(mysql_affected_rows()){
            $output = "Your details have been added to the database.";  
        }else{
            $output = "We could not process your data this time. Please try again, but if the problem persists, contact us.";
        }
    }

}
?>

<!DOCTYPE HTML>
<html>
<head>
    <!-- need title and description tags here -->
</head>
<body>
<form method="post">
<label for = "username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo $username;?>" />
<label for = "password">Password:</label>
<input type="password" name="password" id="password" value="<?php echo $password;?>" />
<label for = "email">Email:</label>
<input type="email" name="email" id="email" value="<?php echo $email;?>" />
<input type="submit" name="submit" value="Sign Up"/>
</form>
<div>
    <?php if(!empty($output)) echo "<p>$output</p>";?>
</div>
</body>
</html>

Notice a few things:

1) Place as much PHP above the doctype! as possible. Try not to mix HTML and PHP.
2) Get rid of the javascript - it's not appropriate here (IMO)
3) Place proper tags in the head area - not plain text
4) Sending a form to itself is not considered good practice - I've kept it here for the time being.
5) <center> is deprecated - don't use it
6) Don't use <br /> for layout - use CSS rules
7) Use labels for your form fields related by the id attribute of the field in the 'for' attribute of the label
8) Email may be given the type of 'email', but you can still use text
9) Your connection is called $connect NOT $con

Hope that helps.

Edited by diafol

0

Hello,
Diafol,

Many thank for reply me.yes its working but date are still not store in database.
please kindly me reply me.

Its really help full..... :)

0

Sorry sir,

Its not date it will be data.I made mistake.If i manually insert data using sql then its store.but its not directly store in database using form fillup.
so now should i do?

please help me....

0

if possible then plese explain me this line code

$output = implode("<br />",$error);

implode ?

0

implode creates a string from array items joined by the first parameter - in this case the <br /> tag. People usually use commas/spaces.

As for your data. I have no idea. At the top of your page:

$output = "";
$username="";
$password="";
$email="";
print_r($_POST); 

It will print something like Array() when you first load the page, but that's oK. As soon as you submit the form, you should see the key-value pairs of the array items. See if they give the output you're expecting.

0

Hi,

please first you visit this site http://www.webdo.x10.mx/ this is my practice site.I just starting my php carrer.here i create a search option with button but its not working as my expectation.i think its code is OK".here the code..
here i use 2 <form> tag i think here some mistake.so please check <input> tag

<?php 
    $connect=mysql_connect('localhost','root','');
    $mysql_db=mysql_select_db('my_database',$connect) or die(mysql_error());     //db name:my_database

if (isset($_POST['search_name']))
{
 $search_name= $_POST['search_name'];
 if(!empty($search_name)){

    if(strlen($search_name)>=4){


  $query = "SELECT name FROM name_search WHERE name LIKE '%".mysql_real_escape_string($search_name)."%'"; 
  $query_run= mysql_query($query);             //table name:name_search colm name:name///

  $query_num_rows=mysql_num_rows($query_run);

 if($query_num_rows>=1)
 {
    echo $query_num_rows.' Result Found:<br/>';
 while ($query_row=mysql_fetch_assoc($query_run)){
    echo $query_row['name'].'<br/>';
 }
 }
 else
 {
    echo 'Not found';
   }
     }
     else {
        echo 'Please Character must be more then 5 keywords';
     }
     }
 }
?>


////--------FORM creation area----------------//////////



<div class="search"><p>I am looking for...</p>
<div class="search_input">
<form>
<input type="text" name="search_name" class="search_input" title="Trainer Name" value="<?php echo $_SESSION['search_name'];?>"> 
</form>
</div>
</div>
<div class="search_button">
<form action= "" method="POST">
<input type="submit" name="search_name" class="search_button" title="Search" value="Find">
</form>
</div>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.