473,486 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP another mysql_insert_id() not working

JnrJnr
88 New Member
Hi,
I have one database connection
I am using an insert statement
The insert statement inserts successfully
Right after the insert I want the ID of the newest row
My database table has a unique ID and set to auto inc
mysql workbench version is 5.2.34
Expand|Select|Wrap|Line Numbers
  1. $save = mysqli_query($connection,"insert into table (message, title, newdate) values ('$Message', '$itle', CURDATE())");
  2.     $newid =  mysql_insert_id($connection);echo('val is '. $newid);
The value of $newid is always empty or 0
Please help!
Feb 11 '12 #1
2 3105
Joseph Cobham
23 New Member
why don you try some thing of this nature it works perfectly for me

Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT into `table` (`message`,`title`,`newdate`)
  2.     VALUES
  3. ('$message','$title', CURDATE())";
  4.  
  5. mysql_query($query,$connection) or die("Insertion Failed:" . mysql_error());
  6. $newest_id = mysql_insert_id($connection);
and dont forget to escape your query data using mysql_real_escape_string()

If you find any error let me know
Feb 11 '12 #2
Dormilich
8,658 Recognized Expert Moderator Expert
in case you didn’t notice:
Expand|Select|Wrap|Line Numbers
  1.  $save = mysqli_query($connection,"insert into table (message, title, newdate) values ('$Message', '$itle', CURDATE())");
  2. // -----------^ 
  3. $newid = mysql_insert_id($connection);echo('val is '. $newid);
  4. // -----------^ 
Feb 12 '12 #3

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

Similar topics

2
6228
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
6
3047
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
3
3091
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
8
1815
by: Hardy Wang | last post by:
Hi: Is it possible for me to create/open web application from remote machine other than port 80? And create application directly under virtual web site instead of creating a virtual directory?...
4
1615
by: GP | last post by:
We are facing a strange problems everything works fine when we are using the visual studio environment .But when we deploy it in the webserver the save buttons/submit buttons which has the cause...
5
2789
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
3041
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
2491
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
14809
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
3181
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
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,...
0
7175
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...
1
6842
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...
0
7319
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
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...
0
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
598
muto222
php
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.