[HELP] Error in script

Posted on Sunday 9th November 2008 at 05:57 PM
setsukemizuhara
setsukemizuhara's Avatar
PHP Code
  1. <?
  2.  
  3. // Include data base connection
  4. include("dbconnect.php");
  5.  
  6. // Check for form submission
  7. if(isset($_REQUEST['submit'])) {
  8. // Check for empty fields
  9. if(empty($_REQUEST['username'])||empty($_REQUEST['password'])||empty($_REQUEST['cpassword'])||empty($_REQUEST['email'])) {
  10. // Cancel the register process and display error
  11. echo "Some fields are not filled out.";
  12. }
  13. else {
  14. // If fields are not empty
  15. // Set varibles for submitted data
  16. $username = $_REQUEST['username'];
  17. $password = $_REQUEST['password'];
  18. $cpassword = $_REQUEST['cpassword'];
  19. $email = $_REQUEST['email'];
  20. $ip = $_SERVER['REMOTE_ADDR'];
  21. }
  22.  
  23. // Check if username already exists
  24. $sql1 = "SELECT * FROM `user` WHERE `username`='$username'";
  25. $result1 = mysql_num_rows($result);
  26. if($result1 == 1) {
  27. //If username exists
  28. echo "Username already exists.";
  29. }
  30.  
  31. // Check if submitted passwords are the same
  32. if($password != $cpassword) {
  33. //Passwords do not match, display error
  34. echo "Passwords do not match.";
  35. }
  36.  
  37. // If username does not exist and passwords match
  38. // Encrypt password for database storage
  39. $spw = md5($password);
  40.  
  41. // Insert data into database
  42. $sql2 = "INSERT INTO `users` (`username`,`password`,`email`,`ip`) VALUES ('$username','$spw','$email','$ip')";
  43. $query1 = mysql_query($sql2);
  44.  
  45. // Redirect if query runs correctly
  46. header("location: https://requiemofdestiny.awardspace.com/confirmed.php"); // Change to whatever you want the redirected apge to be
  47.  
  48. ?>


Parse error: parse error, unexpected $ in /home/www/requiemofdestiny.awardspace.com/register.php on line 48

It's annoying...
Posted on Sunday 9th November 2008 at 06:03 PM
Dava
Dava's Avatar
Code
<?

// Include data base connection
include("dbconnect.php");

// Check for form submission
if(isset($_REQUEST['submit'])) {
// Check for empty fields
if(empty($_REQUEST['username'])||empty($_REQUEST['password'])||empty($_REQUEST['cpassword'])||empty($_REQUEST['email'])) {
// Cancel the register process and display error
echo "Some fields are not filled out.";
}
else {
// If fields are not empty
// Set varibles for submitted data
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$cpassword = $_REQUEST['cpassword'];
$email = $_REQUEST['email'];
$ip = $_SERVER['REMOTE_ADDR'];
}

// Check if username already exists
$sql1 = "SELECT * FROM `user` WHERE `username`='$username'";
$result1 = mysql_num_rows($result);
if($result1 == 1) {
//If username exists
echo "Username already exists.";
}

// Check if submitted passwords are the same
if($password != $cpassword) {
//Passwords do not match, display error
echo "Passwords do not match.";
}

// If username does not exist and passwords match
// Encrypt password for database storage
$spw = md5($password);

// Insert data into database
$sql2 = "INSERT INTO `users` (`username`,`password`,`email`,`ip`) VALUES ('$username','$spw','$email','$ip')";
$query1 = mysql_query($sql2);

// Redirect if query runs correctly
header("location: https://requiemofdestiny.awardspace.com/confirmed.php"); // Change to whatever you want the redirected apge to be
}
?>


der ya go problem solved
Dava
Posted on Sunday 9th November 2008 at 06:10 PM
setsukemizuhara
setsukemizuhara's Avatar
Ok, error is gone but it is not entering the data into my site DB and it just gives a blank screen not redirecting...
Posted on Sunday 9th November 2008 at 06:12 PM
ShadowMage
ShadowMage's Avatar
Change
Code
$query1 = mysql_query($sql2);

To
Code
$query1 = mysql_query($sql2) or die(mysql_error());
failure i sense
Posted on Sunday 9th November 2008 at 10:24 PM
setsukemizuhara
setsukemizuhara's Avatar
PHP Code
  1. <?php
  2.  
  3. // Start Sessions
  4. session_start();
  5.  
  6. // Include dbconnect.php
  7. include("dbconnect.php");
  8.  
  9. // Check if form was submitted
  10. if(!$_POST['create']) {// Form wasn't submitted
  11. // Echo the Form
  12. echo "
  13. <form method="post">
  14. <table width="300px" border="0" align="center" cellpadding="1" cellspacing="1">
  15. <tr>
  16. <td colspan="4"><div align="center">Register</div></td>
  17. </tr>
  18. <tr>
  19. <td colspan="2"><div align="right">Username:</div></td>
  20. <td colspan="2"><input type="text" name="username" id="username"></td>
  21. </tr>
  22. <tr>
  23. <td colspan="2"><div align="right">Password:</div></td>
  24. <td colspan="2"><input type="text" name="password" id="password"></td>
  25. </tr>
  26. <tr>
  27. <td colspan="2"><div align="right">Confirm Password:</div></td>
  28. <td colspan="2"><input type="text" name="cpassword" id="cpassword"></td>
  29. </tr>
  30. <tr>
  31. <td colspan="2"><div align="right">E-mail:</div></td>
  32. <td colspan="2"><input type="text" name="email" id="email"></td>
  33. </tr>
  34.  
  35. <tr>
  36. <td width="100"><input name="ip" type="hidden" id="ip" value="<?php echo $_SERVER[REMOTE_ADDR]; ?>"></td>
  37. <td colspan="2"><div align="center">
  38. <input type="submit" name="create" id="create" value="Create">
  39. </div></td>
  40. <td width="100">&nbsp;</td>
  41. </tr>
  42. </table>
  43. </form>
  44. ";
  45. }
  46. else { // Form Was Submitted
  47. // Check if form is empty
  48. if(empty($_POST['username'])||empty($_POST['password'])||empty($_POST['cpassword'])||empty($_POST['email'])) {
  49. echo "Please fill in all form data.";
  50. }
  51. else {
  52. // Collect Form Data
  53. $username = $_POST['username'];
  54. $password = $_POST['password'];
  55. $cpassword = $_POST['cpassword'];
  56. $email = $_POST['email'];
  57. $ip = $_POST['ip'];
  58.  
  59. // Check if submitted data is already in Database
  60. $checkuiuser = mysql_query("SELECT * FROM `users` WHERE `username='$username'") or die(mysql_error());
  61. $checkuiuserc = mysql_num_rows($checkuiuser);
  62. $checkuiemail = mysql_query("SELECT * FROM `users` WHERE `email`='$email'") or die(mysql_error());
  63. $checkuiemailc = mysql_num_rows($checkuiemail);
  64. }
  65.  
  66. // Run if statement for checking
  67. if($checkuiuserc > 0 || $checkuiemail > 0) {
  68. // Username or Email exists in DB
  69. echo " Username or Email already in use.";
  70. }
  71. if ($cpassword != $password) {
  72. // Check if pass word match
  73. echo "Password do not match";
  74. }
  75.  
  76. $uiencryptpass = md5($password);
  77.  
  78. $uiinsert = mysql_query("INSERT INTO `users` (`username`,`password`,`email`,`ip`,`userlvl`) VALUES ('$username','$uiencryptpass','$email','$ip','1'");
  79. echo "You have been Registered.";
  80.  
  81. ?>


An edited version of the register I posted.

Error:
Parse error: parse error, unexpected $ in /home/www/requiemofdestiny.awardspace.com/register.php on line 81

But line 81 is the ?> and 80 is blank.
Posted on Sunday 9th November 2008 at 11:19 PM
Dava
Dava's Avatar
Code
<?php

// Start Sessions
session_start();

// Include dbconnect.php
include("dbconnect.php");

// Check if form was submitted
if(!$_POST['create']) {// Form wasn't submitted
// Echo the Form
echo "
<form method="post">
<table width="300px" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td colspan="4"><div align="center">Register</div></td>
</tr>
<tr>
<td colspan="2"><div align="right">Username:</div></td>
<td colspan="2"><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td colspan="2"><div align="right">Password:</div></td>
<td colspan="2"><input type="text" name="password" id="password"></td>
</tr>
<tr>
<td colspan="2"><div align="right">Confirm Password:</div></td>
<td colspan="2"><input type="text" name="cpassword" id="cpassword"></td>
</tr>
<tr>
<td colspan="2"><div align="right">E-mail:</div></td>
<td colspan="2"><input type="text" name="email" id="email"></td>
</tr>

<tr>
<td width="100"><input name="ip" type="hidden" id="ip" value="<?php echo $_SERVER[REMOTE_ADDR]; ?>"></td>
<td colspan="2"><div align="center">
<input type="submit" name="create" id="create" value="Create">
</div></td>
<td width="100">&nbsp;</td>
</tr>
</table>
</form>
";
}
else { // Form Was Submitted
// Check if form is empty
if(empty($_POST['username'])||empty($_POST['password'])||empty($_POST['cpassword'])||empty($_POST['email'])) {
echo "Please fill in all form data.";
}
else {
// Collect Form Data
$username = $_POST['username'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$email = $_POST['email'];
$ip = $_POST['ip'];

// Check if submitted data is already in Database
$checkuiuser = mysql_query("SELECT * FROM `users` WHERE `username='$username'") or die(mysql_error());
$checkuiuserc = mysql_num_rows($checkuiuser);
$checkuiemail = mysql_query("SELECT * FROM `users` WHERE `email`='$email'") or die(mysql_error());
$checkuiemailc = mysql_num_rows($checkuiemail);
}

// Run if statement for checking
if($checkuiuserc > 0 || $checkuiemail > 0) {
// Username or Email exists in DB
echo " Username or Email already in use.";
}
if ($cpassword != $password) {
// Check if pass word match
echo "Password do not match";
}

$uiencryptpass = md5($password);

$uiinsert = mysql_query("INSERT INTO `users` (`username`,`password`,`email`,`ip`,`userlvl`) VALUES ('$username','$uiencryptpass','$email','$ip','1'");
echo "You have been Registered.";
}
?>


just remember you do need to end functions
Dava
Login or register to respond to this forum topic.