🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: rocksolid.shared.helpdesk
7 messages
7 total messages Started by Anonymous@novabb Mon, 21 Dec 2020 00:57
Notice: Undefined Variable (continued)
#147
Author: Anonymous@novabb
Date: Mon, 21 Dec 2020 00:57
205 lines
10015 bytes
Hello. This is a continuation of all the errors that I'm getting in code of mine. I was finally able to solve the _SESSION problem, but there was also another error that came below _SESSION, which was "Notice: Undefined Variable: q". After fixing the _SESSION error, I still noticed that this error was still in my code when I tried to get an account.

Another thing that I should mention is that I tried removing the $_SESSION['captcha_code'] and <img src="cap.php"><br/><label for="code">captcha:</label><input type="text" name="code" /> in index.php to find out more about my problem. When I did this, the "Notice: Undefined Variable: q" error was gone when I tried to register an account. Therefore, I believe that the error lies within the captcha that I made. However, even with this error gone, I still, for some reason, get {text2}. Even though I get {text2} with a username and password, I don't get any error logs about this whatsoever. Here's some of my code:

index.php:

<!doctype html>
<html>
<head>
<style>
*{margin:{number}px; padding:{number}px;}
#account{border-radius: {number}px {number}px {number}px {number}px; border: {number}px solid {color}; width:
{number}px; margin-top: {number}px; margin-left: {number}px; }
#login{border-radius: {number}px {number}px {number}px {number}px; border: {number}px solid {color}; width: {number}px; margin-top: {number}px; margin-left: {number}px; margin-right: {number}px; }
</style>
</head>

<body style="background-color:{color}">
<?PHp
session_start();
               require_once("connect.php") ;
      if(isset($_POST['register'])){
    $user_name = $_POST['user_name'] ;
    $password = $_POST['password'] ;

    if($user_name != "" and $password != "" and $_POST['code'] === $_SESSION['captcha_code'])

    $q= "INSERT INTO `user` (`id`, `user_name`, `password`)
       VALUES(' ' , ' ".$user_name." ' , ' ".$password." ')
    " ;
if(mysqli_query($con, $q)){
   echo '{text1}' ;
               }else{
echo "(text2)" ;
               }

               }

?>
<h1><strong>{Some Text}<strong></h1>
<div id="registration">
<h2>{Some Text}</h2>
<form method="post">
Intended username:<br>
<input type="text" name="user_name" /><br>
Intended password:<br>
<input type="text" name="password" /><br>
<img src="cap.php"><br/><label for="code">captcha:</label><input type="text" name="code" />
<input type="submit" name="register" value="Submission" />

</form>
</div>
</body>
</html>

cap.php:

<?php
session_start();

$captcha = ' ' ;

for($x = 0 ; $x< 7 ; $x++){

     $captcha .=chr(rand(97, 122)) ;
}
$_SESSION['captcha_code'] = $captcha ;

$f ;

$image = imagecreatetruecolor(170, 60) ;

${variable1} = imagecolorallocate($image, {number}, {number}, {number}) ;
${variable2} = imagecolorallocate($image, {number}, {number}, {number}) ;
${variable3} = imagecolorallocate($image, {number}, {number}, {number}) ;

imagefilledrectangle($image, 0, 0, 200, 100, ${variable3}) ;
imagettftext($image, 30, 5, 10, 40, ${variable}, $font, $_SESSION['captcha_code']) ;

header("Content-type: image/png") ;
imagepng($image) ;

?>

connect.php:

<?php

$con = mysqli_connect("{host}", "{username}", "{password}", "{database}")

?>

Error log output before removing captcha elements:

Notice: Undefined variable: q in {directory} on line {number}

Error log output after removing captcha elements:

Nothing...

Please note that the different {number}, {color}, {text}, {directory}, {host}, {username}, {password}, {database}, and {variable} brackets are supposed to represent different elements in my code that I believe aren't too necessary to type out and are also elements that I feel somewhat insecure sharing. As said before, once again, if there's any information that I can provide to you or anything that you're confused about, then please feel free to ask. I also would've put hashtags around the main parts of my code to focus on, but I SERIOUSLY don't know what's wrong when I removed the parts of my code that was related to the captcha, so I believe that everything is up for analysis.

Please also note that php is the main code here and that the INSERT INTO value is basically used for a database in order for users to register. The mysqli_connect value connects to a database in phpmyadmin, which is where the database for user registration is located.

Here's my process of making this table:

