
garyed
Members-
Posts
198 -
Joined
-
Last visited
Everything posted by garyed
-
php mysql statement not working on decimal value
garyed replied to garyed's topic in PHP Coding Help
Thanks, that's good info . -
php mysql statement not working on decimal value
garyed replied to garyed's topic in PHP Coding Help
What I would like to do is have most of the numbers go to 2 decimals & just a few go to 4 decimals. The problem with that is if I set decimals to (10,4) so it will read a number like 32.0756 then 27.55 goes to 27.5500 & it looks kind of cumbersome. That's why I originally thought float was best for my database but I didn't know how floats were treated. -
php mysql statement not working on decimal value
garyed replied to garyed's topic in PHP Coding Help
Can I assume if I wanted to have the capability of a number as large as 125000.50 that I would need to set something like " cost decimal(10,2)" for that. -
php mysql statement not working on decimal value
garyed replied to garyed's topic in PHP Coding Help
As usuall you guys are right on the money. I spent all day working on this & even spent about an hour google searching to no avail. Why i never thought that float could be a problem was because the number sits right in the database as is & prints out as it is also. It's only the the = sign that doesn't recognize it. -
php mysql statement not working on decimal value
garyed replied to garyed's topic in PHP Coding Help
float -
I have a query that only works using like but not with = on decimal values even if the values are exact: $sql_amount=mysqli_query($con,"update $table set item='$item1' where cost= 27.55" ); $sql_amount=mysqli_query($con,"update $table set item='$item1' where cost like 27.55 " ); The second way works but I can't figure out why the first way doesn't. I can reverse the first query using set cost = 27.55 where item='$item1' & it works fine. Is there something I'm missing in the first command that will not let me use the "where" with an = sign on a decimal?
-
Unless I'm missing something that link only descibes how to edit the mysql database which I arleady have no problem with. My only prblem is eidting the databse without having to reload the webpage. I'm not sure what API you're referring to but I didn't see it on the link you posted but I'm not even sure what API really is. What I'm looking for is a some way whether it's javascript, ajaxj,jquery or something else that will tell a php function to run on the server without reloding the page.
-
I thought I could just change the php function in my example to a mysql call to edit a database & it would work from plain javascipt but I was obvuiously wrong. Thanks for setting me straight before I wasted any more time. It looks like I'm going to have to learn some ajax to do what I want. As for the page reloading time issue, I'm sure I can solve the time issue using just php code but I wanted to learn a way to execute a php function without reloading the page.
-
I get what you're saying about the server side protecting against a malicious query & I understand I need to work on that. My real question is whether there any more danger in using my javascript example to call the php function than if I was to use ajax instead. As for the time issue, when the page loads it pulls data from other sources that are not from my server & that is what takes so long. Editing my database is virtually instantaneous so there is quite a bit of down time saved if I can do it without reloading the page every time the database is edited.
-
To go a little further into what I'm planning to do with my php function is to edit a mysql database. That's why I was concerned when I read about my javascreipt method of calling the php function being insecure. I was trying to figure out how calling a php function with javascript would be any more insecure than any php code that is executed when a page loads.
-
I have a php file that pulls information from another source & takes about 5 to 10 seconds to load. After it loads I want to be able to run a php function from the page without waiting for it to reload. I found a simple way to do it wit Javascript but my research is telling me it's very dangerous & would open the server to malicious attacks. I'm trying to understand why & also to see if there is another simple option to do it. Here's an example of the code I'm using: <?php function tester() { $x= "Get or do anything you want from the server"; echo $x; } ?> <script> function test1() { var test = "<?php echo tester(); ?>"; document.getElementById("tx1").innerHTML=test; } </script> <div id="tx1">This shows on page load </div> <button onclick="test1();"> call php function</button>
-
Thanks for the reply, That makes a lot of sense.
-
In trying to get the text off a particular website, I've used two different ways, both of which seem to work fine & give the exact same results.. I was wondering if anyone could give me any insight or recommendations why one way might be any better or worse than the other . I've used these two ways: $ch1=curl_init(); curl_setopt($ch1,CURLOPT_URL,$link1); curl_setopt($ch1,CURLOPT_RETURNTRANSFER, true); $text1=curl_exec($ch1); // or $text1 = shell_exec('curl '.$link1 ); The second way seems easier & speedwise they both are about the same I've also tried "file_get_contents" which also gives the same results but is obviously slower.
-
Thanks, that's exactly what I needed. I thought I had posted in the wrong forum because I had no idea what REGEX was or meant. In all the years I've been playing around with PHP, I hardly ever used regular expressions & I didn't even know that is what they were called either.
-
I've been trying to find some sort of tutorial on how to come up with search patterns for a function like preg_match. I was hoping someone here could point me to a site with a tutorial so I don't have to do a search every time I need to find a particular pattern. I don't need any specific search pattern right now but it's frustrating not having a clue on how to come up with one.
-
I'm learning things like this the hard way & I really appreciate all the constuctive help. The majority of my code is in php & the errors of my ways are building up.
-
Thanks for the heads up. It looks like isNaN even returns false on an empty input.
-
I think this is probably the best solution but I have about 100 different input fields to sort through & about 60 of them need to be numeric. I already had a list of the those 60 field names in an array so I thoght it would be a good idea to do it by including a simple external .js file & leaving the original file alone. I do like your idea & really appreciate the help. I'm learning as I go & didn't even know getElementsByClassName even existed.
-
Thanks to all, I appreciate the ideas. If I'm understanding things correctly shouldn't the line in the above code be the letter "i" instead of "0" in the: let linker = item[0].value Here's what I came up with that seems to work: const arrayone= ["it_c","it_h","ot_c","ot_h"]; function hasNumericValue(arr) { // check for numeric values posted in the array of the input fields var items, comd1, comd2; for (let i = 0; i < arr.length; i++) { items=arr[i]; comd1="document.tester."+items+".value"; comd2=eval(comd1); if (isNaN(comd2)) { alert(comd2+ " is not a number"); return false; } } alert("all the numbers needed have been entered"); return true; }
-
I have a lot of inputs on a form & a good many have to be numeric. I have all the names of the inputs that need to be posted as numbers in an array. I don't want to use type="number" on the inputs but would rather use a javascript function that would return either true or false when submitting the form with onsubmit= "return function()". This way I can put up an alert & display the field in error & it won't change the look of the page. The problem is I can't figure out how to use the elements of the array in the commands needed to test them. I can figure out how to check them for numeric values individually but at this point I just need to figure out how I can use the elements of the array in the command : documet.form_name.input_name.value so I can check them all. Here's a temporary code: <html> <head> </head> <body> <script> const arrayone= ["it_c","it_h","ot_c","ot_h."]; function hasNumericValue(arr) { // check for numeric values posted in the array of the input fields var linker; var items; for (let i = 0; i < arr.length; i++) { items=arr[i]; linker="document.tester."+items+".value"; alert("you made it to step2"+ linker) if (linker == 10) { alert("it works true"); return true; } } alert("it doesn't worlk False"); return false; } </script> <form name="tester" method="post" action="" onsubmit="return hasNumericValue(arrayone);" > <input name="it_c" type="text" value=""> <br> <input name="it_h" type="text" value=""> <br> <input name="ot_c" type="text" value=""> <br> <input name="ot_h" type="text" value=""> <br> <input type="submit" value="submit"> </form> </body> </html>
-
I thought about marking this thread as solved but I would be lying because I still am in the process of trying to solve all my errors. It seems rather ridiculous that one version of php will work with errors turned off while a newer version won't. I've already fixed over a hundred errors in php 8.x & things are looking worse than before I started. I can go back to php 7.4 & the program will work flawlessly. If it's not an undefined variable error, it's a string & int error or something else. It's frustrating because I spent years writing this program & just learned as I was going along. It's been working fine for 10 years & now the upgrade to php 8.x has killed it. I've got over 1000 variables I'm dealing with & hundreds of calculations so it's not a simple task.
-
I appreciate the help. It's a lot of good information that I've got to process. I'm a little slow at times but i'll eventually get it.
-
I'm tried your code but it still doesn't insert the session data in the fileds & dropdown when I leave & return. I'm not sure what I'm missing but the only thing I know to do is to add something similar to what I already have to get it to work.
-
Thanks, I'll check into "heredocs". I never even heard of it before you just mentioned it. I'm also going to study your code until I understand it better. What I'm really trying to do is to havel all 50 states in the dropdown menu from a MYSQL database & put whichever one is selected into the session. Then change the page to perform another task then return to the page & have the state from the session be already selected upon return.
-
It seems to work fine but I would like to hear what you guys who are more versed in php think. In my previous post I was trying find a way to hide the errors but I really want to get things right this time. This is a sample code that I'm using as a test but on my site I'm going to be pulling my variables off a database & using a while loop to fill in all 50 states. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); // Starts session & uses function to keep data */ function get_value($var) { // this will check your session if it's not empty and you send an empty post if ($_POST[$var]!="" || (!empty($_SESSION[$var]) && $_POST[$var] === '')) { $_SESSION[$var]=$_POST[$var]; } if (isset($_SESSION[$var])){ return $_SESSION[$var];} else{ return $_POST[$var];} } if(!isset($_POST['submitter'])) {$_POST['submitter']="anything"; } // initialize to avoid Undefined array key error ?> <form name="test" action="" method="post"> <input type="text" style="width:255px;" name="owner" value="<?php if(isset($_POST['owner'])) {echo get_value('owner'); } else { if(isset($_SESSION['owner'])){ echo $_SESSION['owner'];} } ?>"> <br> <input type="text" style="width:255px;" name="renter" value="<?php if(isset($_POST['renter'])) {echo get_value('renter');}else { if(isset($_SESSION['renter'])){ echo $_SESSION['renter'];} } ?>"> <br> <select name="state" > <option value=""> select state </option> <?php $state1="Maine" ; $state2="Texas" ; ?> <option value="<?php echo $state1; ?>" <?php if(isset($_POST['state'])) { if(get_value('state') == $state1) { echo 'selected="selected"'; } } else { if(isset($_SESSION['state'])){ if ($_SESSION['state']==$state1) { echo 'selected="selected"'; } } } ?> > Maine </option> <option value="<?php echo $state2; ?>" <?php if(isset($_POST['state'])) {if (get_value('state')==$state2) { echo 'selected="selected"'; }} else { if(isset($_SESSION['state'])){ if ($_SESSION['state']==$state2) { echo 'selected="selected"'; } } } ?> > Texas </option> </select> <br> <br> <br> <input type="submit" value="submit"> <input name="submitter" type="submit" value="clear session"><br> </form> <?php if ($_POST['submitter']=="clear session") { echo $_POST['submitter']."<br>"; session_destroy(); }; print_r($_SESSION); ?>