mrcarmine Posted October 15, 2009 Share Posted October 15, 2009 I want to make the database output an error message when a user puts a phone number in a form which is too long (>20 char) but its not working. This is my code: <html> <head><title>Sample Form Response</title></head> <body> <h1>Sample Form Response</h1> <?php $stringl == strlen(phone); $res = odbc_connect ("CTORACLE", "SCAT070", "SCAT070"); if (!$res) echo "Connection unsuccessful!"; elseif ($stringl >= 14) { echo "Phone Number length too long."; } else { $query = "insert into customers(name, address, phone) values ("; $query .= "'" . $_POST["name"] . "', "; $query .= "'" . $_POST["address"] . "', "; $query .= "'" . $_POST["phone"] . "'"; $query .= ")"; // echo $query; $cur = odbc_exec( $res, $query); if (!$cur) { echo "Query failed."; } else echo "Your details have been recorded!"; } ?> </body> </html> I have an idea where I am going wrong, I think I am not extracting the value which is being stored in 'phone' properly. How do you exract this value? Also, Could someone please narrate to me what is going on? what the hell is going on in this piece of code: $query .= "'" . $_POST["phone"] . "'"; What are the dots there for? Thanks. Link to comment https://forums.phpfreaks.com/topic/177811-help-me-code/ Share on other sites More sharing options...
MatthewJ Posted October 15, 2009 Share Posted October 15, 2009 <html> <head><title>Sample Form Response</title></head> <body> <h1>Sample Form Response</h1> <?php $stringl = strlen($_POST["phone"]); $res = odbc_connect ("CTORACLE", "SCAT070", "SCAT070"); if (!$res) echo "Connection unsuccessful!"; elseif ($stringl >= 14) { echo "Phone Number length too long."; } else { $query = "insert into customers(name, address, phone) values ("; $query .= "'" . $_POST["name"] . "', "; $query .= "'" . $_POST["address"] . "', "; $query .= "'" . $_POST["phone"] . "'"; $query .= ")"; // echo $query; $cur = odbc_exec( $res, $query); if (!$cur) { echo "Query failed."; } else echo "Your details have been recorded!"; } ?> </body> </html> The dots are concatenation operators... it is saying append phonenumber to the query wrapped in single quotes Link to comment https://forums.phpfreaks.com/topic/177811-help-me-code/#findComment-937556 Share on other sites More sharing options...
mrcarmine Posted October 15, 2009 Author Share Posted October 15, 2009 <html> <head><title>Sample Form Response</title></head> <body> <h1>Sample Form Response</h1> <?php $stringl = strlen($_POST["phone"]); $res = odbc_connect ("CTORACLE", "SCAT070", "SCAT070"); if (!$res) echo "Connection unsuccessful!"; elseif ($stringl >= 14) { echo "Phone Number length too long."; } else { $query = "insert into customers(name, address, phone) values ("; $query .= "'" . $_POST["name"] . "', "; $query .= "'" . $_POST["address"] . "', "; $query .= "'" . $_POST["phone"] . "'"; $query .= ")"; // echo $query; $cur = odbc_exec( $res, $query); if (!$cur) { echo "Query failed."; } else echo "Your details have been recorded!"; } ?> </body> </html> The dots are concatenation operators... it is saying append phonenumber to the query wrapped in single quotes AHHHH I get it. Thank you for that. So in order to utilise what value is held in 'phone', do I apply a string length method to $_POST["phone"] such as strlen($_POST["phone"]) would that work? Link to comment https://forums.phpfreaks.com/topic/177811-help-me-code/#findComment-937559 Share on other sites More sharing options...
MatthewJ Posted October 15, 2009 Share Posted October 15, 2009 Correct, I changed it in the code I reposted.. .you should be able to just copy that and run it. Link to comment https://forums.phpfreaks.com/topic/177811-help-me-code/#findComment-937560 Share on other sites More sharing options...
mrcarmine Posted October 15, 2009 Author Share Posted October 15, 2009 Correct, I changed it in the code I reposted.. .you should be able to just copy that and run it. Thanks it really works! Link to comment https://forums.phpfreaks.com/topic/177811-help-me-code/#findComment-937581 Share on other sites More sharing options...
mrcarmine Posted October 15, 2009 Author Share Posted October 15, 2009 So matthew , why are those "'" single quotations required? Link to comment https://forums.phpfreaks.com/topic/177811-help-me-code/#findComment-937583 Share on other sites More sharing options...
MatthewJ Posted October 15, 2009 Share Posted October 15, 2009 String data being inserted into mysql has to be wrapped in quotes in the query. Link to comment https://forums.phpfreaks.com/topic/177811-help-me-code/#findComment-937653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.