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.





Insert/select From Same Page


I was wondering (and I suspect I already know the answer) if it's possible to insert data into a mysql table and select that same data from within the same php page.




View Complete Forum Thread with Replies

Related Forum Messages:
Select And Insert
I've been reading php.net but still kind of lost. This is what I want to do..I have two database (maindb and seconddb). I want to transfer the username from maindb to seconddb. How would I do that? I understand it's just selecting the maindb and insert it in the seconddb.

I just don't understand how to write the syntax. Do I have to do a mysql connect also? What goes into: mysql_query("INSERT INTO mytable (product) values ('kossu')");? I'm trying to do a phpbb integrate with my site. If my site's password is not encrypted, will that cause any issues transfering it to phpbb's password since phpbb is encrypted. Code:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('maindb');

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d
", mysql_insert_id());
?>

View Replies !
Insert/Select
I have a 10 column table tracking stats for 10,000+ songs using statements such as "playcounter=playcounter + 1".

DAILY_STATS (condensed version)
stat_date - PRI KEY
songid - PRI KEY
plays
downloads.

Every night a cron will INSERT/SELECT this into an identical table called WEEKLY STATS. What's the best strategy for resetting the first table? If I TRUNCATE it then I have to use conditions all day to decide INSERT or UPDATE. I could TRUNCATE and then refill it with only the songids (10k+), or I could leave all rows intact and set the other columns to "".

View Replies !
SELECT, INSERT, UPDATE
On this project I have got 2 items a mobile and simcard, these are in one table as two records and have a unique equid each. the simcard is also in another table called siminfo and has a parentid (which is the same equid as the mobile) to create the link. In the equipment table there is also userid

I already have code that transfers these items individually, but i want to be able to transfer them both when i transfer the sim card. I currently have the followin but its not working for some reason. the variable $equid does work i have tested it. This code is not picking up the simparentid though Code:

View Replies !
Sql Statment INSERT INTO ....SELECT
I've been trying to copy data from one database to antother using the INSERT INTO ...SELECT statement. But for some reason it doesn't copy the data.....

View Replies !
SELECT ... INSERT Statement
I am trying to write a query to duplicate an order in our eCommerce application here. I could have sworn I wrote a query JUST like this before and it worked, but for some reason this is not working. My query looks like this: Code:

SELECT 1141139101, orig_cart_ordr_hdr.ordr_po_num, orig_cart_ordr_hdr.ordr_requested_date ...
FROM cart_ordr_hdr AS orig_cart_ordr_hdr
WHERE orig_cart_ordr_hdr.ordr_id=33
INSERT INTO cart_ordr_hdr (ordr_received_on, ordr_po_num, ordr_requested_date, ...)

There are about 50 fields in the query, but I just listed a few in my snippet of the query here. We're running MySQL 4.1.7 on this server. Any ideas?

View Replies !
Select And Insert Data
Can't I select and insert data into the same table in PHP?

$SQL = "INSERT INTO c (name, prices, prices2, del, loc) SELECT D.name, D.prices, D.prices2, D.del, 7777777 FROM c D WHERE D.loc = '". $_POST['txtCopyFrom'] ."'";

View Replies !
Sql Problem Select Then INsert
I tried to select then insert but I got error in this line $row=mysql_fetch_array($result); . Anyone have any comment !!!

$sql="Select * form PC where CountryID='$CountryID' and PostalCodeID='$code'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$Myvalue =$row["CountryPostalCodeID"];

$sql="INSERT INTO `AR` (Postal) VALUES ('$code') where CountryPostalCodeID='$Myvalue' ";
$result=mysql_query($sql);
If($result)
{
echo "OK";
}

View Replies !
Insert A Page Break For Printing Purposes After X Records On Page.
I need to insert a page break for printing purposes after X records on page. I'm querying five diffrent records with 5 different results and displaying them like:

$record1
$record2
$record3 and so on

So I want to get total number of records which is pretty easy I just add all the totals let's call it $subtotal. Then I want a page break after every 20 records of the $subtotal. Is this possible?

View Replies !
MySQL: Insert...select - Update?
I was reading about insert select
http://dev.mysql.com/doc/mysql/en/insert-select.html

Thought this may be a better way to perform a query I'm doing. The differenc is that I need td select from one field, and then update another field in the same record (it is a backup/undo field).

Is there a way to do this in one query? It's a large chunk of data (longtext) so I thought this would be faster than the alternative...

