PDA

View Full Version : What is wrong with this PHP script? ASAP+REP!



myke
10-03-2008, 11:30 AM
<a href="register.php">Register Here</a>
</td></tr></table></form></center>");
}
if ("$_POST['login'];")
{
$username=$_POST["username"];
$password=md5($_POST["password"]);
Error I'm getting:

Parse error: syntax error, unexpected T_STRING in /home/more/public_html/DB/login.php on line 28

Line 28 is the if function :)

d17c
10-03-2008, 01:30 PM
I'm a bit rusty with php, but try this:

<a href="register.php">Register Here</a>
</td></tr></table></form></center>");
}
if (isset($_POST['login'])) {
$username = $_POST["username"];
$password = md5($_POST["password"]);I assume you were trying to check if it had been submitted.

myke
10-03-2008, 03:06 PM
no, didn't work :(!

+rep for tring :)!

myke
10-03-2008, 03:22 PM
sorry, can't edit, sorted.

Protege
10-03-2008, 04:13 PM
sorry, can't edit, sorted.

Basically in PHP if your using a echo or placing a string (I think your echoing) you have a problem with (ref="register.php">), think about it, you've started it off with echo(" <<-- and your ending it with "); "register.php" Your basically ending it there, and then starting it again, so to fix this;


echo("<a href=\"register.php\">");or

echo('<a href="register.php">');or

echo("<a href=register.php>");all will work, and let you use a href tag in a PHP code.

Hope that helped :)

I just re-read it and i saw a few more errors in the coding

if statements, I shall explain as you've really and the only word i found to explain this is f**ked it up big time.

if statements are very easy, and its the basic of coding on a whole, once you understand it, you can basically build anything.



$string = "Bob";
$string2 = 5;
## code 1
if($string == "Bob")
{
echo("True");
}
else
{
echo("False");
}

## code 2
if($string2 == 2)
{
echo("False");
}
else
{
echo("True");
}


Code #1 would be result on the page "True" and Code #2 would result "False" In strings/vars you can place numbers without quotes, but if its text, you need to quote it, and ALWAYS finish off VARS/STRINGS with ; or your code will fail.

What you've done wrong is basically go a bit too far with the syntax

if ("$_POST['login'];")

the correct version would be


if ($_POST['login'])
I tend not to do coding like that, so Id probably do

if($_POST['login'] == "")

^^ That should work, good luck!

rh4u
11-03-2008, 09:53 PM
<a href=register.php>Register Here</a>
</td></tr></table></form></center>");
}
if ("$_POST['login'];")
{
$username=$_POST["username"];
$password=md5($_POST["password"]);
}


try that =]

Invent
11-03-2008, 09:59 PM
@^: Oh come on!



<a href="register.php">Register Here</a>
</td></tr></table></form></center>");
}

if( $_POST["login"] /* isset() can be used */ )
{

$username = $_POST["username"];
$password = md5( $_POST["password"] );

Hypertext
11-03-2008, 10:08 PM
roflmao at this failure
USE ' over " if you want " use escape it with \
<a href='register.php'>Register Here</a>
</td></tr></table></form></center>");
}

if($_POST["login"])
{

$username = $_POST["username"];
$password = md5( $_POST["password"] );

Navicat
11-03-2008, 10:59 PM
<a href="register.php">Register Here</a>
</td>
</tr>
</table>
</form>
</center>
<?php
if ($_POST ['login']) {
$username = $_POST ["username"];
$password = md5 ( $_POST ["password"] );

// DO THE REST OF YOUR **** HERE //


}
?>

Hypertext
12-03-2008, 01:50 AM
by the looks of the ); ending in, he's already in an echo/print so you'd have to keep in php

Navicat
12-03-2008, 02:00 AM
Well he should have posted it all :P

QuickScriptz
14-03-2008, 02:44 PM
As I've been reading this thread the use of parentheses in the echo construct have been really bugging me. Just so we're all clear, it is a much better practice to NEVER use parentheses while using the echo construct - main reason being that you cannot pass more than one parameter when using parentheses.

Anyway.... here would be the correct usage in your situation...


// If or else statement should go here
echo '<a href="register.php">Register Here</a>
</td></tr></table></form></center>';
}
if ($_POST['login']) { // Option #1
$username = $_POST["username"];
$password = md5($_POST["password"]);
// Rest of stuff goes here
}
if (isset($_POST['login'])) { // Option #2
$username = $_POST["username"];
$password = md5($_POST["password"]);
// Rest of stuff goes here
}
if ($_POST['login'] != null) { // Option #3
$username = $_POST["username"];
$password = md5($_POST["password"]);
// Rest of stuff goes here
}


Hope that helps :)

lolwut
19-03-2008, 01:22 PM
*shrug*
I always used


<?php echo("<a href=\"register.php\">Register Here</a>"); ?>

Always worked for me.

Want to hide these adverts? Register an account for free!