AJinNYC
Members-
Posts
14 -
Joined
-
Last visited
AJinNYC's Achievements
Newbie (1/5)
2
Reputation
-
That definitely helped. This seems to work: <?php function find($initial, $goal){ $looped=0; $string=null; $hold=$goal; if($initial==0 || $goal==0){ return false; } while($hold > $initial){ $sqrt=sqrt($hold); if(floor($sqrt) == ceil($sqrt)){ $hold=sqrt($hold); $string.=' square '; if($sqrt==1) break; } else{ $hold=$hold-1; $string.=' increment '; } $looped++; } return $looped.':'.$string; } echo find(1,100); ?>
-
Just realized this: $looped=$looped++; Should be this: $looped++; And I should get rid of the equals sign in the while loop. However, it's still not returning what I'm expecting. This is the current result:
-
I'm having a bit of problems with the following: <?php function find($initial, $goal){ $looped=0; $string=null; $hold=$goal; while($hold >= $initial){ if(sqrt($hold) % 1 == 0){ $hold=sqrt($hold); $string.=' square '; } else{ $hold=$hold-1; $string.=' increment '; } $looped=$looped++; } return $looped.':'.$string; } echo find(1,100); ?> This should be printing out 5: square increment square increment increment (The part of the string after the colon will ultimately be flipped around, just haven't done that yet). But I'm just getting a never ending loop that ultimately leads to a memory crash of PHP.
-
Also, simply checking whether $POST_['submit'] is set might not generate proper results. isset($_POST['submit']) might return true even if it is null or in some circumstances even if it is blank. I find this covers every possible situation: if(isset($_POST['submit']) && ($_POST['submit']!=null || $_POST['submit']!='')) You really should check against the value of the submit button, not just whether it is set or not.
-
You're missing single quotes in in query on the $_POST array keys. ('$_POST[fname]','$_POST[lname]') ('$_POST['fname']','$_POST['lname']') Assign the post variables to another set of variables (say $fname and $lname) and drop those into the query. <?php $con = mysql_connect("sql2**.******.***","b8_14160309_simpleDB3","b8_14160309","c*******"); if (!$con) { die('Could not connect:' . mysql_error()); } mysql_select_db("b8_14160309_simpleDB3", $con); $fname=$_POST['fname']; $lname=$_POST['lname']; $sql="INSERT INTO simpleTable3 (fname, lname) VALUES ('$fname','$lname')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; ?> Also, part of the problem may be that you (and I, so not sure if mine will work either) are using variables inside single quotes in the query.
-
To chime in, my suggestion would be to use SHA-384 or SHA-512 (both considered to be SHA2). They're more secure than SHA1. You would use the PHP function hash_hmac and set the algorithm input to SHA-384 or SHA-512. http://www.php.net/manual/en/function.hash-hmac.php
-
One issue I see is it looks like you're missing your closing bracket on your select elements. It's not too hard to echo out. Just use single quotes, around the HTML block, and then you have to "breakout" of the single quotes because variables inside single quotes are treated like strings/plain-text. For example: echo 'Some Text '.$variable.' Some more text'; You can think of the quotes as thread and the periods (or more technically concatenating) as needle holes... you're stitching together the variable, and the text after the variable, to the first bit of text. So using the above method on your code, you end up with this. foreach ($arrValues as $row) { $id = $row['employee_id']; echo '<tr> <td><input type="text" name="record['.$id.'][firstName]" value="'.$row['first_name'].'" readonly /></td> <td><input type="text" name="record['.$id.'][lastName]" value="'.$row['last_name'].'" readonly /></td> <td><input type="text" name="record['.$id.'][height]" value="'.$row['height'].'" readonly /></td> <td><input type="text" name="record['.$id.'][cap]" value="'.$row['cap'].'" readonly /></ td> <td><input type="text" name="record['.$id.'][color]" value="'.$row['colors'].'" readonly /></td> <td><select name="record['.$id.'][degree]"> </td> <option> "Filler" </option> </select> <td><select name="record['.$id.'][school]"> </td> <option>'.$row['name'].'</option> </select> <td><input type="submit" name="update" value="Update" /></td> </tr>'; } If you don't know it, the definition of concatenating is to: link (things) together in a chain or series.
-
Regex for letters, hyphens, space, and periods only. (No Numbers)
AJinNYC replied to AJinNYC's topic in Regex Help
Excellent thanks. -
Need some help to get the right RegEx pattern for a preg_match check on names. It must match letters, hyphens, spaces, and periods only. No numbers or any other symbols. /*Verify that Names are in the proper format*/ function name_verify($name){ return preg_match("/^\b[\p{L}](?:[\p{L}. -]+[\p{L}])?\b$/u", $name); } This works except when there is a period in the value. Need periods for initials.
-
Post the code where you're connecting to the database (remove the password, username, hostname, etc. for security reasons when you post the code). Also the mysql extension was deprecated, you should look at the mysql improved extension.
-
I triggered an error on a custom made mysqli_sanitize function (basically a function to escape mysql data). The function requires two arguments and I only entered one. So the error is something like argument 2 is missing from function mysqli_sanitize. function mysqli_sanitize($link, $value){ if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $value=stripslashes($value); } return mysqli_real_escape_string($link, $value); } I entered the below to trigger the error: mysqli_sanitize(1);
-
I'm trying to use the following script given to me by 1and1 to generate an error log for php. This code is not creating a new file or updating the file even if I create it manually. //set time zone of website date_default_timezone_set("America/New_York"); //Set error warning for active or non-active site if($SiteIsActive=="no"){ error_reporting(E_ALL); } else{ error_reporting(0); $old_error_handler = set_error_handler("userErrorHandler"); function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars){ $time=date("d M Y H:i:s"); // Get the error type from the error number $errortype = array (1 => "Error", 2 => "Warning", 4 => "Parsing Error", 8 => "Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "User Error", 512 => "User Warning", 1024 => "User Notice"); $errlevel=$errortype[$errno]; var_dump($errno); var_dump($errmsg); var_dump($filename); var_dump($linenum); //Write error to log file (CSV format) $errfile=fopen("errors.csv","a"); fputs($errfile,"\"$time\",\"$filename: $linenum\",\"($errlevel) $errmsg\"\r\n"); fclose($errfile); if($errno!=2 && $errno!={ //Terminate script if fatal error die("A fatal error has occurred. Script execution has been aborted"); } } } This code is included into other scripts where it sets the error handling for those scripts. It works fine to determine if the error_reporting should be turned on (for debugging) or off when the site is active. But it won't generate the error log file. The var_dumps in there produce nothing at all. I know there is an error in the code, because I went out of my way to create one. And when the site is in debug mode it shows the errors as it should.
-
EDIT: Nevermind, my issue was that the function wasn't returning anything. The DB connection wasn't being returned out of the function. I can't for the life of me see why this prepared statement inside of the if conditional is not working: $dbConn=conn($host, $user, $password, $dbname, $_SESSION['websitename']); /* set autocommit to off */ mysqli_autocommit($dbConn, false); $executed_ok=null; if($prepareuserdetails=mysqli_prepare($dbConn, "INSERT INTO `userdetails` (`fname`, `email`) VALUES (?,?)")){ die("Test"); if($binduserdetails=mysqli_stmt_bind_param($prepareuserdetails, 'ss', $regfname, $regemail)){ if($executeuserdetails=mysqli_stmt_execute($binduserdetails)){ $executed_ok1=true; $lastID=mysqli_insert_id($dbConn); var_dump($lastID); } else{ $executed_ok1=false; } } else{ $dberrorshow=true; }*/ } else{ $dberrorshow=true; } if($prepareuser=mysqli_prepare($dbConn, "INSERT INTO `users` (`username`, `pass`, `id`) VALUES (?,?,?)")){ if($binduser=mysqli_stmt_bind_param($prepareuser, 'ssi', $regusername, $regpass, $lastID)){ if($executeuser=mysqli_stmt_execute($binduser)){ $executed_ok2=true; } else{ $executed_ok2=false; } } else{ $dberrorshow=true; } } else{ $dberrorshow=true; } //If there is a DB error, show message. if($dberrorshow===true){ die('Database Error: We couldn\'t connect to the database. Please return to the <a href="//'.getDomain($_SESSION['websitename']).'">homepage</a>.'); } else{ //If all queries executed okay, commit them; if not, rollback. if($executed_ok1===true && $executed_ok2===true){mysqli_commit($dbConn);} elseif($executed_ok1===false || $executed_ok2===false){mysqli_rollback($dbConn);} } I placed the die("Test") in there to see where it was failing, and it's failing at the prepare point... it immediately fails and heads to the error message. The query runs fine in phpMyAdmin. For reference: conndetails.php just has the connection details, dbname, username, password, and host. DBFuncs.php //Database Connection function conn($host, $user, $password, $dbname, $websiteName){ //MySQLi Connection $dbConnection=mysqli_connect($host, $user, $password, $dbname); /* check connection */ if(!$dbConnection){ if($_SESSION['siteisactive']=="no"){ $errormsg='('.mysqli_connect_errno().') '.mysqli_connect_error(); } else{ $domainname=getDomain($websiteName); $errormsg='We couldn\'t connect to the database. Please return to the <a href="//'.$domainname.'">homepage</a>.'; } die('Connection Error: '.$errormsg); } }