Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP






SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





PHP-MySQL: Returning ID When New Record Is Made?


Let's say I create a new record in a table like this:
mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn);

....that had an auto-incrementing, unique identifying column named "ID"
that would be populated with a unique number upon insertion...

How can I get the unique number it assigned to that record returned for
futher use?




View Complete Forum Thread with Replies
Sponsored Links:

Related Messages:
ID Of Record Not Returning ?
The following code returns the fields from the row ( $product for example is used later and displays OK ) except the 'prid' field ( only ever has zero), which is the unique ID for this table.
Any thoughts appreciated - PHP Code:

View Replies !   View Related
Returning 1 Instance Of A Record
The subject might sound a bit weird but Im having trouble describing my problem, basically I have a database with following fields prodId, prodMan, prodItem For example say I have in the DB:

1, Man 1, ProdItem1
2, Man 1, ProdItem2
3, Man 1, ProdItem3
4, Man 2, ProdItem4
5, Man 2, ProdItem5
6, Man 3, ProdItem6
7, Man 3, ProdItem7.

View Replies !   View Related
How To Securely Store A Record Index When Editing A Mysql Record
is there a secure way
to do this? the non-secure ways are, as i understand it, to populate
a listbox with indices as names, or maybe use a hidden control. is the
only secure way with sessions? i was also thinking about perhaps
creating a meta table that says who is editing which record right
now. any advice?

View Replies !   View Related
Problem With Shopping Cart Made From Mysql
I'm writing a basic shopping cart function in php. I've created a databse in mysql containing a user, a cart and a book among other things. I've used the following function to create a cookie Code:

View Replies !   View Related
Returning 1 Result From MySQL
I know the usual way of receiving results from MySQL, useing a while loop e.g.

$sql = "SELECT * FROM users WHERE email='joe@hotmail.com'";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($result)){
echo $row["firstname"];
echo $row["lastname"];
echo $row["email"];}

BUT, if I know they only 1 result is going to be returned, is there a way to do this without using a while loop? So if I only wanted to get only the firstname of the person with email joe@hotmail.com. can I do this without a while loop or do I have to use one?

View Replies !   View Related
Mysql- Returning First 200 Characters?
how do i return the first x amount of characters from a field in a mysql database?

View Replies !   View Related
Mysql- Returning First 'x' Characters
how do i return the first x amount of characters from a field in a mysql database?

View Replies !   View Related
MySQL Not Returning Results
I'm using mySQL to retrieve one row of results. The row is already in the database named 'reviews' and the database is running fine (phpbb works perfectly). So no problems there.

So, it must be a problem with the code. But what's wrong with this code that it won't return any results? It's not a php error (I get the page layout, it's embedded in HTML that I have omitted). Code:

View Replies !   View Related
MySQL Query Not Returning All Results
I have a user table in the DB, for example:

+---------+----------------+-------------------+
|     uid     |     username     |       firstname       |
|----------+----------------+------------------+
|       1     |       cobby        |       Andrew          |
|       2     |       admini        |     test-account    |
+---------+-----------------+------------------+

If, in phpMyAdmin, I query:
   SELECT `username` FROM `users`;

It will return results correctly (cobby and admini, respectively).
But if I make a simple PHP script, such as:

<?php

mysql_connect('localhost', 'cobby', 'dbpass');
mysql_select_db('testdb');

$query  = mysql_query('SELECT `username` FROM `users`');
print_r(mysql_fetch_assoc($query));

?>

It only returns:
Array ( [username] => admini )

Why does it only return the second result? I have a feeling I'm doing something really silly, but I looked over this test script and its got me stumped.

View Replies !   View Related
Returning The Results Of Two MySQL Inserts
How can I return the result of two MySQL inserts? When a new user register on the website, his info is inserted into a table, and his custom picture is inserted into a different table. Code:

View Replies !   View Related
Mysql Query Returning Incorrectly
The following MySql Query is not retuning correctly. It is returning dates outside the given range. Why? Code:

SELECT distinct
sale_type_landsale.sale_type_landsale_id
,sale_type_landsale.sale_date,sale_type_landsale.city,sale_type_landsale.name,sale_type_landsale.sale_price,sale_type_landsale.number_lots
FROM
sale_type_landsale
Left Outer Join connector_sale ON sale_type_landsale.sale_type_landsale_id = connector_sale.ref_id
Left Outer Join sale ON connector_sale.sale_id = sale.sale_id
Where
sale_type_landsale.sale_date >= &#55614;&#57158;-01-01'
AND sale_type_landsale.sale_date <= &#55614;&#57159;-06-08'
AND sale_type_landsale.city =&#394;'
OR sale_type_landsale.city =&#3913;'
AND connector_sale.ref = 'sale_type_landsale'
AND sale.sale_archive <> 1

View Replies !   View Related
Mysql Joins Returning Null
I dont know how to explain it so ill show you the code

$select=$q("SELECT UserExp.CrimeExp, User.Nerve,  CrimeList.ExpNeeded, CrimeList.ExpGain, CrimeList.ExpLoss, CrimeType.Nerve FROM UserExp,User,CrimeList,CrimeType
where CrimeList.CrimeID=CrimeType.ID AND CrimeType.ID='$_GET[type]'")or die(mysql_error());
$select=mysql_fetch_array($select);
$Test=$select[User.Nerve];
$Test2=$select[CrimeType.Nerve];
echo("Test: $Test Test2: $Test2 ");
if($select[User.Nerve]<$select[CrimeType.Nerve]){
Basicly there both returning null, any advice in getting around this problem

View Replies !   View Related
Returning An Array Indexed By Numbers With MySql
Anyone know how to get an array indexed by numbers (i.e. - NON - Associative)? Seems like it should be able to be done with a function - but I haven't been able to find one.

View Replies !   View Related
MySQL Query Returning Empty Column
Here's my code:

$query_get_machine = sprintf("SELECT machines.ID, machines.NotifyID, machines.Name, notify.ID, notify.`Data` FROM machines RIGHT JOIN notify ON machines.notifyID = notify.ID WHERE machines.ID = %s", GetSQLValueString($colname_get_machine, "int"));

Can anyone tell why the notify.`Data` column might be returned empty? All others display as they should.

View Replies !   View Related
Code Returning False Mysql Result
I'm working on code which will allow users to "rate" something, for instance, on a scale of 1-5. When they click on a star (1-5), it sends them to the following PHP script, with ?rid=&rating=

rid is the id of the item they are rating, and rating is the integer 1, 2, 3, 4, or 5. Problem is... even with an empty db table, it returns "Rating added successfully." - but doesn't add anything. If I add a row with uid=1 rid=2 and rating=3, and am logged in as uid=1, it still says "Rating added successfully.", and does nothing. It SHOULD HAVE updated the existing row and told me so. Code:

View Replies !   View Related
Returning Result Set (many Rows) From MySQL Stored Procedure
I have a MySql stored procedure that simply runs a SELECT that will return multiple rows. I'm calling it using PEAR::Db->query. I get an error return:

[nativecode=1312 ** PROCEDURE neighborhoodserver.proc_Get_available can't return a result set in the given context]'

If I simply execute the SELECT statement through 'Db->query', it works fine. If I call the stored procedure from the command line, it works fine.

What am I missing?

View Replies !   View Related
MySQL Query Not Returning Values Based On Date Correctly
I am trying to use a MySQL query that searches the database and only returns results during a specific time frame. And it is giving me articles that are not correct. Code:

View Replies !   View Related
Returning NULL Vs. Returning FALSE
It seems to be a generally adopted convention to have a function return FALSE in case of an error. But if a function is supposed to return a boolean anyway, one cannot distinguish anymore between the "normal" FALSE and the "error" FALSE. So why not using NULL instead to indicate an error? Are there drawbacks I am not aware of?

View Replies !   View Related
Getting One Record From MySQL
I am very new to php-mysql, and im a bit confused by all the tutorials which explain how to get records from mysql. In all the tutorials, they show how to recover all records from a table using a loop command.

I have a mySQL table called news, which has headline and a body fields (as well as id). On my php page, i have two seperate tables. One I wish to print the info from one of the headline fields , and the info from the field body in the other.

I don't wish to print all the records.

View Replies !   View Related
Add Record To Mysql Via Php
I am using Yahoo hosting. When I run my script, I get error on line 16, which is

@ $db = mysql_pconnect(,'nitmal','xcxcxcxcx');

Should there be a parameter I need to pass before user name.

View Replies !   View Related
MySQL Next Record
Is there any easy way to see if there is a next or previous record in a MySQL table without looping through all the records? If I select a row, can I ask if there is a row before and/or after that row.

View Replies !   View Related
Best Way To Update A Mysql Record
I have a small app that a user can select an entry to be considered as "cancelled". This will change an entry in a mysql database.

Is there someway of making a button that as soon as its clicked, sends the appropriate update info to the database and reloads the page?

View Replies !   View Related
Please Help With A Record Problem With MySql
I have php code that enters information into a mysql database. How can I make it so that the person entering the information has the choice for the listing to expire after a given number of days. Therefore I would like the record to become not active after this period.

View Replies !   View Related
Deleting Record From Mysql
I am just tring to delete on record based on a link generated. The link shows up, the number of the field is shown as deleted when the link is clicked, but the entry ios still in the db. Maybe a problem with how I have the db setup? I only have one field, add_manufacturers, and it is text. It is in a table called manufacturers. Code:

View Replies !   View Related
Accesing A Record In MySQL And PHP
I am accesing a record in a MySQL DB with the a sentence embeded in a
php code. The result access a page like:

http://www.mysite.com/page.php?id=16

where the id=16 indicates the id of the result. This work perfect, but
I don´t want the user to know that the number 16 correspond to a
specified record. I´d like to change the 16 for an algoritm. The
algoritm result will be 16, but this will be only know by the database.

As example, I´d like that

http://www.mysite.com/page.php?id=ewrefj34239dsa

equals

http://www.mysite.com/page.php?id=16

View Replies !   View Related
UPDATE A Record In MYSQL DB With PHP
What is the best way to update a record in a MYSQL DB using a FORM and PHP
?
Where ID = $ID !

Any examples or URLS ?

View Replies !   View Related
Getting The Last INSERTed Record From Mysql
I remember reading about a function that will get the last inserted mysql record, but I don't recall if this is a php or mysql function. What is the name of the function?

View Replies !   View Related
Record Expire PHP / MySQL
I created a database that lets people post a job opening. I thought of
manually removing each entry after 2 months, but is there some code that
can do this without me having to monitor the table?

View Replies !   View Related
Adding Record To A MYSQL DB Using PHP ?
What is the best way to add a new record to a MYSQL DB using a FORM and PHP
?
Any examples or URLS ?

View Replies !   View Related
Edit Mysql Record
I want to use a userform on a webpage so members can edit their data.

Displaying the data on the form isn't the problem.
But when members change their data how do i save then new data in their
record. I dont want a new record.

View Replies !   View Related
Mysql Delete Record
when I run this code below it doesn't delete the record or display any error message

$id = $_GET['id'];
include("../dbconnect.php");
mysql_query("DELETE FROM promotions WHERE id='$id'") or die(mysql_error());

Such a simple thing to do but I don't no why it doesn't work 

View Replies !   View Related
Not Updating Record Into MySQL
I am attemting to update a MySQL record and after I hit the submit button from the update form  I get a blank white page. I have error reporting on, but still nothing. Code:

View Replies !   View Related
Finding A Mysql Record
So when a client came to me and asked if I could create a website that would allow users to search the traceability details of his products, I rose to the challenge and said yes.

Let me exlpain further: The client produces a fish product, and has a simple (one table) database, with about 5 or 6 fields, that give details about the harvesting dates, the geographic origin, the batch number, etc. for each batch of fish.

I managed to create the table in a mySql database using phpMyAdmin. I also managed to create a set of "out-of-the-box" user admin tools for the client, by installing a free script (phpMyEdit I think). Code:

View Replies !   View Related
Add A Record Into My Mysql Database
I have the following code to add a record into my mysql database: Code:

View Replies !   View Related
Inserting Record Into Mysql
If someone goes to mypage1.php and their ip address is already in my mysql database, how can I find that record and update the "status" field so it says "Yes"?

View Replies !   View Related
Mysql Record On Page
I'm trying to link to a specific record from one page to another. Let me try to explane:
I have a homepage with some of the records of the latest news table + a link to "read more". I have the news page with all of the records of the latest news table Now when I click the read more link on the homepage I want to go to that specific record on the news page. I've tried to use

printf ("<a href='http://www.crivic.com/latest_news/index.php?id=$rij[id]'>(read more...)</a>");

View Replies !   View Related
How To Duplicate Record In Mysql
Is there a simple select or subselect statemet that will duplicate a record from within a table.

I tried some thing like this insert into howto select * from howto where howto_id=31;

I think I am running into a problem because the howto_id is my primary key. Is there someway of doing this, simple.

I could do it with PHP by calling that record and storing the variables and then inserting without the howto_id, but that seems expensive. Seems like there should be a simple sql statement to accomplish copying a record within your table.

View Replies !   View Related
Updating A Record In A MySQL DB
Maybe this is where i am going wrong, but I am using dreamweaver for this form. Right, made a form to insert a record into a mysql db. this works fine, no problem here.

I then copied this form, and then modified it to an update form. The main difference is that that form text boxes are pre-populated from the database, thus allowing easy modifications. however, the box where I browse for the image is empty Code:

View Replies !   View Related
Updating A Record In A Mysql Database
I am sorry if this is a simple oversight, but I have been struggling for many hours over something which seems dead simple.

I need to update a record in a table with more info. I am using the code below which soen't give me any errors but nothing happens.

include("link.inc");
$db=connect_db();
$db_name=db_name();
mysql_select_db($db_name,$db);

$sql="UPDATE data SET age='age',live='live',whatdo='whatdo',drinkalcohol='drinkalcohol',takedrugs='takedrugs',firstdrug='f irstdrug',seconddrug='seconddrug',medicine='medicine',alcohol='alcohol' WHERE id='$id'";
$result=mysql_query($sql,$db);

View Replies !   View Related
Output Xml File From Mysql Record
how to get the record from databse directly..but now my application require me to output my record as xml output....so I really need help on it.../some guide ...this is what's my xml gonna be.. Code:

View Replies !   View Related
Check Duplicate Record In Mysql
I am trying to make sure that I do not insert a duplicate record in the database.  Here is my code:

View Replies !   View Related
Applying A Class To The First And Last MySQL Record
I need to apply a class to the first and last records from a MySQL query. What I'm trying to do is pull the menus for my site but the first and last links need a class name for the design. I can't set them in the database because the order and items in the menu will change from time to time.

so, here is how I pull my menu (cut down for this post). You can see it just grabs the name, url and makes a link. How would I apply a class to the first and last records?

mysql_connect("localhost","root","password");
mysql_select_db("my_site");
$result = mysql_query("SELECT * FROM menu ORDER BY id");

while ($are=mysql_fetch_array($result))
{
$name = $are['name'];
$url = $are['url'];

print '<a href="'.$url.'">'.$name.'</a>'."
";
}

View Replies !   View Related
Select SECOND Top Record In Table + Mysql
how to get second hightest record in table is there posible in mysql

View Replies !   View Related
Inserting Unique Record MySQL
Are you able to check if a record that you are about to insert into one table isnt already located in another table? Obviously I can do a select query and check that way, however I am inserting multiple values in one statement and this is not efficient. The column is called "URL" in both tables and they are both set to unique. Can I somehow check if the value I am inserting is unique to both tables?

View Replies !   View Related
Checking For Existing Record In MYSQL
I've got a mysql database with a single table. I also have a page containing a FORM with a number of fields that once submitted is stored into the database.

My problem is, users are able store the same information more than once. How do i check if that record already exists before inserting into mysql table?

For example, I want to check that, that particular username, nickname and email exists in the table. If it does, print out a warning. If it doesnt exist, go ahead and perform the query and insert the record.

View Replies !   View Related
Return Record Ranking Of A Mysql Table
I have a table consisting of names, and registration dates. I query the db "select * from users order by regdate" I want do another query for a particular user, I am looking for the script to say: user is row 15 of 30.

View Replies !   View Related
Deleting A MYSQL Record From Within An Html Form
Just rebuilt an admin tool in PHP (originally built in asp) for a news section of a site.
The problem is: My delete records php page is set out in an html form, with each news story expressed with a checkbox. normally i'd put a <a href="delete.php?id=<? echo $row->id; ?> </a> alongside the record, but i need to have it work in a form.

What action should the form have, and how do i get the form to process the deletion process with the correct news story checkbox selected?

View Replies !   View Related
MySQL Php Record And Refresh What Url Current Visitor Is Seeing
I need code examples where I can have php record and refresh what url
a list of current visitors are seeing in an iframe and list it in
fields below, does anyone have code that would help me to accomplish this?

View Replies !   View Related
Mysql: Return A Record That Doesn't Contain Multiple Values?
This code doesn't appear to work :

$q = 'SELECT ident, type, question, option1, option2, option3, option4, answer, stage
FROM data
WHERE type="test" AND ident!="'.$usedids.'"
ORDER BY RAND()
LIMIT 1'

Now $usedids is simply "125,54,56,36" etc. Basically I am trying to put together a quiz. Now I am trying to get it to select a random question from the database. The hard part comes is not showing that question again.

Once a question is displayed I am storing it in an array. Each time a question is displayed it is being added to the array. What I am trying to get it to do, is every time it selects a question it should pick one in $usedids(which is now a comma sepreated string".

View Replies !   View Related
Automatic Mysql Record Trigger Program
does anyone know of a "product" that monitors mysql inserts/deletes etc, and can trigger an event based on them? For instance, i have a database that is currenlty being used to track attempts at authentication. What i would like to do it trigger an email when the database see's an insert for a particular event.

View Replies !   View Related
Deleting A Mysql Record In Active Result
I'm doing a select in wich I retrieve some values. If the value is in an array, I must delete the record. As I'm doing a "mysql_fetch_object", may I delete this record inside the loop ?

when doing a mysql_query, do I have a "local" copy or just a link to the mysql query result. In the first case I may delete the record as I get an "image" of the query result, in the second case I shouldn't as the query result will be changed by the deletion of any record.

View Replies !   View Related
Script Repeat Updates The Record And Also Inserts Another Record With The Same Information.
I have a form which contains some fields that are populated with data from a table. This same form also has fields that are empty because the data has not been collected yet. The main table is called client with a primary key of client_id. What I need to do with this form is select the client and update the record into a new table with the missing information. If the client doesn't not exist in this second table, I need to insert the row otherwise if the client does exist in this table because of a previous update, update the record.

When I run my script, the insert works. When I try to run the script again and try to update the record, the script not only updates the record but also inserts another record with the same information. How can I write my script so it checks whether a client exists in a table and if it does, update the record and if the client does not exist in the table, add the client?

View Replies !   View Related

Copyright © 2005-08 www.BigResource.com, All rights reserved