Staredit Network > Forums > Technology & Computers > Topic: PHP Ongoing Assistance
PHP Ongoing Assistance
Mar 9 2008, 4:20 pm
By: InsolubleFluff
Pages: < 1 « 3 4 5 6 >
 

Mar 20 2008, 3:49 pm Forsaken Archer Post #81



had to testie
register.php
<?php
require("connect.php");

$username = $_POST['user'];
$password = sha1($_POST['pass']);
$password2 = $_POST['pass2'];
$email = $_POST['email'];

function error()
{
  if(!$query)
  {
     echo "Query Failed: " . mysql_errno() . '<br />' . mysql_error();
   }
}

function check()
{
  $check1 = mysql_query("SELECT * FROM users WHERE username = {$username}");
  if(mysql_num_rows($check1)==1)
            return TRUE;
  return FALSE;
}

if(!$con)
{
 echo "<br /><br />Registering is disabled right now, please check back later.";
}
else
{
 if(!$_POST['register'])
    {
      echo "<br /><br />Use the following form to register a new account with us.
      <form action='register.php' method='post'><br /><br />
      <font size='1'>Username:</font><br />
      <input type='text' id='user' name='user' size='17' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br />
      <font size='1'>Password:</font><br />
      <input type='text' id='pass' name='pass' size='17' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br />
      <font size='1'>Confirm Password:</font><br />
      <input type='text' id='pass2' name='pass2' size='17' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br />
      <font size='1'>E-mail Address:</font><br />
      <input type='text' id='email' name='email' size='17' style='background-color: #FFFFFF; font-size: 8pt; border: 1 solid #003399' /><br /><br />
      <input type='submit' name='register' id='register' value='Register' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' />
      <input type='reset' value='Clear' style='background-color: #FFFFFF; color: #000000; font-size: 8pt; border: 1 solid #003399' />
      </form>";
    }
 else
    {
        if(!$username)
          $errors[] = "The username you entered encountered a problem.";
        else if (!check())
            $errors[] = "The username " . $username . 'already exists';

       if(!$password || !$password2)
          $errors[] = "The password field cannot be left empty!";
         
       if(!$email)
          $errors[] =  "The email you entered encountered a problem.";
         
       if($password != $password2)
          $errors[] =  "The passwords you entered do not match.";
         
        if (count($errors))
        {
                $error_string = implode("<br />", $errors);
                echo 'You encountered the following errors: <br />'. $error_string . '<br /><br /><a href="javascript:history.go(-1);">Go Back</a>';
        }
        else
        {
           mysql_select_db("divnx5_web");
           $query = mysql_query("INSERT INTO users(username, password, email) VALUES('{$username}', '{$password}', '{$email}')");
           error();
           mysql_close($con);
           echo 'Success!  Your account ' . $username . ' was created.';
        }
     }
}

?>


Attachments:
register.php
Hits: 5 Size: 2.94kb

Post has been edited 3 time(s), last time on Mar 21 2008, 11:35 pm by isolatedpurity.



None.

Mar 21 2008, 2:54 am NexY Post #82



Thank You, will check it out now.



None.

Mar 21 2008, 3:28 am AfterLifeLochie Post #83



A good program to use is Scintilla Text Editor. It's free, and supports language recognition, including PHP, JavaScript, HTML and loads more.
I use this myself and I found it to be really useful.



None.

Mar 25 2008, 3:42 am (U)Bolt_Head Post #84



Question: My forms are not working in Internet Explorer... I'm using type image and the button is unclickable in both IE6 and 7 I've tried different computers as well.

Here is my abbreviated code
Code
<form name=form1 action=checklogin.php method=post>
<table frame=box border=1 cellpadding=5><tr><td><table>
    <tr>
    <td colspan=2 align=center><b>Login<b></td>
    </tr><tr>
        <td align=right valign=top>User Name: </td>
        <td><input type=text name=myusername id=myusername></form></td>
    </tr><tr>
        <td align=right>Password: </td>
        <td><input type=password name=mypassword id=mypassword></form></td>
    </tr><tr>
        <td colspan=2 align=center>
        <a href=?view=1><img src=WebPics/Register.gif border=0 title=Register></a>
        <input type=image name=Submit src=WebPics/Login.gif title=Login></td>
    </tr>
</table>
</form>




None.

Mar 25 2008, 5:51 am Forsaken Archer Post #85



I haven't used type=image at all... But you should enclose all values for attributes in quotations.
<input type="image" name="Submit" src="WebPics/Login.gif" title="Login" />
I dunno if title is valid either..



None.

Mar 25 2008, 6:33 am AfterLifeLochie Post #86



Look, image buttons are much harder to do, but, if you send me the image, I'll work it out.



None.

Mar 25 2008, 6:53 am (U)Bolt_Head Post #87



title has pretty much the same effect as alt. I added that in afterwards when trying to fix it and it had no effect. Firefox will not display the mouse over text if only alt is used.

Also send you the image? what good would that do?

Also I tend to leave the quotes out when it is printed with php echo like this example is. I tried putting in single quotes and no difference is noticed.



None.

Mar 25 2008, 6:58 am Forsaken Archer Post #88



Is your code online to view? I'd like to see this form.



None.

Mar 25 2008, 7:38 am (U)Bolt_Head Post #89



Figured it out, for some reason at the end of the input tags for both 'myusername' and 'mypassword' I had a </form> close tag.
Interesting that it worked at all in firefox with such an error.



None.

Mar 26 2008, 3:38 am AfterLifeLochie Post #90



Quote from AfterLifeLochie
Look, image buttons are much harder to do, but, if you send me the image, I'll work it out.
Refined:

