rerun van pelt Posted July 22, 2009 Share Posted July 22, 2009 I tried searching but there is just too much info. I have an .html form that passes to a .php page which queries an mssql database. I read somewhere that the $_post is varchar and the column in the database is decimal. How do I convert the $_post to decimal Here is the form <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Open RMA</title> <link rel="stylesheet" type="text/css" href="open_rma.css" /> </head> <p><body> <h3>Enter Customer Id to search for Open RMA's</h3> <form method="post" action="open_rma.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Customer Id"> </form> <br> <br> <h3>If you don't know the Customer # <a href="customer_search.html" target="_blank">click here</a></h3> </body> </html> Here is part of the php <?php include ("header.php"); if(isset($_POST['submit'])){ if(isset($_GET['go'])){ { $name=$_POST['name']; } } include ("login.php"); include ("conn.php"); } $sqn="select name from address where id like '".$name."' //id is the decimal "; $rn=odbc_exec($conn,$sqn); This is the line it fails on: $rn=odbc_exec($conn,$sqn); and I traced it back to the varchar to numeric issue Link to comment https://forums.phpfreaks.com/topic/166899-solved-post-convert-varchar-to-numeric/ Share on other sites More sharing options...
xtopolis Posted July 22, 2009 Share Posted July 22, 2009 $name = (int) $_POST['name']; (though you should probably do validation on this rather than typecast it) and maybe $sqn="SELECT name FROM address WHERE id = $name"; Link to comment https://forums.phpfreaks.com/topic/166899-solved-post-convert-varchar-to-numeric/#findComment-879991 Share on other sites More sharing options...
rerun van pelt Posted July 22, 2009 Author Share Posted July 22, 2009 One little point I forgot to make. Sorry it was late when I posted. The form and the php work as they are in Firefox. It is only internet explorer that gives the error. I tried X's reply and still got the same error Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in /open_rma.php on line 26 Link to comment https://forums.phpfreaks.com/topic/166899-solved-post-convert-varchar-to-numeric/#findComment-880335 Share on other sites More sharing options...
rerun van pelt Posted July 22, 2009 Author Share Posted July 22, 2009 I found the problem, but I have no idea how to fix it. Let's say I input 2801 on the form. I added some code to the php to see what was being processed. $name=$_POST['name']; $int=(int)$name; echo "$int"; echo "-"; //only to help see which value is being returned echo "$name"; if(is_numeric($name)) { echo "'{$name}' is numeric", PHP_EOL; } Firefox returns the number that was entered on the form 2801-2801'2801' is numeric IE returns: 0- so this code "$int=(int)$name;" has nothing to process from IE Seems like IE isn't processing the number entered on the form. Link to comment https://forums.phpfreaks.com/topic/166899-solved-post-convert-varchar-to-numeric/#findComment-880566 Share on other sites More sharing options...
rerun van pelt Posted July 22, 2009 Author Share Posted July 22, 2009 After weeks of off an on trying to fix this I found the answer. There is an IE bug that won't pass the submit field when the is only 1 text field. Add this to the form and it works. <div style="display:none"> <input type="text" name="hiddenText"/> </div> Hope this will help someone else Link to comment https://forums.phpfreaks.com/topic/166899-solved-post-convert-varchar-to-numeric/#findComment-880597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.