Im having problems with a signup form I'm trying to create. It's for a class assignment - so don't give me code, but help me understand where I'm going wrong! I'm trying to make a signup form, that checks to see if the username exists, if it does prints a message. It's also meant to check it the password matches certain requirements ( Lowercase, Capital,Number and 6 Characters) I use preg_match but it always says the password doesn't meet the requirements. If it meets the requirements of both the username not existing and the password meeting the length it gets put into the database.
My problem right now is that no matter what I do, the matching says it doesn't meet the requirements, or it won't let me fix it without reloading the the signup form page.
Is there a different way I should go about this? I'm going to update everything to prepared statements after I figure out the logic for the signup.
<form method="POST"> <div class="form-account"> <label for="username">Username</label> <input type="username" class="form-control" id="username" name="username"> </div> <div class="form-account"> <label for="password">Password</label> <input type="password" class="form-control" id="password" name="password"> </div> <input type="submit" name="signsubmit" value="Sign Up" class="btn btn-primary"> <?php $username=""; $password="";
if(isset($_POST['signsubmit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username)){
echo "Enter a username";
}
if(empty($password)){
echo"Enter a password";
}
//See if username exists
else{
$sql="SELECT Login.username FROM Login WHERE Login.username='$username'";
$result = $conn->query($sql);
if($result->num_rows > 0){
echo "Username exists";
}
else if(!preg_match("(?=[^A-Z]*[A-Z])(?=[^a-z]*[a-z])(?=\D*\d).{6,}", $password)){ ?>
<div id="message">
<h3>Password must contain the following:</h3>
<p>A <b>lowercase</b> letter</p>
<p>A <b>capital (uppercase)</b> letter</p>
<p>A <b>number</b></p>
<p>Minimum <b>6 characters</b></p>
</div>
<?php }
else{
session_start();
//input information into DB have other code that I have removed for this.
}
}
I'm trying to create a mocked WordPress function but I cannot seem to get access to some of the variables due to scoping. I'm still new to PHP and this thing seems to work perfectly fine in JS land.
public function create_mocked_function( $arg1, $arg2 ) {
function mocked_wordpress_function( $arg0 ) {
$data = array(
'name1' => $arg1,
'name2' => $arg2,
);
return $data[$arg0];
}
}
Basically I am mocking a WP function in my test environment. When I set $arg1 and $arg2, they will create that associative array, so that whenever the mocked function is called, it will return based on $arg0.
Any way I can resolve this? I suspect it has something to do with the inner function becoming global, thus losing access to $arg1 and $arg2, but I'm still relatively new to PHP.
My PHP version is 5.2. I know it's old and insecure and out of date, but that's what I have to support. Don't respond if you are just going to threaten me to update or whine about old versions.
I want to loop through the $EvenNB array but I'm getting a " Notice: Undefined offset: 2 in C:\Program Files\VertrigoServ\www\Rand.php on line 27 "
Basically an offset error mean that I'm trying to reffer to an index key that is out of range or doesn't exist but how is this possible since I used the sizeof($EvenNB) function?
I tried using foreach loops, it works and doesn't give me an offset error but why this one doesn't work?
Here's my code:
<?php
$RandomNB = array();
$EvenNB = array();
$OddNB= array();
echo "<b>Random numbers:</b>";
for ($i = 1; $i < 30; $i++) {
$RandomNB[$i] = rand(1, 100);
echo " " . $RandomNB[$i];
if ($RandomNB[$i] % 2 == 0) {
$EvenNB[$i] = $RandomNB[$i];
}
}
echo "<br><br><b>Even numbers:</b>";
for ($i = 1; $i < sizeof($EvenNB); $i++) {
echo " " . $EvenNB[$i]; //LINE 27 of the offset error
}
?>
Hey,
So if I set snmp_set_valueretrieval(SNMP_VALUE_OBJECT);, then a walk or get will return an object with type and value.
The problem is - type returns an integer. So for example, a Gauge32 returns a type value of 66.
[iso.3.6.1.2.1.2.2.1.5.1] => stdClass Object
(
[type] => 66
[value] => Gauge32: 0
)
PHP help says to refer to the SNMP constants list re: the 'type' value.
But that is just a very short list of constants of some of the data types. There is no key/value pairing, and it doesn't include the majority of the SNMP data types.
So my question is... how do I get the SNMP data type string (Eg: Gauge32, Integer32 etc) from using the SNMP Datatype return value?!
As a workaround, I'm getting it from the value object by way of explode(':', $value,2); ... but it seems a little hacky.
Create a function taking a positive integer as its parameter and returning a string containing the Roman Numeral representation of that integer.
Modern Roman numerals are written by expressing each digit separately starting with the left most digit and skipping any digit with a value of zero. In Roman numerals 1990 is rendered: 1000=M, 900=CM, 90=XC; resulting in MCMXC. 2008 is written as 2000=MM, 8=VIII; or MMVIII. 1666 uses each Roman symbol in descending order: MDCLXVI.
Example:
solution(1000); // should return "M"
Help:
Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1,000
Remember that there can't be more than 3 identical symbols in a row.
So before fetching using pg_fetch_row, how can i know the columns in the returned result and maybe store them in an array? because I'm building a dynamic table based on user query and i have to show him the columns that he chose, what is the best way to do this?
is there anyway i can iterate through the columns of the result?
I tried making a timer that uses a php function to calculate the difference in days between the current date and a given enddate. It's a fairly simple and straightforward PHP function. I'll post the variables that build the timer below where the $startTimeStamp and $endTimeStamp come from an Advanced Custom Field datepicker field with a "Y/m/d" format.
$startTimeStamp = new DateTime($timer['startdate']);
$currentTimeStamp = new DateTime(date("Y-m-d"));
$endTimeStamp = new DateTime($timer['enddate']);
$numberDays = $endTimeStamp->diff($currentTimeStamp)->format('%a');
The $startTimeStamp variable only hides the timer until a given date. This adds the option to plan ahead and isn't vital to the countdown function.
The code for the timer is placed in the header and is called on multiple pages in a Wordpress website. The timer on the homepage works fine but timers placed on other pages in the live site don't seem to be updating at all. What could be the cause for the timers on the homepage to work but not for the additional timers?
6.9k
Subscribers
32
Online
Post specific problems or questions you have about PHP or your code. Hopefully someone will be able to help you out! If you got something out of here, please contribute back and help others :)