View Replies !
Insert And Select Images (BLOB) From DB2 Using PHP?
DOes anybody have a working example of how do make this work?

I've tried everything I could find, Clara patch, many non-working
examples using pack, baseencode, addslashes, str_replace, bin2hex,
hex2bin, for read only, using different db2 dataypes blob,clob
etc.....I'd post code but I've tried too many to list. just an example
would be excellent.
I've been trying 2 days now.

I know there is a php bug report 25118 http://bugs.php.net/bug.php?id=25118

If I use the DB2 datatype of clob, I can get the insert to work (at
least not produce errors), but getting anything useful back out is
pointless. It seems I can only retrieve 4k of crap (or mabey the insert
only put 4k there). I can read the thing back to a file and look at it,
the first 4k of stuff matches what I input (in this case a 26k jpeg
file), but after that it looks just like random crap including some php
code (pretty funny), so it appears to be padding the file to the proper
length with junk.

datatype of blob produces error on the insert no matter what I try

Any working examples out there? Please please...I really could use some
sleep.

PS, storing on filesystem and putting pointers in DB is not an option in
this case.

View Replies !
Writing An INSERT ... SELECT Statement
I have used this same format of an INSERT ... SELECT statment many times, and once again I'm trying to use it to creat a copy of an order. However, this query is not working on the live site. It works just fine when I run it on my machine and on another server though of course. Code:

View Replies !
Insert Data From Multiple Select List
Am trying to insert data into a mysql database from a multiple select list. How would i do this? Code:

View Replies !
Quickest Method To SELECT And INSERT With OOPS?
When selecting and inserting data into a MySQL dB, I have to create the select and insert PHP scripts that are unique to the table.

I think it is possible to create a generic select and insert PHP script that would work with any table correct? This generic script could be coded in an object model (OOPS) with classes and functions?

View Replies !
INSERT/SELECT With Differing Column Count
I just need a little help with an INSERT statement. I have 2 tables, one for confirmed users and one for temporary. I'm using an INSERT query to transfer data between the 2 once a user validates their registration by Email: Code:

View Replies !
Page Control - Next/previous Or Select Page Number
I'm looking for php script examples that will help me control page layout. Using a table with 12,000 records, would like to be able to display only 5 records per page with page controls at the bottom of the page. The bottom edge would have next/previous or an optional insert desired page number.

View Replies !
Multi Table Insert Delete Select Function Needed.
I am going nuts here and I know with all the functions out there, there must be an easier way to do this. Maybe someone can point me to the right tutorial or even show me how to do this.

I have a $main_id and many $sub_id tables and like to “SELECT to view” INSERT and DELETE those. UPDATE must not be but would be nice.
Here is how it looks:

View Replies !
Insert Page Into Template
I have a script that uses a template for my site. I am trying to add a page(s) to it and have the pages use the template. The template has an area where I want the contents of my other page to appear. The other parts of the script use this PHP Code:

View Replies !
Insert A Page Break
I have a for statement that looks something like this: PHP Code:

for ($i = 1; $i <= 100; $i++) {
        
        echo '<a href="someurl.php?p=$i">Link</a>&nbsp;|&nbsp;'

}

I'd like to put in a <BR> tag after every multiple of 10. I've tried to use a nested for statement, but I just get errors. I don't think I'm doing it right.

View Replies !
How To Insert Tab In An Html Page???
i am making one appllication inwhich the user enters text in textarea field. i am saving this value in database and when user accesses value from database, i want to display text in a format entered by user.

i.e. if the user has entered some text in 2nd line then it should be displayed on second line and not after the end of first line in continuation. if user has entered tab in some location, the tab will be displayed while viewing data from database.

View Replies !
OOP Page: Where To Put Update, Insert, Delete
I have a page that shows info from MySQL. It is for an online education
site. It uses different classes arranged in a hierarchy. Each lesson is
roughly laid out like this:

Lesson
|-Intro
|
|-Section
| |-Procedure
| |-text, video, images
|
|-Section
| |-Procedure
| |-text, video, images
|
|-Summary

I have all the classes working properly for displaying info from the
database. Now I am building the admin site.

Where should I put the update/insert/delete code? Would those go inside the
classes? Should I use the lesson object when doing the maintenance? Or,
should I just have a separate page that handles the database stuff and only
use the objects to display the data from the database?

View Replies !
INSERT Data On Page Load?
I have an avatar system where certain avatars are locked until the user unlocks them by going to certain pages of the site.