The table for this is named user, and this table has Collation and has a total of 3 columns. The first column is named id, and it has the type as INT, has the length/values of 5, has the default value as none, has collation and attributes blank, the null checkbox unchecked, the virtuality was left blank when making this, and has the index as PRIMARY, in which A_I is also enabled.

The second column is named user_name, has the type as VARCHAR, has the length/values of 100, has the default value as none, has all of collation, attributes, and index blank, has the null and A_I checkboxes unchecked, and virtuality was also left blank when making this.

The third column is named password, and has the type as VARCHAR, has length/values as 100, has default as none, has collation, attributes, and index blank, and had the null and A_I checkboxes unchecked. Virtuality was left blank.

So, I think that I might've been a bit too specific with phpmyadmin, but I want you to really imagine me making this table. I also believe that I may be calling cap.php wrong in index.php, which might be why I'm getting undefined variable q. However, I honestly have NO idea why I get {text2} when I try to register for an account without the captcha that I made implemented in index.php. Please help me with these two errors, as I feel very confused with my code. Once again, if you have any possible idea why I might be getting these two errors, see any mistake in the code, see any mistake made in my method of making the table mentioned above, and/or know any links/websites that may help, then please feel free to share your thoughts. Advice would be MUCH appreciated.

Last post I made for anyone who needs it:
{DON'T BOTHER READING ANOTHER WHOLE ESSAY IF YOU DON'T REQUIRE IT}

Hello. I'm in a need of a bit of help. I'm trying to make a website in php. However, in order for users to access a page in this website, they'll need to have an account. This account requires a captcha. However, whenever I try to get an account, my error logs say that a variable is undefined. Here's part of my code:

index.php:

<!doctype html>
<html>
<head>
<style>
*{margin:{number}px; padding:{number}px;}
#account{border-radius: {number}px {number}px {number}px {number}px; border: {number}px solid {color}; width:
{number}px; margin-top: {number}px; margin-left: {number}px; }
#login{border-radius: {number}px {number}px {number}px {number}px; border: {number}px solid {color}; width: {number}px; margin-top: {number}px; margin-left: {number}px; margin-right: {number}px; }
</style>
</head>

<body style="background-color:{color}">
#####<?PHp
               require_once("connect.php") ;
      if(isset($_POST['register'])){
    $user_name = $_POST['user_name'] ;
$password = $_POST['password'] ;

    if($user_name != "" and $password != "" and $_POST['code'] === $_SESSION['captcha_code'])

    $q= "INSERT INTO `user` (`id`, `user_name`, `password`)
       VALUES(' ' , ' ".$user_name." ' , ' ".$password." ')
    " ; if(mysqli_query($con, $q)){
   echo '{text1}' ;
               }else{                       echo "(text2)" ;
               }

               }

?>#####
<h1><strong>{Some Text}<strong></h1>
<div id="registration">
<h2>{Some Text}</h2>
<form method="post">
Intended username:<br>
<input type="text" name="user_name" /><br>
Intended password:<br>
<input type="text" name="password" /><br>
#####<img src="cap.php"><br/><label for="code">captcha:</label><input type="text" name="code" />#####
<input type="submit" name="register" value="Submission" />

</form>
</div>
</body>
</html>

cap.php:

<?php
session_start( ) ;

#####$captcha = ' ' ;

for($x = 0 ; $x< 7 ; $x++){

     $captcha .=chr(rand(97, 122)) ;
}
$_SESSION['captcha_code'] = $captcha ;#####

$f ;

$image = imagecreatetruecolor(170, 60) ;

${variable1} = imagecolorallocate($image, {number}, {number}, {number}) ;
${variable2} = imagecolorallocate($image, {number}, {number}, {number}) ;
${variable3} = imagecolorallocate($image, {number}, {number}, {number}) ;

imagefilledrectangle($image, 0, 0, 200, 100, ${variable3}) ;
#####imagettftext($image, 30, 5, 10, 40, ${variable}, $font, $_SESSION['captcha_code']) ;#####

header("Content-type: image/png") ;
imagepng($image) ;

?>

Error Log Output:

#####Notice: Undefined variable: _SESSION in {directory}/index.php on line {number}#####

