Jump to content

It wont enter any data to my database


dean012

Recommended Posts


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR...l1-strict.dtd">
<!--


-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Yakity Yak</title>
<link href='http://fonts.googlea...=Oswald:400,300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googlea...css?family=Abel|Satisfy' rel='stylesheet' type='text/css'>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">

<p><!-- end #header --></p>
<div id="header" class="container">
<div id="logo">
<h1><a href="#">Yakity Yak</a></h1>
</div>
<div id="menu">
<ul>
<li class="current_page_item"><a href="homepage.php">Homepage</a></li>
<li><a href="trip.php">Destinations</a></li>
<li><a href="contact.php">contact </a></li>
<li><a href="login.php">Login</a></li>
<li><a href="#">Leader</a></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<blockquote>
<blockquote>
<p> <center><img src="sd.jpg" width="999" height="300" alt=""/></center> </p>
</blockquote>
</blockquote>
<div id="page">
<div class="post">
<h2 class="title"><a href="#">Welcome to Yakity yak club</a></h2>
<form method='post' action='login.php'>
<table width='400' border='5' align='CENTER'>

<tr>
<td><h1>Registration</h1></td>

</tr>

<tr>
<td>User Name:</td>
<td><input type='text' name='name'/></td>
</tr>

<tr>
<td>Password:</td>
<td><input type='password' name='pass'/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type='text' name='email'/></td>
</tr>
<tr>
<td><input type='submit' name='register' value='register'/></td>

</tr>

</table>
</form>

</body>
</html>

<div class="entry">
<br><center><b>Already Registered?</br></b></center>
<center><a href='login.php'> login here</a></center>
</div>
</div>
</div>

</body>
</html>


<?php
$connect=mysql_connect("localhost","root","");
$db_selected = mysql_select_db("users_db", $connect);
if(isset($_POST['submit'])){

$users_name = $_POST['name'];
$users_pass = $_POST['pass'];
$users_email = $_POST['email'];

if($users_name==''){
echo "<script>alert('Please enter your Username')</script>";
exit();
}

if($users_pass==''){
echo "<script>alert('Please enter your password')</script>";
exit();
}

if($users_email==''){
echo "<script>alert('Please enter your email')</script>";
exit();
}

$check_email="select*from
users where
users_email='$users_email'";

$run =
mysql_query($check_email) or
die(mysql_error());



if(mysql_num_rows($run)>0){

echo"<script>alert('Email $users_email
is already exist in our databse, please try another
one')</script>"; exit();
}




$query = "insert into users
(users_name,users_pass,users_email) values('
$users_name','$users_pass','$users_email')";




if(mysql_query($query))
$result = mysql_query($query) or die(mysql_error());
if ($result)
{
echo "<script>alert('Registration Successfull!')</script>";
}







}

?>




 

Link to comment
Share on other sites

Did you try using mysql_error() after the insert query to see what you get?

 

Edit: try changing this:

if(mysql_query($query)) 
    $result = mysql_query($query) or die(mysql_error());
    if ($result)
{
    echo "<script>alert('Registration Successfull!')</script>";
}
 
To this:
if($result = mysql_query($query)) 
{
    echo "<script>alert('Registration Successfull!')</script>";
}
echo mysql_error();

 

Edited by cyberRobot
Link to comment
Share on other sites

debugging?whats that?

... You're kidding, right?

 

If not, debugging is a term that means taking the steps necessary to remove the bugs (stuff that doesn't work like it should) from your code. mac_guyver was asking what steps have you taken to try to fix your problem?

Link to comment
Share on other sites

debugging?whats that?

 

Perhaps the following definition will help:

https://www.google.com/search?q=define+debug

 

First off, you should try echoing $_POST to see what it contains. Since it's an array, you could try the following:

echo '<pre> ' . print_r($_POST, true) . '</pre>';

As mac_gyver suggested, your form doesn't have an input field named "submit". Instead of

if(isset($_POST['submit'])){
Try 
if(isset($_POST['register'])){
Link to comment
Share on other sites

still not working ;(

<?php
$connect=mysql_connect("localhost","root","");
$db_selected = mysql_select_db("users_db", $connect); 
if(isset($_POST['register'])){
echo '<pre> ' . print_r($_POST, true) . '</pre>'
 
$users_name = $_POST['name'];
$users_pass = $_POST['pass'];
$users_email = $_POST['email'];
Link to comment
Share on other sites

the action of the form is going to login.php,  your registration form + registration processing is happening some other place.

<form method='post' action='login.php'>

would probably work if you just omitted the action...  which will typically submit the form back to the same URI

<form method='post' action=''>

or....  

<form method='post' action='registration.php'>
Link to comment
Share on other sites

Is the code here in a page called login.php? The POST data should go back to the same document the way it's written.

 

P.S. mysql_fillintheblankcommand is deprecated. You should use mysqli_ or PDO commands instead.

 

P.P.S. The way your login page is written, you're very vulnerable to SQL injection. You should use prepared statements instead of just querying on random data users submit.

Link to comment
Share on other sites

The P.S. and P.P.S. won't solve your lack of POST data. They are just to make your code better (by the way, you don't use mysqli and PDO--you use one or the other). The second is really important, because it is a security issue.

 

My main point was that the POST data existing assumes that the file you're posting code from is called login.php and is resubmitting to login.php. Can you verify that's the case?

Edited by aysiu
Link to comment
Share on other sites

What you need to do, is check whether or not the form was submitted first.

Your issue may be that you're outputting a full fledged document before anything else, and all other output after is not being presented on screen.

 

That's why checking the source code is always helpful when debugging.  The source code never hides anything.

<?php

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

                    // if submitted, validate data and connect to database

     }else{
  
                   // if not, show the registration form
     }
Edited by objnoob
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.