PHP - Slight Hand
Probably real basic but im nto great with the maths aspect of php, how would i get the $level + noto to show from the php below as currently i get,
From: System 4 minutes ago You have reached level 1 + 1 in Notoriety, Please check the Skill Points section to see if you now qualify for any upgrades! $sql="INSERT INTO messages (to_username,from_username,message,type, timestamp) VALUES('$playerdata[username]','System','You have reached level $level + 1 in Notoriety, Please check the Skill Points section to see if you now qualify for any upgrades!','Player', NOW())"; mysql_query($sql) or die(mysql_error()); Similar TutorialsHi I have been getting this error. mysql_fetch_array() expects parameter 1 to be resource, boolean given Its driving me mad I know its something really simple. Can anyone see what it is? Code: [Select] mysql_select_db("product", $con); $sqlout = mysql_query("SELECT * FROM 'tblt' WHERE 'UID' =('$ids')"); while($sqlres = mysql_fetch_array($sqlout)) Thanks James Hey guys for some reason my script is being strange. <? if(!empty($_POST['why'])) { $why = mysql_real_escape_string($_POST['why']); $answer = $_POST['answer']; $id = $_POST['cid']; if($answer == "Accept") { $query1 = mysql_query("UPDATE characters SET accepted = '1' WHERE id = '".$id."'"); $aquery = mysql_query("UPDATE applications SET tester = '".$_COOKIE['Username']."', accepted = '1', answered = '1' WHERE cid = '".$id."'") or die('Could not connect: ' . mysql_error()); echo"Successfully accepted"; } } If you notice the echo it outputs the successfully executed, tho the mysql query doesn't go through for some strange issue even through it says it does since I got the or die(mysql_error) thing and it still doesn't output a error. So I got a hard time finding the problem. Hey guys, I am adding to my current php form processor and I need it to be able to support image uploads, that also show up as an attachment in the email with the rest of the form data. The only part I am having problems with is getting the image to work as an attachment in the email, at the moment, it is not showing up at all in the email but it is successful at showing up on the web server (which I have it doing for storage reasons). I have attached the code involved for the image processing portion, an also a snippet of code showing how the emails are sent. This code is for the image attachment processing <?php //Get the uploaded file information $name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); //Get the file extension of the file $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;//size in KBs //Settings $max_allowed_file_size = 150; // size in KB $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png"); //Validations if($size_of_uploaded_file > $max_allowed_file_size ) { $errors .= "\n File size too large! Max file size alowed is $max_allowed_file_size"; } //------ Validate the file extension ----- $allowed_ext = false; for($i=0; $i<sizeof($allowed_extensions); $i++) { if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0) { $allowed_ext = true; } } if(!$allowed_ext) { $errors .= "\n The uploaded file is not supported file type. ". " Only the following file types are supported: ".implode(',',$allowed_extensions); } //Copy the temp. uploaded file to server $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; $tmp_path = $_FILES["uploaded_file"]["tmp_name"]; if(is_uploaded_file($tmp_path)) { if(!copy($tmp_path,$path_of_uploaded_file)) { $errors .= '\n Error while copying the uploaded file'; } } ?> This is the header setup for sending the email, which for some reason I think i am missing something here, causing the image to not show up in the email. Code: [Select] $headers = "From: edited_out_for_this_post@edited_out_for_this_post.com\r\n"; $headers .= "Reply-To: no-reply@edited_out_for_this_post.com\r\n"; $headers .= "Return-Path: no-reply@edited_out_for_this_post.com\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Thanks for your help in advance! Hey, The code below for some reason is showing; Hoes: 20000 Morale: 4.10 (hoes * hoe_morale * 2)); cred. Any ideas why i need it to show the actual result not the Maths thanks. <?php if($_GET['password']!="1234") { die("You do not have access to this page."); } else { include("functions.php"); include("db_connection.php"); $sql = "UPDATE users SET cash = cash + hoes * hoe_morale * 150, cred = cred + hoes * hoe_morale * 2 WHERE is_active = 1"; mysql_query($sql) or die(mysql_error()); $sql2="INSERT INTO messages (to_username,message,type, timestamp) VALUES('$playerdata[username]',' Hoes: $playerdata[hoes] Morale: $playerdata[hoe_morale] (hoes * hoe_morale * 2)); cred','player', NOW())"; mysql_query($sql2) or die(mysql_error()); echo "Ho Income complete"; } ?> How do I re write my code so it's
$itemAnnual0 = $values[0] * $periods[0]; $itemAnnual1 = $values[1] * $periods[1]; $itemAnnual2 = $values[2] * $periods[2]; ... $itemAnnual79 = $values[79] * $periods[79];
And for my previous post, I solved it. Hi, i made a registration page in php, Only problem is its not submitting anything to the database nor throwing back an errors. I'm confused as to why, the code is below any help will be appreciated thanks ** server.php holds the database info i.e Code: [Select] <?php ///Server Info $dbhost = "localhost"; $dbuser = "*****"; $dbpass = "******"; $dbname = "****"; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(); mysql_select_db($dbname); ?> Registration page in question; Code: [Select] <?php require_once('check.php'); session_start(); $name = $_SESSION['name']; require_once('server.php'); require_once('stats.php'); if($_POST) { function VisitorIP() { if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $TheIp=$_SERVER['HTTP_X_FORWARDED_FOR']; else $TheIp=$_SERVER['REMOTE_ADDR']; return trim($TheIp); } $ipaddress = VisitorIP(); $name = $_POST['username']; $namelength = strlen($name); $email = $_POST['email']; $password = $_POST['password']; $passwordlength = strlen($password); $confirm = $_POST['confirm']; if($namelength < 3){ $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Your username must be at least 3 characters!</span></div>"; echo $error1; } elseif($passwordlength < 6) { $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Password must be at least 6 characters long!</span></div>"; echo $error1; } elseif($email == "") { $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: You must enter an email address!</span></div>"; echo $error1; } elseif($password != $confirm) { $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Passwords do not match!</span></div>"; echo $error1; } else { include("server.php"); $query = sprintf("SELECT COUNT(id) FROM players WHERE UPPER(name) = UPPER('%s')", mysql_real_escape_string($_POST['username'])); $result = mysql_query($query); list($count) = mysql_fetch_row($result); if($count >= 1) { $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: that username is taken.</span></div>"; echo $error1; } else { $query1 = sprintf("INSERT INTO players(name,password,email,ip_address) VALUES ('%s','%s', '$email','$ipaddress');", mysql_real_escape_string($_POST['username']), mysql_real_escape_string(md5($password))); mysql_query($query1); $error1="<div class='text1' style='background-color:#FF0;'><span style='color:#390'>Congratulations, you registered successfully!</span></div>"; echo $error1; } } } ?> 2 weeks and i think i found a direction as to what i need.I worte a program and it will post to a php page. The php page needs to take the posted variables ($user) ($pass) and compair them aginst the database for existing users to return a vail or invaild login. It also needs to check and if not exits, save a 3rd and 4th variable to the the database ($serial) ($ip). Can someone giv eme guadance as to the commands i can research to accomplish this? Hello Guys,
You might have known about Luhn Algorithm, which is used to get checksum of IMEI of phones, credit cards etc etc. It is a public domain so it is not used for security but to ensure that client has passed the correct numbers etc etc.
Anyway, I am trying to get my hands on this algorithm and I will build a logic based on luhn algo to get the checksum, where I am stuck is how can I get the alternate numbers from a numeric string, for example I have written the following code to get all the numbers one by one into the array.
$imei = "356565451265856"; $lenOfStr= strlen($imei); $myArray = array(); //Get all numbers one by one in array for($i=0; $i < $lenOfStr; $i++){ $myArray[] = substr($imei,$i,1); } // Checking the array foreach($myArray as $seperatedNumbers){ echo $seperatedNumbers; }No the problem is that I want to select every 2nd number from right to left e-g 5,5,2,... or 6,8,6 How can I get it done? This logic may not be so good, there may be more brilliant solutions to write luhn algo, but I want to try myself once... Thanks. Edited by Digitizer, 31 August 2014 - 04:53 PM. Someone showed me a while ago this trick for loading variables, but it creates an error when you go to the page initially:
$fname = $_POST['fname'] ? $_POST['fname'] : null;How do I write the short hand to run correctly? Alright, this is the code that i cant seem to get working. Its supposed to update the pin_lock field in my database. I have two databases that it needs to read from, the Account database to verify the login, then the Game database to modify the pin_lock field. It comes up that its sucessfully modified the entry but when i check it, its still the same as it was before. session_start(); if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') { print("<center>Incorrect verification code!"); die(); } require_once('config.php'); mysql_select_db($accdb); $accountid=$_POST['accountid']; $pass=$_POST['pass']; $email=$_POST["email"]; $idnumber=$_POST["question"]; $phone=$_POST["answer"]; session_start(); if(!$_POST["accountid"]) { print("<center>Account ID Field Empty!"); die(); } if(!$_POST["email"]) { print("<center>E-mail Address Field Empty!"); die(); } if(!$_POST["question"]) { print("<center>Security Questions Field Empty!"); die(); } if(!$_POST["answer"]) { print("<center>Answer Field Empty!"); die(); } if(!ereg("^[0-9a-z]{4,12}$",$accountid)) { print("<center>Account ID Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 12 characters"); die(); } if(!ereg("^[0-9a-z]{4,14}$",$pass)) { print("<center>Password Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 14 characters"); die(); } if(!ereg("^[0-9a-zA-Z_]{4,128}$", (strtr($email, Array('@'=>'','.'=>''))))) { print("<center>E-mail Only letters a to z and special chars @ . are allowed!"); die(); } if($_POST["pass"]!=$_POST["pass2"]) { print("<center>Passwords do not match!"); die(); } $ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'"))); if (!$ac) { print("<center>Account ID does not exist!"); die(); } $em = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND email='$email'"))); if (!$em) { print("<center>E-mail is incorrect!"); die(); } $q = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND idnumber='$idnumber'"))); if (!$q) { print("<center>Security Question is incorrect!"); die(); } $an = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND phone='$phone'"))); if (!$an) { print("<center>Answer is incorrect!"); die(); } $ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'"))); mysql_select_db($gamedb); $temp["query"] = sprintf("UPDATE cq_user SET lock_key='0' WHERE account_id='$selectedid'"); if (!mysql_query($temp["query"])) { die(mysql_error()); } else { print("<center>You bank pin has been removed!"); } Any ideas what is wrong with it? I'm modifying a script I built a few months ago to allow someone to upload an attachment via a form and then email it off. It is expected that this form will receive a lot of hits and so it won't be possible to store the attachment in a folder before emailing it out (right away). Problem: If I skip the move_uploaded_file part, and just attach the tmp_name the tmp_name is how I receive it rather than the PDF that it actually is. How can i change the documents name before sending it off, without saving it to a general location. My worry with saving it is, someone uploads their copy and at the exact moment it's supposed to email off, someone somewhere else uploads theirs and it overwrites the first persons and then the email gets sent with the newest persons data. index.php Code: [Select] <form action="process.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> process.php Code: [Select] <?php print_r($_FILES); if ($_FILES["file"]["type"] == "text/plain") { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> |