What's the URL of the images, in exact location?



None.

Mar 26 2008, 4:32 am NexY Post #91



I'm back! After IP helped me out so graciously, I think he gave on me :lol: . But I get this error:
Quote
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1

The code that I think is causing that is:
Quote
function check()
{
$result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'");
$error = mysql_query($result) OR die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "The username " . $username . 'is already taken!';
}
}

O.O Thanks again D:



None.

Mar 26 2008, 6:18 am AfterLifeLochie Post #92



Doesn't like resource #4 in the array...
1. Opened connection to MySQL?
2. Change
$error = mysql_query($result) OR die(mysql_error());
to
$q_result = mysql_query($result)
if (!$q_result)
{
die ......... ;
}
<code keeps going....>



None.

Mar 26 2008, 8:15 am Forsaken Archer Post #93



Code
$result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'");
$error = mysql_query($result) OR die(mysql_error());

The second like parses as mysql_query(mysql_query("SELECT * FROM `users` WHERE `username` = '$username'")); when all is said and done.



None.

Mar 26 2008, 3:16 pm NexY Post #94



Quote from AfterLifeLochie
Doesn't like resource #4 in the array...
1. Opened connection to MySQL?
2. Change
$error = mysql_query($result) OR die(mysql_error());
to
$q_result = mysql_query($result)
if (!$q_result)
{
die ......... ;
}
<code keeps going....>
This gave me the same error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1.

I'm 100% sure I'm connecting to my db and opened connection to Mysql.

@IP: I tried $error = $result OR die(mysql_error()); since you said the way it was read. I didn't get the error but it also never said Username is taken. I'm pretty sure the reason is because $result needs to be in the array, but I guess I could be wrong.

O.O Thanks



None.

Mar 27 2008, 1:13 am AfterLifeLochie Post #95



Afffix an @ symbol before the statement you think's creating this error.

@ symbol susresses all errors the function will 'cause'



None.

Mar 27 2008, 2:14 am NexY Post #96



I'm stumped o.o! I added @ in a lot of places and tested several times, but I still have no luck. I attached the file, if you care too look at it. Sorry IP,the code you edited isn't this one :P. D:

Thanks.

Attachments:
register.php
Hits: 2 Size: 2.86kb



None.

Mar 27 2008, 2:21 am Centreri Post #97

Relatively ancient and inactive

Well, you don't need {$var} in the query. '$varwhatever' serves fine. Also, try using empty() and !isset() (forgot how I used to do it) instead of (!$var). I think yours might work, though, so I feel stupid having used those. I'll try it out later.
That said, I just learned two new functions :P.

Here's basically how I did it before, and my register worked perfectly (though it was somewhat insecure. Well, I'm recoding everything).
Code
$registerConnect = mysql_connect("localhost", "root", "root");
 mysql_select_db('centreri', $registerConnect);

$registerBasicData = "INSERT INTO userinformation (Account, Password, Email, RegisteredTime, Rank) VALUES ('$specAccount', '$specPass', '$specEmail', now(), 'Newcomer')";
 $registerBasicDataExecute = mysql_query($registerBasicData, $registerConnect);
 if (!$registerBasicDataExecute) {
  $_SESSION['fatalRegisterError'] = "<div style=\"width: 750px; height: 50px; background-color: #FF0000\"><center><b>Fatal Error</b></center><br />Your registration was unable to be completed. Please either reregister or contact webmaster.</div>";
  header("location: ../register.php");
 } else {
  $_SESSION['registerComplete'] = true;
  header("location: ../Mainpage.php");

Hey, IP, is it... bad to use an insane amount of variables?

EDIT: Err.. do you ever actually connect to the MySQL database?

Post has been edited 3 time(s), last time on Mar 27 2008, 2:38 am by Centreri.



None.

Mar 27 2008, 4:20 am AfterLifeLochie Post #98



Quote
Hey, IP, is it... bad to use an insane amount of variables?

Errm... I'm not IP, but, it's ok to use loads of variables as long as the ones with passwords in them are DEFINED (see php manual at www.php.net).



None.

Mar 27 2008, 2:16 pm NexY Post #99



@Centreri: I tried it your way, now it's saying:

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/divnxn5/public_html/register.php

:(



None.

Mar 27 2008, 5:02 pm Forsaken Archer Post #100



Nexy, i'll look at it soon.



None.

Options
Pages: < 1 « 3 4 5 6 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[06:36 pm]
RIVE -- Nah, I'm still on Orange Box.
[04:36 pm]
Oh_Man -- anyone play Outside the Box yet? it was a fun time
[12:52 pm]
Vrael -- if you're gonna link that shit at least link some quality shit: https://www.youtube.com/watch?v=uUV3KvnvT-w
[11:17 am]
Zycorax -- :wob:
[2024-4-27. : 9:38 pm]
NudeRaider -- Ultraviolet
Ultraviolet shouted: NudeRaider sing it brother
trust me, you don't wanna hear that. I defer that to the pros.
[2024-4-27. : 7:56 pm]
Ultraviolet -- NudeRaider
NudeRaider shouted: "War nie wirklich weg" 🎵
sing it brother
[2024-4-27. : 6:24 pm]
NudeRaider -- "War nie wirklich weg" 🎵
[2024-4-27. : 3:33 pm]
O)FaRTy1billion[MM] -- o sen is back
[2024-4-27. : 1:53 am]
Ultraviolet -- :lol:
[2024-4-26. : 6:51 pm]
Vrael -- It is, and I could definitely use a company with a commitment to flexibility, quality, and customer satisfaction to provide effective solutions to dampness and humidity in my urban environment.
Please log in to shout.


Members Online: Roy