confused_aswell Posted May 18, 2011 Share Posted May 18, 2011 Hi I have a database created through PHPMYADMIN and have successfully connected to it via Dreamweaver. All of the entries on the database work except the phone entries, In the table, I have set the phone to VARCHAR (30) and the php code in dreamweaver to collect the entry from the text box as an integer, but it doesn't collect the phone number correctly. For example it might put 1628 as an entry in the database if you put 01234 567890 as a phone number. I just can't understand why it is doing this? So any help here would be appreciated. Thanks in advance Phil Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/ Share on other sites More sharing options...
Pikachu2000 Posted May 18, 2011 Share Posted May 18, 2011 There has to be some pattern to the behavior; I doubt it just ends up with a random number in the field. You'll need to check to make sure you're not overwriting the variable somewhere in the script, and that the form field is set up correctly. The output of print_r($_POST) will also be helpful to make sure the value is being passed from one script to the next correctly. Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/#findComment-1217239 Share on other sites More sharing options...
confused_aswell Posted May 19, 2011 Author Share Posted May 19, 2011 Hi Thank you for replying to my post. I have ran the print_r($_post); in my script and it printed Array () on the browser. I can't see any other errors in the script so I have included it for you to look at. I look forward to your reply. Thanks Phil <?php require_once('../Connections/phcleani_forms.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) { $insertSQL = sprintf("INSERT INTO applicants (mr, name, address, county, post_code, email, phone, mobile, ni, dob, nationality, employed, hours, `position`, town, transport, reference, contact_number, what_work, reference_2, phone_number_2, keep_details) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['mr'], "text"), GetSQLValueString($_POST['name'], "text"), GetSQLValueString($_POST['address'], "text"), GetSQLValueString($_POST['county'], "text"), GetSQLValueString($_POST['post_code'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['phone'], "int"), GetSQLValueString($_POST['mobile'], "int"), GetSQLValueString($_POST['ni'], "text"), GetSQLValueString($_POST['dob'], "text"), GetSQLValueString($_POST['nationality'], "text"), GetSQLValueString($_POST['employed'], "text"), GetSQLValueString($_POST['hours'], "text"), GetSQLValueString($_POST['position'], "text"), GetSQLValueString($_POST['town'], "text"), GetSQLValueString($_POST['transport'], "text"), GetSQLValueString($_POST['reference'], "text"), GetSQLValueString($_POST['contact_number'], "int"), GetSQLValueString($_POST['what_work'], "text"), GetSQLValueString($_POST['reference_2'], "text"), GetSQLValueString($_POST['phone_number_2'], "int"), GetSQLValueString($_POST['keep_details'], "text")); mysql_select_db($database_phcleani_forms, $phcleani_forms); $Result1 = mysql_query($insertSQL, $phcleani_forms) or die(mysql_error()); $insertGoTo = "thank_you.html"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_phcleani_forms, $phcleani_forms); $query_Recordset1 = "Select * from applicants"; $Recordset1 = mysql_query($query_Recordset1, $phcleani_forms) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); mysql_free_result($Recordset1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/#findComment-1217807 Share on other sites More sharing options...
mikosiko Posted May 19, 2011 Share Posted May 19, 2011 if you do this test: echo "Value : " . intval('01234 56789'); what do you get? Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/#findComment-1217828 Share on other sites More sharing options...
confused_aswell Posted May 20, 2011 Author Share Posted May 20, 2011 Hi I get Value: 1234 This is sort of the numbers I am getting in the database. Does this make sense to you? Thanks Phil Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/#findComment-1217932 Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2011 Share Posted May 20, 2011 Phone numbers are not integers. They are formatted strings consisting of numeric characters and other (optional) separator and formatting characters. Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/#findComment-1217933 Share on other sites More sharing options...
confused_aswell Posted May 20, 2011 Author Share Posted May 20, 2011 HI So, do I need to change the way dreamweaver gives the information to the database then, or is there something else I need to do? Thanks Phil Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/#findComment-1217934 Share on other sites More sharing options...
confused_aswell Posted May 20, 2011 Author Share Posted May 20, 2011 Hi I have changed the GetSQLValueString($_POST['phone'], "int"), GetSQLValueString($_POST['mobile'], "int"), to GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['mobile'], "text"), and it seems to be working now. Thanks for all your help. Phil Quote Link to comment https://forums.phpfreaks.com/topic/236789-database-not-picking-up-the-phone-number-entry/#findComment-1217942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.