473,379 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

i want to insert the mem_id in $p

my table is member

Expand|Select|Wrap|Line Numbers
  1. mem_id     USername   Password
  2.  
  3. 1           gggg     ggggggg
  4.  
  5. 2            hhh      hhh
  6.  
  7. $p=mysql_query("SELECT mem_id   FROM `member` Where username='username'"); 
  8.  
  9.  
  10. if(isset($_POST["submit"]))
  11.  
  12.  
  13.  
  14. {
  15.  
  16. $sql="INSERT INTO expenses (UserID, Username, Name, Amount, Type, Description )
  17.  
  18. VALUES
  19.  
  20. ('$p','$_POST[username]','$_POST[Name]','$_POST[Amount]','$_POST[Type]','$_POST[Description]' )";
  21.  
  22.  <?php $query = "SELECT * FROM member Where Role='User'";
  23.  
  24.   $result = mysql_query($query);
  25.  
  26.  ?> <select    name="username"> <option>---Select---</option> <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) 
  27.  
  28. { ?> <option value="<?php echo $line['username'];?>"> <?php echo $line['username'];?> </option> <?php } ?> </select> <input type="text" name="Name" required> <input   name="Amount"  required type="number" step="0.01"> <select   name="Type"> <option name="Type">Expenses</option> <option>Income</option> </select> <input   type="text" name="Description">
Jan 22 '15 #1
1 1260
Exequiel
288 256MB
you need to use mysql_fetch_array() for you to get the data inside the table depending on your sql query. like this one.
Expand|Select|Wrap|Line Numbers
  1.  <?php
  2. if(isset($_POST["submit"]))
  3. {
  4.     $p= mysql_fetch_array(mysql_query("SELECT mem_id   FROM member Where username='username'");
  5.     if($p)
  6.     {
  7.         $mem_id = $p['mem_id'];//get the id
  8.         $insert = mysql_query("INSERT INTO expenses(UserID, Username, Name, Amount, Type, Description) VALUES('$mem_id','$_POST[username]','$_POST[Name]','$_POST[Amount]','$_POST[Type]','$_POST[Description]')");
  9.     }
  10. }
  11. ?>
  12.  
Jan 23 '15 #2

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

Similar topics

11
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
0
by: minhadd | last post by:
Hello Would Anyone help me ?? I want insert into Microsoft Acess visitor's IP by ASP. But It is not working ...
1
by: Hendry | last post by:
i want insert many rows into a table use javascript, but it was too slow when i insert 50 by 50 how can i improve the performance.
1
by: rajasekar | last post by:
hi friends, this my code.. i want insert multiple record.. how can i? plz send me the solution.. <? for($i=0;$i<$count;$i++) { $n++; $id=mysql_result($res,$i,trainer); ...
0
by: gazanfar | last post by:
Yes thanks Question is that ---I want to insert image/or image path in my SQlServer 2000 through Visual basic application.like after scan of any photo i want insert in database on whoever's no...
1
by: charlesa | last post by:
Hi all I have a table for job. In that table having some data. But I want insert one more row. Job_id job_title min_sal max_sal 10 cse 1000 ...
0
rajiv07
by: rajiv07 | last post by:
Set MyConn = Server.CreateObject("ADODB.Connection") MyConn.Open "DSN=dataconn" set f=fso.getfile(strPath) strFileSize = f.size set f=nothing set fso=nothing adTypeBinary = 1...
3
by: svsenthilkumar | last post by:
Hai, i want to insert a record and retrieve id using php-mysql. i want insert a record by copy of another one table. after inserting i update a field in the inserted record. so, can i...
1
by: saifulhaque | last post by:
Hi Dear How can insert, Display ,update multiple records simultaneously through GridView in Asp.net. I have Button for insert, update . I want insert, update multiple records through a GridView...
5
by: enrekan2011 lan | last post by:
haii... im new here and in php coding as well.. sorry if im ask stupid question here.. i just need some help from you all because i have try find at google but i still didn't found the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.