| | |
insert data into two separate table / 2 queries in same php file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
i can't get this from working. i want to execute these two queries ebcause i want to insert data to two separate table.
is it possible to do this with one query?
this is what i've got so far:
is it possible to do this with one query?
this is what i've got so far:
php Syntax (Toggle Plain Text)
$sql = "INSERT INTO login SET studNo = $studNo, userName = $user, password = $pass, dateRegistered = NOW()"; $sql2 = "INSERT INTO users SET studNo = $studNo, lastName = $lName, firstName = $fName, gender = $gender, bMonth = $month, bDay = $day, bYear = $year, address = $address, cellNo = $phone, email = $email"; if(mysql_num_rows(@mysql_query("SELECT * FROM classlist WHERE num = '$studNo'"))) { if(mysql_num_rows(@mysql_query("SELECT studNo FROM login WHERE studNo = '$studNo'"))) { $flag = true; $headMsg = "Registration Error"; $msg = "You have already registered."; } else{ @mysql_query($sql); @mysql_query($sq2); } } else { $flag = true; $headMsg = "Registration Unsuccessful"; $msg = "Your student number doesn't exist in the database."; }
a joke.
-1
#2 Oct 11th, 2009
I don't understand the purpose of your 'login' table. If it is to keep a login log - just use the id from the users table and a datetime. You'll need to make 2 sql queries on registering. Using mysql_insert_id() to get the id of the newly added user to the users table.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
0
#3 Oct 12th, 2009
•
•
•
•
i can't get this from working. i want to execute these two queries ebcause i want to insert data to two separate table.
is it possible to do this with one query?
this is what i've got so far:
php Syntax (Toggle Plain Text)
$sql = "INSERT INTO login SET studNo = $studNo, userName = $user, password = $pass, dateRegistered = NOW()"; $sql2 = "INSERT INTO users SET studNo = $studNo, lastName = $lName, firstName = $fName, gender = $gender, bMonth = $month, bDay = $day, bYear = $year, address = $address, cellNo = $phone, email = $email"; if(mysql_num_rows(@mysql_query("SELECT * FROM classlist WHERE num = '$studNo'"))) { if(mysql_num_rows(@mysql_query("SELECT studNo FROM login WHERE studNo = '$studNo'"))) { $flag = true; $headMsg = "Registration Error"; $msg = "You have already registered."; } else{ @mysql_query($sql); @mysql_query($sq2); } } else { $flag = true; $headMsg = "Registration Unsuccessful"; $msg = "Your student number doesn't exist in the database."; }
http://dev.mysql.com/doc/refman/5.1/en/insert.html
However, there is nothing preventing you from doing two MySQL queries on the same PHP script.
It is hardly ever a good practice to force error suppression on function calls. ie: @mysql_query($sql);
If you remove the @ signs you'll see the errors that is preventing the SQL query from executing.
A better alternative is to set the error reporting level.
eg:
PHP Syntax (Toggle Plain Text)
ini_set('display_errors', '1'); ini_set('error_reporting', E_ALL);
or using:
PHP Syntax (Toggle Plain Text)
set_error_handler()
http://www.php.net/manual/en/functio...or-handler.php
When in development, you can choose to display errors. However, when in production mode, you can hide errors.
PHP Syntax (Toggle Plain Text)
ini_set('display_errors', '0'); ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set('log_errors', '1');
This hides errors in the PHP script output, but they are still logged to the PHP error log.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
0
#4 Oct 12th, 2009
Here is a good reference to error handling in PHP: http://www.addedbytes.com/php/php-in...g-and-logging/
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
0
#5 Oct 12th, 2009
i have two separate insert query:
but the data don't appear on the tables. why?
php Syntax (Toggle Plain Text)
@mysql_query($sql); @mysql_query($sql2);
but the data don't appear on the tables. why?
a joke.
0
#6 Oct 12th, 2009
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
0
#7 Oct 12th, 2009
Ditto DE. However, I'm really confused as to why you've got all those loops just for inserting/checking for registration.
Have you confused table 'users' and 'classlist' in your code or are they separate entities? Is 'login' your 'registered users' table?
Could you supply info w.r.t the purpose of the tables. So far I see 3 tables:
users, classlist and login.
Your first post doesn't make it clear why you should have a separate 'login' and 'users' tables. Although, it may just be me being thick.
Have you confused table 'users' and 'classlist' in your code or are they separate entities? Is 'login' your 'registered users' table?
Could you supply info w.r.t the purpose of the tables. So far I see 3 tables:
users, classlist and login.
Your first post doesn't make it clear why you should have a separate 'login' and 'users' tables. Although, it may just be me being thick.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
•
•
Join Date: Feb 2009
Posts: 14
Reputation:
Solved Threads: 1
0
#8 Oct 12th, 2009
Try this
PHP Syntax (Toggle Plain Text)
$sql = "INSERT INTO login (studNo, userName, password, dateRegistered) VALUES ($studNo, $user, $pass , NOW())"; $sql2 = "INSERT INTO users (studNo, lastName, firstName, gender, bMonth, bDay, bYear, address, cellNo, email) VALUES ($studNo, $lName, $fName, $gender, $month, $day, $year, $address, $phone, $email)"; if(mysql_num_rows(@mysql_query("SELECT * FROM classlist WHERE num = '$studNo'"))) { if(mysql_num_rows(@mysql_query("SELECT studNo FROM login WHERE studNo = '$studNo'"))) { $flag = true; $headMsg = "Registration Error"; $msg = "You have already registered."; } else{ @mysql_query($sql); @mysql_query($sq2); } } else { $flag = true; $headMsg = "Registration Unsuccessful"; $msg = "Your student number doesn't exist in the database."; }
Last edited by glycerine; Oct 12th, 2009 at 7:01 pm.
0
#9 Oct 13th, 2009
Remove error suppression (the @ in @mysql), then you might have more reason as to why the information is not going in.
Also you must make sure that the information going in the database it the correct data type i.e. only inserting numbers into INT field
Also you must make sure that the information going in the database it the correct data type i.e. only inserting numbers into INT field
They throw us away like yesterdays jam - Maurice Mossley
Please - rep if someone helps you, it can't be traded for stuff, but it's nice.
Please - rep if someone helps you, it can't be traded for stuff, but it's nice.
0
#10 Oct 13th, 2009
Remove error suppression (the @ in @mysql), then you might have more reason as to why the information is not going in.
Also you must make sure that the information going in the database it the correct data type i.e. only inserting numbers into INT field
Also you must make sure that the information going in the database it the correct data type i.e. only inserting numbers into INT field
They throw us away like yesterdays jam - Maurice Mossley
Please - rep if someone helps you, it can't be traded for stuff, but it's nice.
Please - rep if someone helps you, it can't be traded for stuff, but it's nice.
![]() |
Similar Threads
- insert data where (PHP)
- Insert data into two tables using php and mysql (MySQL)
- Help me to insert data into two tables in mysql (PHP)
- Create a link in a table read from a CSV file and pass a variable (PHP)
- Insert data in charts (PHP)
- Get data out of excel file stored as an image (MS SQL)
- writitng data from php to mysql (PHP)
- how to insert data from dataset into database (VB.NET)
- Multiple queries within one php file (PHP)
Other Threads in the PHP Forum
- Previous Thread: How to force web page to open in internet explorer
- Next Thread: MSqyl error
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary bounce broken cakephp checkbox class cms code codingproblem combobox cron curl database date display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla js limit link login mail menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion regex remote return script search server sessions smash sms soap source space sql syntax system table tutorial up-to-date update upload url validation validator variable video web webapplications websitecontactform xml youtube