So far ( being the newb I am ) I only know how to INSERT data from a form. Is there a way to do it on page load or similar?

I also need it to first check if the data already exists and if not it inserts the data and then displays a message to the user that they have unlocked the avatar. Code:

View Replies !
Traverse And Insert Page Breaks?
My website is going to host various and future pieces of my writing. Some of the pieces are going to be very long, so I need to split them up over multiple pages. I have an input form through which I can type or paste a piece of writing and have it inserted into MySQL. What I need now is to have PHP automatically insert page breaks before the piece is inserted.

I was told I could use regular expressions, or I could use PHP to traverse the string and insert a page break, say, after 1400 characters so long as it ends on a period.

I know of str_replace, but how do I set it go a certain amount of characters? This whole pagination thing has me completely stumped. I'm not looking to paginate display results. I'm displaying one result split up in pages.

View Replies !
Insert To Database On Page Load
I have the code for inserting data to a database form a form (Code below) but I want the data to be entered upon a page loading, how would I do this? Code:

View Replies !
Refeshing Page Duplicate Insert
I am creating a registration script for my site and it is posted to itself. The problem is that when all the information is inserted into the database and i display what you have inserted, like username and email etc.

If i refresh the page then it tries to insert it all again flashing up a dublicate entry message. How can i get around this? I thought of a redirect but would prefere not to.

View Replies !
How To Simply Display On My Page Another Insert From A Different Table.
$judet = $_GET["judet"];

$result = mysql_query ("SELECT oras, id_oras FROM orase WHERE id_oras = '{$judet}' ORDER BY oras");

This is a piece of my code. The variable $judet is working perfect but i have a problem with another variable in the same table with judet witch i can't call.Everything from table orase works i just don't know how to simply display on my page another insert from a different table.

View Replies !
Howto Insert Picture Stored In Directory With Url In Db Onto Web Page?
If I read one tutorial more on how to store a image inside a mysql database I will blow my mind.

I read everywhere on the forums to store the image on the harddrive and use the url in the database and then pull the image out of the directory and onto a web page.

I am new to PHP and mysql but have looked now for two weeks on how to code a page to do this. It really has to be simple, so simple no one has taken the time to write a tutorial on it. There are lots, many, plenty, please no more tutorials on using BLOB to store an image inside a database.

What is the code to pull a image from a dir. using a url in the db and put it on a web page, I have been trying my own ideas and not working....NO I don't want to use BLOB.

darn thing with php, you can't see the code that does the trick...all I can see is the std <img scr="blab,blab,blab">

View Replies !
Stopping Another Data Insert When User Reloads Page
My PHP script inserts data into a mysql table that has been passed into it.

My question is, what is the general method by which to ensure that if a user reloads the screen, the same set of data doesn't get duplicated into the database?

For instance, I am inserting ticket data (its an ecommerce event system) into a mysql and really dont want duplicated entries if the user happens to press reload or back or whatever

Any ideas?

View Replies !
Multi Page Form Question Concerning $id = Mysql Insert Id();
I am creating a multi page form. The code below is what I am using. However, I am having a difficult time having it post to MySQL under "pg2" where it posts to MySQL I have the function $id = mysql_insert_id(); to post the id from "pg1" post to the database. However it only post 0 which I think is due to it being in an array. Code:

View Replies !
Txt Or Pdf File And Select Page
Is is posible in php to have a txt file or a PDF file loaded in to a webpage and have it select the page that is wanted, i.e. have an index thing with links. so when i click on a link it loads up the page with in the PDF and not the whol PDF. i guess i would have to have a function of some type, but i have not used functions yet.

View Replies !
More Than One Select Form On The Same Page.
How can I create a page with more than one select form on the same page, and pass the parameters using POST to another php page?

This is different from using the MULTIPLE attribute, where more than one value can be chosen in the same select form. Code:

View Replies !
Select - Send The Value To Another Page.
In a form I have a control lsDocent. I want send the value to another page.
He send the second parameter 'code' but he send the string lsDocent to the
other page instead of the value of lsDocent. Code:

View Replies !
Use The Php Include Command In Source Code To Insert External Page
Hello, i am trying to use the php include command in source code to insert external page when a main page loads, but get the following errors.. can you help?

View Replies !
Header Problem - Insert The Info Below And Then Jump Back To A Page.
i want to insert the info below and then jump back to a page. Here is insert and the header statement: PHP Code:

