PHP - Checking If Variable Contains A Number At Line 1
Hi Guyz,
I need to check the variable $itemDescription to see if the client has entered a '1' before the item description(example: 1 table) Reason, is the client would like to add sales tax to all NOn-Food related items of 6.25% This is for a local auction house. It needs to be simple. i,e. Don't wanna add any more form fields. Just let the user type the number 1 before all items that need to be taxed. Here's my code: Code: [Select] <?php ob_start(); ?> <link rel="stylesheet" href="style.css" type="text/css"> <style type="text/css"> </style> </head> <?PHP session_start(); ob_start(); # Config settings below # Change these to whatever you want :) ############################# $cellsPerRow = '6'; ############################# include('connect.php'); // These queries get the amount of bidders that are in the database $getAllBidders = mysql_query("SELECT `id` FROM bidders"); $totalBidders = mysql_num_rows($getAllBidders); // This section is to check if the Add New Item form has been submitted if($_POST['addNewItem']) { // Retrieve Query Strings from URL $itemDescription = $_POST['itemDescription']; $itemPrice = $_POST['itemPrice']; $winningBidder = $_POST['winningBidder']; $totalDeals = $_POST['totalDeals']; $totalPrice = ($totalDeals*$itemPrice); // Check the submitted data and make sure all is correct if(!$itemDescription) { $message = 'You must enter an Item Description.'; } else if(!$itemPrice) { $message = 'You must enter an Item Price.'; } else if(!$winningBidder) { $message = 'You must enter a Winning Bidder ID.'; } else if(!$totalDeals) { $message = 'You must enter the amount of Deals.'; } else if(!is_numeric($winningBidder)) { $message = 'The Winning Bidder ID can only be numbers.'; } else { // Check to see if the bidder ID already exists $checkBidder = mysql_query("SELECT * FROM bidders WHERE biddersId='$winningBidder' LIMIT 1"); $checkBidder = mysql_fetch_assoc($checkBidder); // If the Bidder ID does not exist, we re-direct to allow us to save the Bidder ID if(!$checkBidder) { header("Location: ?action=confirmListing&iDesc=".$itemDescription."&iPrice=".$itemPrice."&wBidder=".$winningBidder."&tDeals=".$totalDeals.""); } else { // If Bidder ID exists we just insert the transaction accordingly mysql_query("INSERT INTO transactions (`itemDescription`, `itemPrice`, `bidderId`, `itemQty`, `totalPrice`) VALUES ('$itemDescription', '$itemPrice', '$winningBidder', '$totalDeals', '$totalPrice');"); $message1 = 'The transaction has been successfully added.'; mysql_query("SELECT owed From bidders WHERE biddersId='$winningBidder'") or die(mysql_error()); if ($row['owed']==0) { mysql_query("UPDATE bidders SET owed='1' WHERE biddersId='$winningBidder'") or die(mysql_error()); } } } } // This section is to check if the Add Bidder to database form has been submitted if($_POST['confirmBidder']) { $itemDescription = $_POST['itemDescription']; $itemPrice = $_POST['itemPrice']; $winningBidder = $_POST['winningBidder']; $totalDeals = $_POST['totalDeals']; $totalPrice = ($itemPrice*$totalDeals); $addBidder = $_POST['addBidder']; $checkInput= preg_match([1]+*); if ($itemDescription== $checkInput) $itemPrice= $itemPrice * 6.25%; mysql_query("INSERT INTO transactions (`itemDescription`, `itemPrice`, `bidderId`, `itemQty`, `totalPrice`) VALUES ('$itemDescription', '$itemPrice', '$winningBidder', '$totalDeals', '$totalPrice');"); $message1 = 'The transaction has been successfully added.'; if($addBidder == 'Yes') { mysql_query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder');"); $message1 .= '<br> The Bidder ID has also been added.'; mysql_query("SELECT owed From bidders WHERE biddersId='$winningBidder'") or die(mysql_error()); if ($row['owed']==0) { mysql_query("UPDATE bidders SET owed='1' WHERE biddersId='$winningBidder'") or die(mysql_error()); } } if($addBidder == 'No') { $message1 = '<br><font color= "red"> Bidder has NOT been logged.</font>'; } // $itemDescription = ''; // $itemPrice = ''; // $winningBidder = ''; // $totalDeals = ''; // $totalPrice = ''; // $addBidder = ''; } ?> <?PHP // This line of code will check the current task we are doing if($_GET['action'] == 'confirmListing') { $itemDescription = $_GET['iDesc']; $itemPrice = $_GET['iPrice']; $winningBidder = $_GET['wBidder']; $totalDeals = $_GET['tDeals']; ?> <form name="confirmBidder" method="POST" action="?"> <?PHP // This is the hidden data from the previous form // Better than using sessions and GET query ?> <input type="hidden" name="itemDescription" id="itemDescription" value="<?PHP echo $itemDescription;?>"> <input type="hidden" name="itemPrice" id="itemPrice" value="<?PHP echo $itemPrice;?>"> <input type="hidden" name="winningBidder" id="winningBidder" value="<?PHP echo $winningBidder;?>"> <input type="hidden" name="totalDeals" id="totalDeals" value="1"> <table cellpadding="0" cellspacing="1" border="0" style="background: #ffffff; margin: auto;"> <tr> <td colspan="2" class="formHeader"> Add New Auction Item </td> </tr> <tr> <td class="formField"> Add This Bidder? </td> <td class="formValue"> <select name="addBidder" id="addBidder" class="input" style="width: 195px;"> <option value="Yes">Yes</option> <option value="No">No</option></select> </td> </tr> <tr> <td colspan="2" class="formButton"> <input type="submit" name="confirmBidder" id="confirmBidder" value="Confirm Bidder Action?"> <input type="reset" name="reset" id="reset" value="Reset Form"> </td> </tr> </table> </form> <?PHP // If the action is not to confirm a listing then show add item section } else { ?> <?PHP//----- Add New Item Section -----\\?> <?PHP if($message) { echo '<div class="Error">',$message,'</div><div style="height: 10px;"></div>'; } else if($message1) { echo '<div class="Success">',$message1,'</div><div style="height: 10px;"></div>'; } ?> <form name="addNewItem" method="POST" action="?"> <table cellpadding="0" cellspacing="1" border="0" style="background: #ffffff; margin: auto;"> <tr> <td colspan="2" class="formHeader"> Add New Auction Item </td> </tr> <tr> <td class="formField"> Item Description </td> <td class="formValue"> <input type="text" name="itemDescription" class="formText" id="itemDescription" value="<?=$itemDescription;?>" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> Item Price </td> <td class="formValue"> <input type="text" name="itemPrice" class="formText" id="itemPrice" value="<?=$itemPrice;?>" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> Winning Bidder ID </td> <td class="formValue"> <input type="text" name="winningBidder" class="formText" id="winningBidder" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> How Many Deals? </td> <td class="formValue"> <input type="text" name="totalDeals" class="formText" id="totalDeals" value="1" style="width: 195px;"> </td> </tr> <tr> <td colspan="2" class="formButton"> <input type="submit" name="addNewItem" id="addNewItem" value="Add New Auction Item?"> <input type="reset" name="reset" id="reset" value="Reset Form"> </td> </tr> </table> </form> <?PHP//----- Add New Item Section -----\\?> <?PHP } ?> All help appreciated to the fullest... Similar TutorialsI 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? How can I check a variable to see if it is NULL and if so set to 0000-00-00? I've tried: if ($var IS NULL) THEN $var='0000-00-00'; to no avail. If I do a mysql query from a database on a field that either has a number or is blank, how can I write php to check that. In other words, I am getting that value back into a variable called $isaresult and doing... Code: [Select] if ($isaresult !== '') { //value exists } else { //no value yet } It's that first line of code that doesn't seem to be working. Should I be using "null" or something instead? I'm not real experienced with checking if a value exists, so let me know the proper way to do it (since I assume there are multiple ways). Thanks! Code: [Select] <?php function Login() { session_start(); $_SESSION["loggedin"] = true; echo "You are logged in!"; header("Location: ../L_index.php"); //Aka Logged in Index. } function Logout() { $_SESSION["loggedin"] = false; session_destroy(); } function checklogin() { session_start(); if ($_SESSION["loggedin"] == true) { return true; } else { return false; } } ?> This is just a tiny bit of my code, there is security holes, but as you see, there is 3 functions: Login Logout Checklogin But when i use the Login function, everything is fine, but if i then use the checklogin, then it always returns true(it returns true after i used the logout function), why? Hi All, I'm having a major mind blank, and can't find anything in the previous posts resolving what I'm after. I'm setting $searchtext = $_POST['searchtext']; I want to check $seachtext is not null. I've seen isset($searchtext) but it doesn't solve my problem. Basiclaly; I want an if statement to say if(isset($searchtext)) {......} Thoughts? I want to validate a form field for a number with two decimals (ie. 894567.29), but my script gives me an error, asking me to correct the entry, Following is a snippet of the script:- elseif($field == "oil_waste_ltr") { if(!preg_match("/^[0-9]{1,10}\.{2}$/",$value) ) { $bad_format[] = $field; } } I have the following if statement: Code: [Select] if ((isset($select_category) == 'All') || (!isset($select_category)) && (!isset($most_liked))) { The value for the variable gets taken from a drop down menu, which is a list of categories. The problem I am having is with the isset condition check is that the variable is always set, but it does not consider the check for equality with the 'All' condition. Which basically means no matter which category I choose from the drop down menu, it always goes to this very first if statement, and does NOT go to the other elseif statement, and I think it has to do with the isset condition check, because without it it would work, though without it I am getting a notice warning, that the variables are undefined. Any ideas how I can make it check if its equal to 'All' together with the isset condition check? What I am trying to say is no matter which category is chosen, with the isset condition check, the variable is always set, thus the if statement is true, there basically seems to be a contradiction going on. I’ve just read several manual pages and forum comments on "Error number 1064" but I still don’t understand what’s going on with the problem I'm having now … Also, I'm surprised that the error message mentions two different line numbers (1 and 35). Here is the error message I get : And here are the contents of my "one_more_visit_to_topic.php" file : <?php include("includes/model/database_searches/see_readings.php"); include("includes/model/database_searches/see_watchings.php"); function one_more_visit_to_topic($user_id,$topic_id) { global $db; $request_string='UPDATE forum_topic '. 'SET topic_vu = topic_vu + 1 WHERE topic_id = :topic'; $query=$db->prepare($request_string); $query->bindValue(':topic',$topic_id,PDO::PARAM_INT); $query->execute(); $query->CloseCursor(); // Remember that topic has been read by user if(!(see_if_user_has_read_topic($user_id,$topic_id))) { $request_string='INSERT INTO forum_read (fr_topic_id,fr_user_id) '. 'VALUES (:topic,:user)'; $query=$db->prepare($request_string); $query->bindValue(':topic',$topic_id,PDO::PARAM_INT); $query->bindValue(':user',$user_id,PDO::PARAM_INT); $query->execute(); $query->CloseCursor(); } // If user has already received a warning by mail, // the "alert" value needs to be toggled in the fw_watch table if(see_if_user_has_been_warned($user_id,$topic_id)) { $request_string='UPDATE forum_read SET fw_alert = :alt '. 'WHERE fw_topic_id = :topic AND fw_user_id= :user)'; $query=$db->prepare($request_string); $query->bindValue(':topic',$topic_id,PDO::PARAM_INT); $query->bindValue(':user',$user_id,PDO::PARAM_INT); $one=(int)1; $query->bindValue(':alt',$one,PDO::PARAM_INT); $query->execute(); $query->CloseCursor(); } return; } ?> how can you increase the page number in the following line until $status returns an empty result? curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: xxxxxxxxxxxxx:xxxxxxxxxxxxxxxx", "Page: 2")); Hi, I'm just starting PHP and I ran into a simple problem (that I can fix), but I just want to understand why my first approach doesn't work. I was testing multiplications and additions and the result I got was unexpected. Here is the code that doesn't work: Code: [Select] <?php $number1 = 5; $number2 = 10; print $number1." multiplied by ".$number2." + 1000 = ".$number1*$number2+1000; ?> Obviously, what I want as a result when I'm displaying the page is: "5 multiplied by 10 + 1000 = 1050" What I get: "1005". That's right, nothing else. On top of getting an erroneous answer, the sentence that's supposed to display right before the equation doesn't display at all. It's even worse if I switch it around like that: Code: [Select] print $number1." multiplied by ".$number2." + 1000 = ".1000+$number1*$number2; I get an error message and nothing displays. The obvious solution works: using a parenthesis at the beginning and at the end of the equation, which I should do regardless, but still, it's bugging me and since I just started learning PHP today, I want to understand how the code is compiled / interpreted so I don't make stupid mistakes like this one. Thanks in advance for the replies. I have the following code in my index.php: <?php $files = array(); $files = glob('download/*.iso'); $file = $files[count($files) - 1]; $strlen ( string $file ) : int /* length of $file */ $filelen = $strlen -9 /* length of unwanted characters - "download/" */ $filename = /* how do I get the filename starting at the 10th position */ ?> <div class="container"> <div class="divL"> <h3>Get the latest version of FoxClone iso</h3> <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt="" width="200" height="60"></a> I'd like to replace "Get the latest version of FoxClone iso" in the next to last line with "Get Foxclone "<?php echo "/{$filename}";?>". How do I extract just the file name from $file? I know that I have to:
1. get the length of $file Step 3 is where I just don't know how to accomplish the task. I'd appreciate some help on this.
Thanks in advance, I'm new at PHP and have a problem. I have a MySql database with lists of students grouped into classrooms. A typical group is shown in the attached screenshot screenshot.docx. I want to be able to select one or more of the names by using the associated checkbox, and upgrade a student or students into a different group as defined in the radio button list also in the screenshot. I have the rudiments of the file attached, but I have absolutely no idea how I can post the array so that the records are updated. Each student has an individual record with a field name userGroup which holds a string nominated by their classroom teacher, such as "year7", "year 8" and so on while they are in one of the several classrooms, but when they leave school this is recorded in a field named noGroup with a value of 0 or 1. I can post further details as required, but it would be great if someone could help me. Hi everyone, Like the title says I need to count the amount of 1's in a column but I can't figure out how. Gr and thanx already Ryflex Hi, How can I check if a variable only has these characters: - number (0-9) - decimal point (.) - positive (+) - negative (-) - dollar ($) I tried is_numeric, but it doesn't like negative values... I need to add the variable value to another variable. I have to accept numbers (including negative and decimals)... ex: 0.1 = TRUE -.1 = TRUE 12 = TRUE 1000.00 = TRUE 12a = FALSE thanks I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? I'm trying to increase the variables $schedulemonth, $scheduledate, $scheduleyear in each loop so that they look like $schedulemonth1, $schedulemonth2, $schedulemonth3, etc... for each of them. I've tried several options and know I'm on the right track, but no go. The customer will choose how many payments and the script below will loop that many times - I have that part working - but the calendar I'm using with the variables above is the issue. Here's the code I'm using. while ($balance > 0){ if ($balance>$monthlypayment){ $myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear); //output the calendar $myCalendar->writeScript(); echo " "; echo "<input type=\"text\" name=\"payment" . $monthlypayment . "\" value=\"" . $monthlypayment . "\">\n"; $paymenttotal=($monthlypayment+$paymenttotal); $balance=round(($invoicetotal-$paymenttotal),2); echo " Balance: $balance\n"; $schedulemonth++; if ($schedulemonth==13){ $schedulemonth=1; $scheduleyear=($scheduleyear+1); } echo "<br>\n"; } if ($balance<$monthlypayment||$balance==$monthlypayment){ $myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear); //output the calendar $myCalendar->writeScript(); echo " "; echo "<input type=\"text\" name=\"payment" . $paymentnumber . "\" value=\"" . $balance . "\">\n"; $paymenttotal=($balance+$paymenttotal); $balance=round(($invoicetotal-$paymenttotal),2); echo " Balance: $balance\n"; $schedulemonth++; if ($schedulemonth==13){ $schedulemonth=1; $scheduleyear=($scheduleyear+1); } echo "<br>\n"; } } Additionally it needs to pick up each of these variables on the next page the variables are part of hidden fields in an form later in the page. So my question is actually 3 fold. 1. How do I increase the variable count in the loop above. 2. How do I put the <input type="hidden".......> in the form so that it loops through and catches the increasing variables 3. How do I loop through on the insertion page after the form is submitted to catch how many inserts to the database are needed. This one has me bent over. I'm new to PHP and I'm just trying to make a form send. here's my code. I don't know what's wrong please help ! Code: [Select] <?php /*Subject and Email Variables*/ $emailSubject = 'Inquiry'; $emailAddress = 'inquiry@topazbranch.com'; /*Gathering Data Variables*/ $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $contact = $_POST['contact']; $email = $_POST['email']; $newsletter = $_POST['newsletter']; $projects = $_POST['projects_']; $trippingSchedule = $_POST['tripping schedule']; $source = $_POST['source']; $agent = $_POST['agent']; $comments = $_POST['comments']; $body = <<<EOD <br/><hr/><br/> Firstname : $firstname<br/> Lastname : $lastname<br/> Contact: $contact<br/> Email : $email<br/> Newsletter : $newsletter<br/> Projects : $projects<br/> Tripping Schedule : $tripping schedule<br/> Source : $source<br/> Agent name : $agent<br/> Additional Comments : $comments<br/> EOD; $headers = "From: $email\r\n"; $headers .= "content-type: text/html\r\n\"; $sucess = mail($emailAddress, $emailSubject, $body, $headers); /* Results render as HTML*/ $theResults = <<<EOD <html> <body> <h1>thank you</h1> </body> </html> EOD; echo "$theResults"; ?>
Hello everyone,
1 <?php
7 // Create connection
10 // Check connection
14 $firstname = $conn->real_escape_string($_REQUEST['firstname']); 25 $sql2 = "INSERT INTO countries VALUES ('$country')"; 27 $sql3 = "INSERT INTO Contacts (firstname, lastname, address, city, country, phone, email) VALUES ('$firstname', '$lastname', '$address', $city, $country, '$phone_number','$email')";
29 SELECT * FROM cities;
if($conn->query($sql2) === true){
if($conn->query($sql3) === true){ I am new to php and html, I am trying to make a search function where you can search by a persons firstname or lastname but I am getting an error. the error is Notice: Undefined variable: searchq in C:\wamp\www\search2.php on line 17. Can anyone help me please |