473,698 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Posting into a MSSQL Database

5 New Member
I am trying to post values into a mssql database and having some trouble. I create a detail_id in the first query and want to pass this detail_id to several other queries to insert into several other tables. It creates the detail_id in the first table, but doesn't pass it on, when I try to retrieve it. Here is my code:

------------------------------------------------------------------------------------------------------------------
$query1 = "INSERT INTO Detail(date_con tacted, user_id, issue_type, ref_by, contact_type, contact_descr, date_added, time_added)
VALUES '$date_contacte d','$REMOTE_USE R', '$issue_type_id ','$ref _type_id','$typ e_id','$contact _descr','$today ','$time')";

$mssql_result = mssql_query($qu ery1);

$get_id = "SELECT detail_id FROM Detail where issue_type='$is sue_type_id' and ref_by='$ref_ty pe_id'";

$mssql_result = mssql_query($ge t_id);
$row = mssql_fetch_ass oc ($mssql_result) ;
$NewDetail = intval ( $row['detail_id']);
$detail_id=$New Detail;

$query2 = "INSERT INTO Contact(detail_ id, user_id, date_contacted, contact_type, first_name, last_name, address, city, state, zip, email, phone, ext, alt_phone, contacted_by, start_time, end_time, total_time, email_content)

VALUES ($NewDetail, '$REMOTE_USER', '$date_contacte d','$type_id', '$first_name', '$last_name', '$address', '$city', '$state', '$zip', '$email', '$phone', '$ext', '$alt_phone', '$contacted_by_ id', '$start_time', '$end_time', '$total_time', '$email_content ')";

$mssql_result = mssql_query($qu ery2);
-------------------------------------------------------------------------------------------------------------------

The values from the form are going into the database, it just isn't getting the detail_id from the first query and putting into the second table.

Any help would be greatly appreciated!
Jul 27 '07 #1
7 1825
kovik
1,044 Recognized Expert Top Contributor
MySQL has a nifty little function called mysql_insert_id () which gets the primary key value of the last insert statement. Just another reason MySQL is better. :-P

print_r($row) so that you can see if the data is even being retrieved.
Jul 27 '07 #2
ScottieFromNM
5 New Member
MySQL has a nifty little function called mysql_insert_id () which gets the primary key value of the last insert statement. Just another reason MySQL is better. :-P

print_r($row) so that you can see if the data is even being retrieved.

The data is going into the database, it is just not getting the detail_id from the previous query.
Jul 27 '07 #3
kovik
1,044 Recognized Expert Top Contributor
The data is going into the database, it is just not getting the detail_id from the previous query.
I didn't say the data wasn't going in, I'm saying that you might not be getting the data out. That's what $row is. print_r($row) and tell us what the contents are.
Jul 27 '07 #4
ScottieFromNM
5 New Member
I didn't say the data wasn't going in, I'm saying that you might not be getting the data out. That's what $row is. print_r($row) and tell us what the contents are.
I get the following error:
Warning: mssql_fetch_ass oc(): supplied argument is not a valid MS SQL-result resource in /var/www/html/victim/victim_form.php
Jul 30 '07 #5
kovik
1,044 Recognized Expert Top Contributor
I get the following error:
Warning: mssql_fetch_ass oc(): supplied argument is not a valid MS SQL-result resource in /var/www/html/victim/victim_form.php
-_-
What did you change? print_r() only prints data like echo, but prints the elements as well. All I want you to do is get the contents of $row displayed to the screen.
Jul 30 '07 #6
ScottieFromNM
5 New Member
-_-
What did you change? print_r() only prints data like echo, but prints the elements as well. All I want you to do is get the contents of $row displayed to the screen.
Okay get the following:

Array ( [detail_id] => 252 )

This is the same result every time I run the query.
Jul 31 '07 #7
ScottieFromNM
5 New Member
Okay get the following:

Array ( [detail_id] => 252 )

This is the same result every time I run the query.
It is now working. I guess the following line:

$get_id = "SELECT detail_id FROM Detail where issue_type='$is sue_type_id' and ref_by='$ref_ty pe_id'";

The "where" portion of this was causing the problem. Once I commented this out it started working. Thank you for your help on this issue.
Jul 31 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

11
4388
by: badz | last post by:
Hi frenz Lately I try to use MSSQL and PHP , the problem arise when PHP try to read MSSQL field with 'image' data type, header("Content-type: image/jpeg"); // act as a jpg file to browser I try to used normal working file that store BLOB as file type in MSSQL ...but still not working. Is it because the image data type in MSSQL can not be recognise by PHP?
2
1718
by: bigoxygen | last post by:
Hi. I am experiencing problems connecting to MSSQL. I'm not sure where to begin looking for the problem. I don't know if the problem is originating with PHP or MSSQL What should the host name be? When I mouse over MSSQL manager it says "\\S-CIS-0042" $db_host='local'; //IP/host of the database server
3
2197
by: francisl | last post by:
We have to build some script were I work to make a dynamic server inventory. But, the project team, a windows crew, start it all in vbscript and on mssql. Note, due to political reason, we can not use mysql or anyother one that are not *authorize*, it's oracle or mssql. Now we have to make it work also with our sun and HP unix server(plus one Linux). So I propose to use python, and after they see my litle python/wxwindow program, that...
16
1758
by: davemateer | last post by:
Hi We have a current system: Linux / Apache / PHP4.x talking to Microsoft SQL 2000 Thinking about going to: Windows 2003 / PHP4.x talking to the same Microsoft SQL 2000 box...
0
7944
by: m3rajk | last post by:
I've recently become the defacto DBA of two MSSQL databases at work because I am the only one with SQL experience. I have been asked to do some tasks with the databases but this requires and understanding of their structure. I cannot find anything akin to MySQL's mysqldump for mssql and have been looking for that among other help in being able to use my MySQL experience as a base for learning MSSQL. I have spent a few days (8 to 9 hours per day)...
9
5838
by: Advo | last post by:
Im having major problems trying to connect to a mssql database thats hosted on our server. I've got the ip, username, password and database name, yet no matter what i try, I cant seem to connect. I've trawled the net for hours looking for code, has anyone got any that definately works, or just a simple way I can check the connection. Thanks
8
6325
by: php-taz | last post by:
I built a PHP website on Windows 2000 (using IIS) that connects to a SQL Server 2000 database using the mssql functions. I migrated the website and the database onto a Windows 2003 machine, and now the mssql functions are significantly slower. On the Windows 2000 machine, the mssql_connect takes .03 seconds to run, and the odbc_connect takes the same amount of time. On Windows 2003, the mssql_connect takes a full second to run, but...
0
1307
by: LizRickaby | last post by:
My client has several Access databased that they wanted converted into MSSQL to be able to access them online (excuse the pun). I added the first Access database, LenderPrograms, as a table in the MSSQL database with no problem, it runs fine. But when I tried to add the other Access database, LenderContacts, as another table, it doesn't work. When I first import LenderContacts using Enterprise Manager it turns all of the "text" fields into...
4
2343
by: ThePhenix | last post by:
Hi everybody, I have recently been doing a conversion for my boss for a access 2000 database (both front and backend) to a MSSQL backend. I finished the conversion today (as quite a lot of the code / queries ran slow due to access running the queries locally rather than on the server). And tested it on my and my boss's machine with no problems so he gave the go ahead to update everybody to our new mssql 2000 backend with the modified...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.