Jump to content

Random PHP Error


OliverWKim

Recommended Posts

I'm a bit of a PHP n00b so I decided to try my hand at a user registration script, the following:

<?php
session_start();
include "includes/pass.inc";
$user = $_POST['username'];
$passwd = $_POST['password'];
$rpasswd = $_POST['rpassword'];
$email = $_POST['email'];
$table_name = "users";

if (strcasecmp($passwd, $rpasswd) !== 0) {
include "includes/header.inc";
echo "Passwords do not match! Please try again!";
include "pages/register.inc";
include "includes/footer.inc";
}
else{
if($user = ""){
include "includes/header.inc";
echo "The user field has been left blank! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
elseif($passwd = ""){
include "includes/header.inc";
echo "The password field has been left blank! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
elseif($email = ""){
include "includes/header.inc";
echo "The email field has been left blank! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
elseif(strlen($user) > 30){
include "includes/header.inc";
echo "Your username is too long! Please <a href='index.php?page=register'>shorten it</a>.";
include "includes/footer.inc";
}
else{
$cxn = mysql_connect($host,$username,$pass);
$db_selected = mysql_select_db("users",$cxn);
$sql = "SELECT 'user_name' FROM $table_name WHERE 'user_name'='$user'";
$result = mysql_query($sql,$cxn);
$number = mysql_num_rows($result);

if($number > 0){
include "includes/header.inc";
echo "Username already exists! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
else{
$md5pass = md5($passwd);
$q = "INSERT INTO users VALUES ('$username','$md5pass','$email')";
return mysql_query($q,$cxn);
include "includes/header.inc";
echo "Welcome to <strong>Work in Progress</strong>, " . $username . "!<br>";
include "includes/footer.inc";
}
}
}

?>

However, whenever I run the script, PHP outputs just two hyphens, like so: --. No errors, no specifications, nada. Did I do something horribly wrong, or is this PHP's fault? (I'm running PHP 4.3 and Mysql 4.0 on EasyPHP)

Link to comment
https://forums.phpfreaks.com/topic/54692-random-php-error/
Share on other sites

You are incorrectly using the return statement. Use...

 

else {
  $md5pass = md5($passwd);
  $q = "INSERT INTO users VALUES ('$username','$md5pass','$email')";
  if (mysql_query($q,$cxn)) {
    include "includes/header.inc";
    echo "Welcome to <strong>Work in Progress</strong>, " . $username . "!<br>";
    include "includes/footer.inc";
  }
}

Link to comment
https://forums.phpfreaks.com/topic/54692-random-php-error/#findComment-270472
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.