Jump to content

Recommended Posts

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? :shrug:

 

So any help here would be appreciated.

 

Thanks in advance

 

Phil

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.

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);
?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.