View Replies !
Using PHP To Select A Page Theme/layout
I'm in the process of converting my site (www.aldera.net) into a database driven site using MySQL and PHP. If you take a look around in the navigation, you will see that the pages are all similar but with different graphics/design.

Is it possible to write a php script for the site so that the pages have a variable $theme (or layout)?

like if I put $theme="characters"; then the characters layout would display the database driven content, .... if I set $theme="spaceships"; it would show the spaceships layout? etc...

Any ideas? how about if I named all the graphics the same thing and put them in different folders and filled substituted a variable for a folder name?.. like this:

$theme="spaceships";
print "<img src='/graphics/ . $theme . /top-image.jpg'>";

... and (if I wrote it correctly), the output would be:
<img src='/graphics/spaceships/top-image.jpg'>

.. I'd have to do that for every graphic on the page.. is that how this is done? Is there a better way? Suggestions appreciated!!

View Replies !
How Do I Return 10 Results Per Page Using SELECT Statement?
I'm wasn't sure whether to post this under the PHP or under the MySQL section of the forums. Since most people (I'm assuming) who write PHP script, also use MySQL, I thought I'd stick with PHP. I'm rather new to both PHP and MySQL and I'd be very grateful to anyone who can help me solve a problem I'm having at the moment. First, I'll give you an introduction to my little project...

I'm developing a database in MySQL that is used to store the song titles of all the MP3s I have on my PC. I've written a basic search feature that works well. The user has 2 options: Either he can type a special "!ALL" "parameter", that I made up, to return all the songs in the database or the user may enter a few characters in the textbox and select "song title" or "artist" etc. from a dropdown to search for a specific song title or artist etc.. Hope you are following so far? Say for example the user presses submit after typing "!ALL" to return all the song titles - there could be hundreds of results. What I want to do now is display 10 results on a page, then on the next page another 10, etc. (like a real search engine!). I've tried doing it with the LIMIT statement, but like I said I'm new to this and discovered that that is not the right way of going about it. My question is this: how would I go about returning 10 matches per page? Do I use hidden form fields? What would the SELECT statement look like? What would the PHP scripting look like to setup the "back" and "forward" navigation between the result for the search?

View Replies !
Automatically Open Default Mail Program And Insert The Current Page Of Browser As The Body Of The Message.
On my website I would like the facility to click on an image or text that will automatically open up their default mail program and insert the current page on their browser as the body of the message.

I realise that most browsers will have this facility already but I would like to add my own method. Problem is, I have no idea on how to achieve this. I'm sure it can't be that difficult though. It maybe can be done just using HTML, I don't know.

View Replies !
Insert Values - Table Has Four Columns To Insert Into
I have a bunch of information that I want to insert into a table

insert into TABLE values ('hello','I','am','lost');

pretend that the words that are being inserted are coming from a form for another page. In he case I above I have declared that the table has four columns to insert into. What if I do not know how many columns there are?

View Replies !
Insert Into Table - $query = "INSERT INTO Tbl
I have a small problem which I've been working on for a while. PHP Code:

$query = "INSERT INTO tbl(username,ip,link) VALUES("Brin' . $result['id'] . '","$REMOTE_ADDR","http://www.domain.com/sub/start.php?username=Brin"' . $result['id'] . ' )";
mysql_query($query);

Any ideas?

View Replies !
Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution.

So it goes <select name='status[]'>... <select name='resolution[]'>

Then i have a another php page.
$status = $_POST['status'];
$resolution = $_POST['resolution'];

Now my question is, how do i do the sql query statement?

mysql_query("SELECT * from bugs where status=$status and resolution=$resolution");

The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.

View Replies !
SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

View Replies !
Insert Statement Doesn't Insert Anything
I have an int field in a database and for teh purposes of this case the insert statement doesn't insert anything into the field using the ' ' syntax however in the mysql database this appears as 0. I was wondering can I still use the empty syntax as follows or will it not work as it is 0 does is this not classed as empty?

  if (empty($row['intTest'])){
 
 $sns= "empty";
 }

View Replies !
SELECT * VS SELECT Field1, Field2, Field3
If I need all/almost all fields from a table, is there any significant performance difference between using SELECT * from table and SELECT field1, field2, field3 etc from table?

View Replies !
Select Statement - Select Random ID #
I have made up a page that pull info on 13 branches of stores onto one main page. It's basically there to display all the branches on one page... then you click on the one you're interested in and then you go to a more detailed page.

Back to the main page. On the top, there's kind of a featured branch that has a bigger picture and bigger title but it's still getting pul pulled from the same table etc etc etc.

In order for me to avoid favortism to one branch (and for other branches to start complaining) I want to ramdomized the order every time someone came to page but I have no idea how.

right now I have a super simple select statement.

View Replies !
SELECT From Results Of Previous SELECT. Possible?
Is it possible to do a SELECT on the database, then run another query on the results of the SELECT? e.g. From 100,000 rows I wish to SELECT 500.

From that 500, I want to do 10 SELECTs. I only ask because I assume that it will be a lot quicker to extract rows from the smaller "results" produced by the main SELECT than to run the 10 SELECTs on the main database.

Is this even possible? Or should I just do 10 SELECTs from the main database?

View Replies !
SELECT Within A SELECT And UNION
I'm really trying to wrap my brain around how this works...no such luck...I'll just break it out the way I started and see if somebody can help me see this one through...

What I'm doing here is querying two tables to retrieve three results - this works just fine. Then, as I loop through the results I make another query at each pass to retrieve img and content which are stored in the same table as the previous query.

Is there a way to combine all of this into one query? I've been messing with a SELECT within a SELECT and also UNION without any luck... Code:

View Replies !
$PHP_SELF - Create A Link Which Refreshes The Current Page, And Based On Certain Items On The Page
On a page, I want to create a link which refreshes the current page, and based on certain items on the page (simple form objects like radio buttons)the page will load differently. My link looks like this: PHP Code:

View Replies !
Warning: Cannot Modify Header Information - Redirect From Login Page To Logged In Page
I am trying to redirect from login page to logged in page, but using the {header( 'Location: C:wampwww' ) ;} is giving me this error {
Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwpassword.php:14) in C:wampwwwpassword.php on line 35}, find below my code:

