Jump to content

Help me code


mrcarmine

Recommended Posts

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

<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

<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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.