Jump to content

Recommended Posts

Hi guys,

 

      just wondered if anyone can help me understand where to insert my include function to pull in my "design".

 

//This code runs if the form has been submitted
if (isset($_POST['submit'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") 
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}


// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. 
');
}

 

I want the following responses to be in my overall site design instead of simple text and white background:

-'You did not complete all of the required fields'

-'Sorry, the username '.$_POST['username'].' is already in use.'

-'Your passwords did not match.'

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/68332-adding-design-to-php/
Share on other sites

Hello,

I usually sort out any header information, declare any variables, include the start of my design, do something here!, include the end of my design:

 

e.g.

 

- session bits

- get/post variables

- validate any recieved data

- include the start of my layout

- display results or error messages / warnings

- include end of my layout

 

There are loads of different ways to do it. Does anyone have a better method? Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/68332-adding-design-to-php/#findComment-343588
Share on other sites

youre spot on with what I want to acheive, but the $error_message produces another issue, as the script submits the data to the database even if you leave all registration feilds blank. I know I can use validation, but the Die function stops accessing the db immediatley. I dont really want to play with the script, as it works fine, I just cant get my design in place.

 

It would be great if I could do something like below, as my design is being included once a user signs up. it produces the message "Thank you, you have registered - you may now login" exactly where i want it, in the "content" part of the page, in my template/design.

 

// now we insert it into the database
$insert = "INSERT INTO users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
$add_member = mysql_query($insert);
include('../fmn/header.htm')

?>


<p class="login_nav">Registered</p>
<p class="login_nav">Thank you, you have registered - you may now login</a>.</p>
<?php 

 

 

Link to comment
https://forums.phpfreaks.com/topic/68332-adding-design-to-php/#findComment-343661
Share on other sites

I think I get what you mean, here's an example to show you how you could do something like this...

 

<?php

// Do all your checking here...like for example

if (empty($_POST['username']))
{
    die();
    $error_message = "You didn't enter a Username.";
}
else
{
    $username = mysql_real_escape_string($_POST['username']);
}

if(strlen($_POST['password']) < 5 )
{
    die();
    $error_message = "Password not long enough...";
}
else
{
    $password = mysql_real_escape_string($_POST['password']);
}

// etc...

if ($username && $password)
{
    $insert...
}
else
{
    echo('Errors: '.$error_message.'');
// Show form again...
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/68332-adding-design-to-php/#findComment-343666
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.