Jump to content

Quick fix? New geek to PHP


VaporX07

Recommended Posts

Hey PHPFreak Community,

 

I'm new to PHP and I'm just trying to get a simple log in script working... I have the intention of the the script running after the submit button is pressed on my form, but when I do so, none of the information I have processed gets inserted to my DB... I know my DB settings are right... I can't even get a simple echo onto the screen after the submit button is pressed to know verify that atleast the script is executing... is this because of my first if statement condition? If anyone could please take a look at my code, and point out whats wrong, I would GREATLY appreciate it! :D

 

<?php

//Connect to DB
mysql_connect("localhost", "root", "***my secret password ***") or die (mysql_error());
//Select DB
mysql_select_db("oiam") or die (mysql_error());

//Run code only if submitted...
if (isset($_POST['submit'])){

//Check to see if script executes... does not run as of now? possibly my "if" condition?
echo "hellooo";

//Check for blank fields...
if(!$_POST['username'] | !$_POST['password'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['email']){
die('You did not fill in all the fields.');
}

//Check if username is taken already...
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 username is taken, display message...
if($check2 != 0){
die('Sorry, the username '.$_POST['username'].' is already in use.');}

//Insert registration into DB...
$insert = "INSERT INTO users (username, password, firstname, lastname, email) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['firstname']."', '".$_POST['lastname']."', '".$_POST['email']."')";
$add_member = mysql_query($insert);
}
else
{
}
?>

<html>
<title>
Register Page
</title>

<body>
<form name="input" action="" method="post">
User Name:<input type="text" name="username"></br>
Password:<input type="password" name="password" size="10"></br>
First Name: <input type="text" name="firstname"></br>
Last Name:<input type="text" name="lastname"></br>
Email:<input type="text" name="email"></br></br>
<input type="submit" value="Register">
</form> 

Link to comment
Share on other sites

Youn need to name your submit button in order for your first if() condition to execute.

 

<input type="submit" name="submit" value="Register">

 

Also... or is || not | this line....

 

if(!$_POST['username'] | !$_POST['password'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['email']){

 

will need to be....

 

if(!$_POST['username'] || !$_POST['password'] || !$_POST['firstname'] || !$_POST['lastname'] || !$_POST['email']){

Link to comment
Share on other sites

Im a bit short of time since I need to catch the bus but something I see your doing and I think you should avoid at all cost is this line:

 

<?php $_POST['username'] = addslashes($_POST['username']);}

$usercheck = $_POST['username'];

?>

 

 

your comfusing itself because your changing the value of a global variable.

 

change he $_POST['username'] = addslashes($_POST['username']);

 

 

to a normal var. like $username_as = addslashes($_POST['username']); 

 

 

Link to comment
Share on other sites

ahh shoot! that was such a newb thing to forget the name of the submit button in my control... thanks for the relies everyone! it worked perfectly after naming my submit button... i also edited my || sytanx as needed, thanks again for the help! i really appreciate it

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.