View Replies !
Refresh Problem - Warning: Page Has Expired The Page You Requested Was Created Using Information
i got two php page at the movement, which they called edit2.php and edit3.php. when i submit a form from edit2.php to edit3.php, then i could not come back from edit3.php to edit2.php.

Warning: Page has Expired The page you requested was created using information
you submitted in a form. This page is no longer available. As a security precaution,
Internet Explorer does not automatically resubmit your information for you.

To resubmit your information and view this Web page, click the Refresh button. Code:

View Replies !
Page Expired After Going Back From Del. Pageto Form Page Where Comment Is Submitted..
i've made a submit comment form with php and mysql, the form has an action to itself with a hidden var like this: input type=hidden action=add

When i delete a comment on the page i go to a page called delete.php3 and there is a link with a javaline which goes -1 back in my history..

When ive added a comment, the comments page contains action=add and when i delete a comment, i want to click on the link to go back to the comment page, but then, it doesnt work and it says:

Page has expired.

I wondered how to deal with this kind of problems........

View Replies !
Page Has Expired Message In Between The Php Page When I Click Back In Explorer Menu
I have a php script page, which is basically quiz. Visitors (after login in
with their email address) are supposed to answer each question, and when
they click the button at the bottom, the next page will show which problems
they got right or wrong.

Now my visitors, after seeing some problems they got wrong, click Back
button at the Explorer menu, and if they do, they get the below message:
=========================
Warning: Page has Expired The page you requested was created using
information you submitted in a form. This page is no longer available. As a
security precaution, Internet Explorer does not automatically resubmit your
information for you.

To resubmit your information and view this Web page, click the Refresh
button.
========================
Below are the script that I am using. This scripts are after initial login
page, which asks for visitor's email address. I have authorized visitors
already in my MySQL table, and only the visitors whose email address is in
my MySQL table are allowed to login......

View Replies !
Session Var Is Setting ONLY AFTER I Reload Page, Form Var Displays First Page Load
Page1 has a form that calls Page2. The beginning of Page2:
<? php session_start();
$s=$_POST['sSelected'];
session_register("s"); ?>

in the middle of Page2 I have a form varaible:
<?php echo $_POST['stateSelected']; ?>
<?php echo $_SESSION['s']; ?>

The form var displays the first time the page loads. The session var
displays only after reloading the page2.

View Replies !
Login In A User, And Then Pass The Username And Session_id From Page To Page
I want to login in a user, and then pass the username and session_id from page to page until the leave the admin area of the site. Here's a simplified function: PHP Code:

View Replies !

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