PHP - Placing Limits On Variable Input, And Displacing Results Once Variable Is Entere
Hello all. I am very new to PHP, and I am not sure where to look or what I'm looking for in my current assignment.
My task is to take in two numbers between 0-100. Once I take in that number, it should state beside it "The __ was accepted." The program should not accept any numbers greater than 100 or any characters. Once I do this, I must take a second number and do a similar thing. Finally, I must have a statement show up at the bottom stating which number is greater. Essentially, I need help in determining what I should use to place parameters, and how I can keep the program from echo ing any statement until input has been taken and tested for parameters. Any help you can provide will be greatly appreciated! Similar TutorialsHi There, I would like to place the last for month names into an variable- for example: February 2011 January 2011 December 2010 November 2010 But I would like them to all have the same variable ($date) - so when I use it in a mssql_fetch_assoc - it increments with every instance of $date, as there will be one instance of $date for every row returned, getting older with every row. Hope that is enough info? Cheers Matt I'm trying to take a number of items from a database using a while loop and put the results into a variable so that I can send one email with all the results. I'm having trouble figuring this out though. Can anyone please give me any ideas as to how to make this work? Here's what I've done so far... all it does is result in an email with the first set of results in the while loop, not all of them. Code: [Select] <?php include("conf.inc.php"); $result = mysql_query("SELECT `to`,`from`,`subject`,`message`,`date` FROM allmsgs WHERE reported = 'n' ORDER BY `messid` ASC"); $row = mysql_fetch_row($result); $cdate = date('m-d-Y'); $sendto = "List@emails.here"; $emailsubject = "Webstats Report For $cdate."; while ($row = mysql_fetch_row($result)) { $to = $row[0]; $from = $row[1]; $subject = $row[2]; $message = $row[3]; $datetime = $row[4]; $eachmessage = "<p> <table width=\"400\"> <tr> <td> <hr width=\"400\"> To: $to<br> From: $from<br> On $datetime<br> <br> $subject<br> <br> $message </td> </tr> </table> </p>"; } $emailmessage = "<html> <body> <p>Here is a list of the messages that have been exchanged in the last 24 hours using the webstat system system.</p> $eachmessage </body> </html>"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Webstats <reports@webstats.com>' . "\r\n"; // Mail it mail($sendto, $emailsubject, $emailmessage, $headers); ?> Hello everybody.
I'm changing some php in one wordpress website.
What I'm trying to do is to pass some values from one website page to the other.
When I do it this way, everything works fine:
Example 1:
First php file: (the one sending the value)
$Variable1 ='Hello'; $_SESSION['kamail']=$Variable1; printf('<li> Variable value:'. $Variable1 .'</li>'); Second php file: (the one getting the value) $Variable2=($_SESSION['kamail']);In the previous "Example 1" I get the correct value in $Variable2 and the print_f also prints the correct value In the next "Example 2", it does print the correct value, but in the second file, $Variable2 gets a completely different value. Example 2: First php file: (the one sending the value) $Variable1 =($javo_directory_query->get('email')); $_SESSION['kamail']=$Variable1; printf('<li> Variable value:'. $Variable1 .'</li>'); Second php file: (the one getting the value) $Variable2=($_SESSION['kamail']);I guess that this haves something to do with pointers or something similar, but I'm a completely PHP beginner, so I'm stuck with this Francisco I have to make a mail form (which is already coded) that will pull peoples names and email address from a database based on certain form parameters. I have the form done and am so close on finishing it up but am stuck on some mail() issues. I have the form set up to use: mail($sendTo, $theSubject, $theMessage, $headers); Using this format, I know that I can send this email to multiple recipients at once doing the following: mail('Name1 <email1@na.com>, Name2 <email2@na.com>', $theSubject, $theMessage, $headers); So I have my mySQL query all set up and it looks like so: $query="SELECT * FROM operations_forms WHERE department='$initiatedBy'"; $result=mysql_query($query); while( $row = mysql_fetch_assoc( $result ) ) { $name = $row["name"]; $email = $row["email"]; $recip = $name . " <" . $email .">, "; $sendTo = $recip; } The problem I am having is that my $sendTo variable only is passing on one record, not a combination of all of them. I am at a loss here on how to spit out all the variables and then combine them into one. I can use the above and produce an echo call that looks correct... but it doesn't function correctly on the back end. Any help? Thanks! Hello, i have the code below and i need to have all results in a variable as a string, inside the loop they are displayed how i want but outside will echo the last result. Thank You. Code: [Select] foreach($_POST as $key=>$value){ if (is_numeric($value)) { $valoare = "$value,"; } } echo $valoare; Hi. I need some help getting my preg_match regex working with a variable input. I'm trying to limit visits to once per day, after you come the first time, you are added to data.txt and will be denied if you come again. The code works, but I need to limit the searches using ^ and $ and I'm having some difficulty. $number will be a number input from an html form ranging from 1-1000+ and I want to make sure that 1,10,100 etc., aren't treated as the same. here is my preg_match, how do I use regular expressions with $number? Code: [Select] preg_match("/$number/", $file, $match) from what I have read, it should be like this, but it doesn't work Code: [Select] preg_match('/^+$' , "/$number/", $file, $match) heres the full code Code: [Select] $filename = "data.txt"; $handle = fopen($filename, "r"); $file = fread($handle,filesize($filename)); if (preg_match("/$number/", $file, $match)) { echo " Sorry, Already visited today"; exit; } else { fclose($file); $file=fopen(data.txt,"a") or exit("Unable to open file!"); fwrite($file, "$number"); fwrite($file, "\n"); fclose($file); echo " Accepted!"; exit; } Thanks So basically I want to take this input "site:google.com" And record only the "google.com" part as a variable. Any idea how to do that? Well this may sound confusing. I tried to findways to allow users to input an integer value and then assign it to a variable called $quantity, but all I could find from the internet was the usage of forms. Do I have to use forms, or can I just try this this simple syntax: $quantity = "<input name='quantity' type='text' id='quantity' size='3' maxlength='3'>"; If I do have to use forms, then how can I ever assign user's input value to a variable? Please help. Here's a question for all you great php programmers. What I want to do is use a variable username as the name of a select input of a form. I.E echo"<select name='$user'>"; Of course this code doesn't work though I feel sure that there must be a way to do this. Anyone know it? I am trying to allow the user to update a variable he chooses by radio buttons, which they will then input text into a box, and submit, to change some attributes. I really need some help here. It works just fine until I add the second layer of variables on top of it, and I can't find the answer to this question anywhere. <?PHP require('connect.php'); ?> <form action ='' method='post'> <select name="id"> <?php $extract = mysql_query("SELECT * FROM cars"); while($row=mysql_fetch_assoc($extract)){ $id = $row['id']; $make= $row['make']; $model= $row['model']; $year= $row['year']; $color= $row['color']; echo "<option value=$id>$color $year $make $model</option> ";}?> </select> Which attribute would you like to change?<br /> <input type="radio" name="getchanged" value="make"/>Make<br /> <input type="radio" name="getchanged" value="model"/>Model<br /> <input type="radio" name="getchanged" value="year" />Year<br /> <input type="radio" name="getchanged" value="color" />Color<br /><br /> <br /><input type='text' value='' name='tochange'> <input type='submit' value='Change' name='submit'> </form> //This is where I need help... <?PHP if(isset($_POST['submit'])&&($_POST['tochange'])){ mysql_query(" UPDATE cars SET '$_POST[getchanged]'='$_POST[tochange]' where id = '$_POST[id]' ");}?> My login script stores the user's login name as $_SESSION[ 'name'] on login. For some unapparent reason, i'm getting errors stating that $user and $priv are undefined variables, though I've attempted to define $user as being equal to $_SESSION['name'], using $user to look up the the user's privilege level (stored as the su column ) in the SQL table, and then where the result of the sql query is $priv which is then evaluated in an if statement. I can't seem to figure out why this might not be working. The code I'm using: <?php session_start(); function verify() { //verify that the user is logged in via the login page. Session_start has already been called. if (!isset($_SESSION['loggedin'])) { header('Location: /index.html'); exit; } //if user is logged in, we then lookup necessary privleges. $_SESSION['name'] was written with the login name upon login. Privleges // are written in db as a single-digit integer of of 0 for users, 1 for administrators, and 2 for special users. $user === $_SESSION['name']; //Connect to Databse $link = mysqli_connect("127.0.0.1", "database user", "password", "database"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } //SQL Statement to lookup privlege information. if ($result = mysqli_query($link, "SELECT su FROM accounts WHERE username = $user", MYSQLI_STORE_RESULT)) { //LOOP TO CYCLE THROUGH SQL RESULTS AND STORE Privlege information as vairable $priv. while ($row = $result->fetch_assoc()) { $priv === $row["su"]; } } // close SQL connection. mysqli_close($link); // Verify privleges and take action. Only a privlege of "1" is allowed to view this page. A privlege of "2" indicates special //accounts used in other scripts that have certain indermediate additional functions, but are not trusted administrators. if ($priv !== 1) { echo $_SESSION['name']; echo "you have privlege level of $priv"; echo "<br>"; echo 'Your account does not have the privleges necessary to view this page'; exit; } } verify(); ?>
I have just re-installed Xampp and suddenly my sites are now displaying lots of: Notice: Use of undefined constant name - assumed 'name' in ... Notice: Use of undefined constant price - assumed 'price' in ... this is an example of the line its refering too: $defineProducts[1001] = array(name=>'This is a product', price=>123); I have a script that adds points together based upon the placing. This is the actual script: Code: [Select] <? $points = 0; if($place === '1st') {$points = $points + 50;} elseif($place === '2nd') {$points = $points + 45;} elseif($place === '3rd') {$points = $points + 40;} elseif($place === '4th') {$points = $points + 35;} elseif($place === '5th') {$points = $points + 30;} elseif($place === '6th') {$points = $points + 25;} elseif($place === '7th') {$points = $points + 20;} elseif($place === '8th') {$points = $points + 10;} elseif($place === '9th') {$points = $points + 10;} elseif($place === '10th') {$points = $points + 10;} elseif($place === 'CH') {$points = $points + 50;} elseif($place === 'RCH') {$points = $points + 40;} elseif($place === 'TT') {$points = $points + 30;} elseif($place === 'T5') {$points = $points + 30;} elseif($place === 'Champion') {$points = $points + 50;} elseif($place === 'Reserve Champion') {$points = $points + 40;} echo "Total HF Points: $points"; ?>What it *should* do (my friend's script works the same way and it works) it starts at points = 0, than if there is a first place, it adds 50, and so forth until it reaches the end. It is included into a file, in this area: Code: [Select] <div class="tabbertab"> <h2>Records</h2> <? $query92 = "SELECT * FROM THISTABLE WHERE VARIABLE='$id' OR VARIABLE = '$name' ORDER BY ABS(VARIABLE), VARIABLE"; $result92 = mysql_query($query92) or die (mysql_error()); echo "<table class='record'> <tr><th>Show</th> <th>Class</th> <th>Place</th></tr> "; while($row92 = mysql_fetch_array($result92)) { $class = $row92['class']; $place = $row92['place']; $entries = $row92['entries']; $race = $row92['show']; $purse = number_format($row92['purse'],2); echo "<tr><td>$race</td> <td>$class</td> <td>$place</td></tr>"; } ?> <tr><td colspan='3'><div align='right'><? include('includes/points.php'); ?></div></td></tr> </table> </div> This is the code that is relevant. When ended here, it echoes the last place that appears in the results (such as a 5th place echoing 30 points). When I move it to be included in the while loop, it shows Total Points: 50 Total Points: 25 Total Points: 10 (depending on the results displayed on that page). What am I doing wrong? I have a form that creates rows of data input textboxes depending on a user input number of things. I have a naming convention for all these textboxes that basically just keeps incrementing a number suffix for each row. All this is working fine. My problem is I need to get the data inserted into this table of textboxes into an array. Here's my code where I attempt to to this (it does not work): Code: [Select] $temp = $_SESSION['Num_Part']; $count = 1; while ($count <= $temp){ $temp2[$count] = "'Participant_P".$count."'"; //echo $temp2[$count]."<br/>"; $temp3[$count]=$_POST[$temp2[$count]]; //here's the problem $temp4[$count] = "'Result_P".$count."'"; $temp5[$count]=$_POST[$temp4[$count]]; //here's the problem //echo $temp4[$count]."<br/>"; $count++; } The problem is that the $_POST does not work with the variable in the argument position - even though the argument is formatted with single quotes. Can a variable be used in a POST argument and if so what is the correct syntax? If not, is there some other simple solution to harvest the data into an array. I understand I can harvest by explicitly accessing each key in the post assoc array. But this could be dozens of rows of input fields. Thanks in advance for your help here. I couldn't find anything online re this topic. Hello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? Code: [Select] <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu Probably something simple but I have searched high and low and can't figure this one out. I have a variable that is of the datetime format. I have another variable that is of the time format. I need to add them together. Example: $var1 = 2012-02-24 06:38:22 $var2 = 02:00:00 $var3 = $var1 + $var2 = 2012-02-24 08:38:22 Thanks for the help! hi all, I have an language pack for example: languages/en.php: Code: [Select] $en['mail']['letter closing'] = "regards,\n your friend!"; and in my config: Code: [Select] $language = "en"; $include_language = @include("languages/".$language.".php"); if(!($include_language)) { $try_default_language = @include("languages/nl.php"); if(!($try_default_language)) { echo "kan de taalpakket niet vinden<br>"; echo "Could not find the language pack.<br>"; echo "example on error: ".$test." shows nothing"; exit; } } In my function I want to include the language pack for example i have $language = 'en' so I want to include $en['general']['letter closing'] I will do this: Code: [Select] global $language,${$language}['general']; But that gives an error unexpected '[' blah blah. How can i call the variable variable array in the valid php way? I have a function that get's a quick single item from a query: function gimme($sql) { global $mysqli; global $mytable; global $sid; $query = "SELECT ".$sql." FROM ".$mytable." WHERE sid = ".$sid; $result = $mysqli->query($query); $value = $result->fetch_array(MYSQLI_NUM); $$sql = is_array($value) ? $value[0] : ""; return $$sql; // this is what I've tried so far $result->close(); } It works great as: echo(gimme("name")); Then I realized that I could use that as a variable ('$name' in this case) elsewhere. However, I can't figure out how get that new, variable variable 'outside' of the function. As such, echo($name); isn't working outside the function. Is there a way to return a variable variable? In other words, is there a way to make a function that creates a variable variable that will available outside of the function?
Thanks
Quote i need to store a variable from database like if i have "copies" in one of my column in my database then i have to store a particular value for copies store it to $copies here i want that i can store value of copies into $copies $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } } I just moved my code from Appserv to EasyPHP and it gave me this error, it was working fine on Appserv...what's with easyPHP ?? |