For what connect.php is and what the INSERT INTO values are as mentioned above in index.php, they're databases that are used in order for users to register, and I also believe that they're unimportant in terms of my issue. The different {number}, {color}, {text}, {directory}, and {variable} brackets are supposed to represent different elements in my code that I believe aren't necessary to type out and are also elements that I feel somewhat insecure sharing. Of course, if there's any information that I can provide you or anything that you're confused about, then please feel free to ask. Since the code may be a bit long to some, I put hashtags around sections of code that I think are especially important to read. Anyway, I believe that with the code that I wrote out, the SESSION variable shouldn't be undefined, as it was defined in cap.php (captcha). However, here I am, not knowing why I keep on getting this error and {text2}. If you have any idea why I may be getting this error, if you see a mistake in the code, and/or if you know any links and websites that might help, please reply. I would love some advice, as I don't know what's wrong at all. Thanks.


--
Posted on novaBBS
news.novabbs.com
Re: Notice: Undefined Variable (continued)
#148
Author: retro.guy@rockso
Date: Mon, 21 Dec 2020 09:14
46 lines
1890 bytes
Anonymous wrote:

> Hello. This is a continuation of all the errors that I'm getting in code of mine. I was finally able to solve the _SESSION problem, but there was also another error that came below _SESSION, which was "Notice: Undefined Variable: q". After fixing the _SESSION error, I still noticed that this error was still in my code when I tried to get an account.

It appears you are setting $q to your query under a certain condition (if statement), then sending the query whether $q was set or not:

  if(isset($_POST['register'])){
    $user_name = $_POST['user_name'] ;
    $password = $_POST['password'] ;

##### Setting $q below if statement is true:
    if($user_name != "" and $password != "" and $_POST['code'] === $_SESSION['captcha_code'])
      $q= "INSERT INTO `user` (`id`, `user_name`, `password`)
         VALUES(' ' , ' ".$user_name." ' , ' ".$password." ')
      " ;

##### Calling mysqli_query with $q whether $q was set or not:
  if(mysqli_query($con, $q)){
     echo '{text1}' ;
  }else{
     echo "(text2)" ;
  }

You're log entry you posted says:

Notice: Undefined variable: q in {directory} on line {number}
so we have no way of knowing if this is the part of the code where you're getting the error. Even so, I would probably write the above like this:

  if(isset($_POST['register'])){
    $user_name = $_POST['user_name'] ;
    $password = $_POST['password'] ;

    if($user_name != "" and $password != "" and $_POST['code'] === $_SESSION['captcha_code']) {
      $q= "INSERT INTO `user` (`id`, `user_name`, `password`) VALUES(' ' , ' ".$user_name." ' , ' ".$password." ')" ;
      if(mysqli_query($con, $q)){
        echo '{text1}' ;
      }else{
        echo "(text2)" ;
      }
    } else {
      echo "Error: user_name, password or captcha_code not set" ;
    }


--
Posted on novaBBS
www.novabbs.com
Re: Notice: Undefined Variable (continued)
#149
Author: Anonymous@novabb
Date: Mon, 21 Dec 2020 21:00
5 lines
903 bytes
Thanks for the advice! Following this code with the captcha parts, I got "Error: user_name, password or captcha_code not set". To analyze even further, I decided to remove $_POST['code'] === $_SESSION['captcha_code'] and <img src="cap.php"><br/><label for="code">captcha:</label><input type="text" name="code" />, so that the only thing required was the username and password. When I did this, I got {text2}. No errors, nothing.

Due to this, I'm almost 100% sure that my first issue revolves around the captcha that I made, although I don't know what of the captcha. For the second problem, the username and password may be filled out, but it seems to me that the if(mysqli_query($con, $q)){ statement wasn't executed for...whatever reason. This might be a problem with phpmyadmin, some other parts of the code, or literally a lot more possible causes. Any ideas?
--
Posted on novaBBS
www.novabbs.com
Re: Notice: Undefined Variable (continued)
#150
Author: retro.guy@rockso
Date: Mon, 21 Dec 2020 23:29
10 lines
736 bytes
Anonymous wrote:

> Thanks for the advice! Following this code with the captcha parts, I got "Error: user_name, password or captcha_code not set". To analyze even further, I decided to remove $_POST['code'] === $_SESSION['captcha_code'] and <img src="cap.php"><br/><label for="code">captcha:</label><input type="text" name="code" />, so that the only thing required was the username and password. When I did this, I got {text2}. No errors, nothing.

Sounds like $_SESSION['captcha_code'] is not set. I would echo the values of variables where I plan to use them for testing, this makes it easy to see what variable is not correct.

Then you need to trace back why a variable's value is incorrect.

--
Posted on novaBBS
www.novabbs.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads