Jump to content

PHP IF statement help


talor123

Recommended Posts

hey, im new to this site and php..

everytime i enter this code

		$new_user = $_POST["user"];
	$new_password = $_POST["password"];
	$new_password_confirm = $_POST["password_confirm"];
	$new_first_name = $_POST["first_name"];
	$new_sex = $_POST["sex"];
	$new_email = $_POST["email"];


if (empty ($_POST['$new_user'])){ 
header("Location: login.php?message=Enter+a+Username.");
exit;
}

(thats the part with errors)

it tells me i have the "if" statement wrong.. ive also tryed

if($new_user == 0)header("Location: login.php?message=Enter+a+Username.");

exit;

}

 

..ive tryed lots n they all come up with errors, please tell me how to fix it..

and btw this script just meants to make it so when your signing up on the form you cant leave spaces blank..

 

thank you :)

Link to comment
https://forums.phpfreaks.com/topic/98766-php-if-statement-help/
Share on other sites

<?php
// ...

if($new_user == 0)header("Location: login.php?message=Enter+a+Username.");
   exit;
   }

// ...
?>

You haven't included the opening bracket for this IF statement.

It should be:

 

<?php
// ...

if($new_user == 0) { header("Location: login.php?message=Enter+a+Username.");
   exit;
   }

// ...
?>

Link to comment
https://forums.phpfreaks.com/topic/98766-php-if-statement-help/#findComment-505419
Share on other sites

 

just copy and paste and save as login.php

 

 

 

<?php

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

{

$new_user = $_POST["user"];

//$new_password = $_POST["password"];

//$new_password_confirm = $_POST["password_confirm"];

//$new_first_name = $_POST["first_name"];

//$new_sex = $_POST["sex"];

//$new_email = $_POST["email"];

 

if (empty ($new_user)){

header("Location: one.php?message=Enter+a+Username.");

exit;

}

}

 

if(isset($_GET['message'])) {

echo "$_GET[message]";

}

 

echo "

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

<input type='text' name='user' />

<input type='submit' name='submit' value='Submit' />

</form>

";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/98766-php-if-statement-help/#findComment-505440
Share on other sites

..that would cut lots of stuff out(my full code for the login has lots more to it)..  is there a way i can use a javascript function in a php script?? EG:

<?
javascript:check_all('');

// php stuff goes here
>?

 

or a code to put at then end of a javscript function that runs a php script??..

 

because i just made a javascript up that checks if the fields are empty, thats why it would be good if i could run the javascript function then if everythings filled out it would run the php script.. or something along those lines..

 

thanx

Link to comment
https://forums.phpfreaks.com/topic/98766-php-if-statement-help/#findComment-505443
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.