PDA

View Full Version : Create online Contract - mysql query


newphp
05-24-2011, 07:45 PM
Hi all,

I'm new here at the forum and also a new dreamweaver user, and hope you can help me out with this issue.
I'm trying to create a part on my website where the logged in user fills in a form and after clicking a "create contract" button it genarates an online contract where the fileds get data from mysql table.
After some online research I've found out that I have to work with recordsets and sessions, but I cant get it work .... here is what I heve untill now...

1) created a php form (my page 1) to post the data, in this form I created only an insert record server behavior
2) created a contract page (second page), where I set up a session variable as follow

<?php session_start(); session_register("sess_id"); $sess_id = $HTTP_POST_VARS['id']; ?>

where "id" is the autoincrement field filled in with my page 1 post.

Then I inserted a session variable, and named it "sess_id", the same as I named in the session_start, and draged it into my code.
<?php echo $_SESSION['sess_id']; ?>

Then I created a recordset, and in the filter I choose "id" = session variable "id" (also tried as session variable "sess_id", since I dont know if I was supposed to just leave the field or the session name), and in the bindings window I draged the fields into the respective cells.

But is still not working ! now I'm getting this messages...
( ! ) Deprecated: Function session_register() is deprecated in C:\wamp\www\contratos\contrato_ts_session.php on line 2

( ! ) Deprecated: Function session_register() is deprecated in C:\wamp\www\contratos\contrato_ts_session.php on line 2Call Stack#TimeMemoryFunctionLocation10.0013733024{main }( )..\contrato_ts_session.php:0( ! ) Notice: Undefined variable: HTTP_POST_VARS in C:\wamp\www\contratos\contrato_ts_session.php on line 2
( ! ) Notice: Undefined variable: HTTP_POST_VARS in C:\wamp\www\contratos\contrato_ts_session.php on line 2Call Stack#TimeMemoryFunctionLocation10.0013733024{main }( )..\contrato_ts_session.php:0


Can anyone please help with this ? What am I doing wrong?

Follow the whole php code

<?php require_once('Connections/locaweb.php'); ?>
<?php session_start(); session_register("sess_id"); $sess_id = $HTTP_POST_VARS['id']; ?>
<?php echo $_SESSION['sess_id']; ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
$colname_Recordset1 = "-1";
if (isset($_SESSION['sess_id'])) {
$colname_Recordset1 = $_SESSION['sess_id'];
}
mysql_select_db($database_locaweb, $locaweb);
$query_Recordset1 = sprintf("SELECT * FROM dados_contrato WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $locaweb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);


?>tks in advance!

edbr
05-25-2011, 02:12 AM
<?php session_start(); session_register("sess_id"); $sess_id = $HTTP_POST_VARS['id']; ?> with just
session_start(); and make it the first item should do it

newphp
05-25-2011, 05:03 PM
Thanks for your reply Edbr!
Actually, I realized that as soon as I set the user login and the restrict access to the page I already have a session as follow
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
Then I believe that I dont have to set up any other session, correct?
However, when I create the recordset and draged the fields into the cells I got this 2 scenarios:
1) If I set the "filter to id = session variable id ", I dont get any results, i have a blank field
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
$colname_Recordset1 = "-1";
if (isset($_SESSION['id'])) {
$colname_Recordset1 = $_SESSION['id'];
}
mysql_select_db($database_locaweb, $locaweb);
$query_Recordset1 = sprintf("SELECT * FROM dados_contrato WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $locaweb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>2) If I dont set up any filter I got some result, but not the last one tha I'd inserted

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
mysql_select_db($database_locaweb, $locaweb);
$query_Recordset1 = "SELECT * FROM dados_contrato";
$Recordset1 = mysql_query($query_Recordset1, $locaweb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>What I'm I doing wrong ?

tks

gentleone
05-25-2011, 08:07 PM
Newphp, please wrap your posted code between php tags. It's an icon in the menu from the advanced editor.
Its much easier to read like this, don't you think so? ;)

newphp
05-25-2011, 08:56 PM
Sorry gentleone...tks for the tip... follow again my post with the quotes...

Thanks for your reply Edbr!
Actually, I realized that as soon as I set the user login and the restrict access to the page I already have a session as follow
//initialize the session
if (!isset($_SESSION)) {
session_start();
}


Then I believe that I dont have to set up any other session, correct?
However, when I create the recordset and draged the fields into the cells I got this 2 scenarios:
1) If I set the "filter to id = session variable id ", I dont get any results, i have a blank field

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
$colname_Recordset1 = "-1";
if (isset($_SESSION['id'])) {
$colname_Recordset1 = $_SESSION['id'];
}
mysql_select_db($database_locaweb, $locaweb);
$query_Recordset1 = sprintf("SELECT * FROM dados_contrato WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $locaweb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

2) If I dont set up any filter I got some result, but not the last one tha I'd inserted

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
mysql_select_db($database_locaweb, $locaweb);
$query_Recordset1 = "SELECT * FROM dados_contrato";
$Recordset1 = mysql_query($query_Recordset1, $locaweb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

edbr
05-26-2011, 02:01 AM
echo $_SESSION['id']; and see what you get

newphp
05-26-2011, 03:38 AM
echo $_SESSION['id']; and see what you get
where should I put the echo ? Should I use option number 1, 2 or none? :confused:

edbr
05-26-2011, 04:40 AM
just add it to your page after the session start. it will show if a value is being passed

newphp
05-26-2011, 06:23 AM
//initialize the session
if (!isset($_SESSION)) {
session_start();
echo $_SESSION['id'];

}

If I dont use the ID filter when creating a recordset I still get any record, not the previous form input.
If i dont use the filter I still get nothing

edbr
05-26-2011, 06:35 AM
no i didnt expain very well


if (!isset($_SESSION)) {
session_start();

} echo $_SESSION['id'];


this should ech the actual value thats been passed

newphp
05-26-2011, 09:13 PM
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
echo $_SESSION['id'];

Right?
I got this message, and also: still if I set up the filter still getting the wrong data, and If I leave it without filter still get nothing

Notice: Undefined index: id in C:\wamp\www\contrato_ts\teste.php on line 9Call Stack#TimeMemoryFunctionLocation10.0011714712{main }( )..\teste.php:0

newphp
05-26-2011, 10:27 PM
Sorry... I just realized that the problem might be at my recordset field
In the cells that I need the data to be retrieve this is the conde

<?php echo $row_Recordset1['p_nome']; ?>

newphp
05-30-2011, 05:16 PM
hey guys, any idea? :confused:

newphp
06-05-2011, 09:11 PM
does any one can, please, help with this matter? does anyone has an example to send me ?

tks