Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  

Kiss me, Kate, we will be married o' Sunday. -- William Shakespeare, "The Taming of the Shrew"


rocksolid / Helpdesk / Re: Notice: Undefined Variable (continued)

SubjectAuthor
* Notice: Undefined Variable (continued)Anonymous
`* Re: Notice: Undefined Variable (continued)Retro Guy
 `* Re: Notice: Undefined Variable (continued)Anonymous
  `- Re: Notice: Undefined Variable (continued)Retro Guy

1
Subject: Notice: Undefined Variable (continued)
From: Anonymous
Newsgroups: rocksolid.shared.helpdesk
Organization: novaBBS
Date: Mon, 21 Dec 2020 00:57 UTC
Path: i2pn2.org!.POSTED!not-for-mail
From: Anonym...@novabbs.i2p (Anonymous)
Newsgroups: rocksolid.shared.helpdesk
Subject: Notice: Undefined Variable (continued)
Date: Mon, 21 Dec 2020 00:57:31 +0000
Organization: novaBBS
Message-ID: <f91d608450459e34165aeca8ed6fbb23$1@news.novabbs.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org; posting-account="retrobbs1";
logging-data="30129"; mail-complaints-to="usenet@i2pn2.org"
User-Agent: Rocksolid Light (news.novabbs.com/getrslight)
X-Rslight-Site: $2y$10$qk047Q4yXajUPSPhzkdKAOUlgTUuOA.A8dalG4u/UnSzwVIlKnpSO
View all headers
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 ;

$font = '/fonts/ttf/28dayslater.ttf' ;

$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>

Click here to read the complete article
Subject: Re: Notice: Undefined Variable (continued)
From: Retro Guy
Newsgroups: rocksolid.shared.helpdesk
Organization: novaBBS
Date: Mon, 21 Dec 2020 09:14 UTC
Path: i2pn2.org!.POSTED!not-for-mail
From: retro....@rocksolidbbs.com (Retro Guy)
Newsgroups: rocksolid.shared.helpdesk
Subject: Re: Notice: Undefined Variable (continued)
Date: Mon, 21 Dec 2020 09:14:11 +0000
Organization: novaBBS
Message-ID: <e21778232129a63fe02e04a43da11c6b$1@www.novabbs.com>
References: <f91d608450459e34165aeca8ed6fbb23$1@news.novabbs.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org; posting-account="retrobbs1";
logging-data="29418"; mail-complaints-to="usenet@i2pn2.org"
User-Agent: Rocksolid Light (news.novabbs.com/getrslight)
X-Rslight-Site: $2y$10$DVcErpF2/QsTQrGi6YAKF.I0zSWQZeS0InUih58nJ7PyDm6x5UCk2
View all headers
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


Subject: Re: Notice: Undefined Variable (continued)
From: Anonymous
Newsgroups: rocksolid.shared.helpdesk
Organization: novaBBS
Date: Mon, 21 Dec 2020 21:00 UTC
Path: i2pn2.org!.POSTED!not-for-mail
From: Anonym...@novabbs.i2p (Anonymous)
Newsgroups: rocksolid.shared.helpdesk
Subject: Re: Notice: Undefined Variable (continued)
Date: Mon, 21 Dec 2020 21:00:43 +0000
Organization: novaBBS
Message-ID: <789d48617330e507d9cade627331e8a6$1@www.novabbs.com>
References: <f91d608450459e34165aeca8ed6fbb23$1@news.novabbs.com> <e21778232129a63fe02e04a43da11c6b$1@www.novabbs.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org; posting-account="retrobbs1";
logging-data="10823"; mail-complaints-to="usenet@i2pn2.org"
User-Agent: Rocksolid Light (news.novabbs.com/getrslight)
X-Rslight-Site: $2y$10$Fnz.x9.TGcP7bHYejJ6VReWND0Czdhjadb.w2WLxPCmhPU/fNx56G
View all headers
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


Subject: Re: Notice: Undefined Variable (continued)
From: Retro Guy
Newsgroups: rocksolid.shared.helpdesk
Organization: novaBBS
Date: Mon, 21 Dec 2020 23:29 UTC
Path: i2pn2.org!.POSTED!not-for-mail
From: retro....@rocksolidbbs.com (Retro Guy)
Newsgroups: rocksolid.shared.helpdesk
Subject: Re: Notice: Undefined Variable (continued)
Date: Mon, 21 Dec 2020 23:29:19 +0000
Organization: novaBBS
Message-ID: <c72cb89f8a743bbf3fe436cb428e4018$1@www.novabbs.com>
References: <f91d608450459e34165aeca8ed6fbb23$1@news.novabbs.com> <e21778232129a63fe02e04a43da11c6b$1@www.novabbs.com> <789d48617330e507d9cade627331e8a6$1@www.novabbs.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org; posting-account="retrobbs1";
logging-data="31589"; mail-complaints-to="usenet@i2pn2.org"
User-Agent: Rocksolid Light (news.novabbs.com/getrslight)
X-Rslight-Site: $2y$10$t3rlpCKMbxd0.p8SIosXfuvPeWyAflFtWiQBDKI2r9Y9Qh5tzfQay
View all headers
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


1
rocksolid light 0.6.9
clearneti2ptor