Current location: Hot Scripts Forums » Programming Languages » PHP » can i things into 2 tables in the same database on 1 script?


can i things into 2 tables in the same database on 1 script?

Reply
  #1 (permalink)  
Old 06-30-04, 09:08 AM
tisza tisza is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
can i things into 2 tables in the same database on 1 script?

ok, what ive done is made an html form, you type in info etc and click submit and it sneds it to register.php, which puts it into a database, but what i want it to do is to also add some more info into another table in the database, but it doesnt seem to do it, heres what i have, $add works fine, but it doesnt add $add2 to the database:

<?php

$conn = mysql_connect('localhost', 'tisza', '');
mysql_select_db('game',$conn);

$add = "INSERT INTO info values ('', '$_POST[name]', '$_POST[pass]', '$_POST[email]', '$_POST[race]', '1', '0', '100', '25', '25', '10', '10', '100', '100', '1', '1', '1', '1', '1', '1', '1', '50', '0')";

$add2 = "INSERT INTO inv values ('', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', '0' 'None', '0', 'None', '0', 'None', '0', 'None', '0')";

$checkname = "SELECT name FROM info WHERE name='$_POST[name]'";
$checkemail = "SELECT email FROM info WHERE email='$_POST[email]'";
$namecheck = mysql_query($checkname);
$emailcheck = mysql_query($checkemail);

if ( mysql_num_rows($namecheck) >= 1 ) {
echo "The name already exists. <a href='register.html'>Back</a>";

} elseif ( mysql_num_rows($emailcheck) >= 1 ) {
echo "That email adress has already been used. <a href='register.html'>Back</a>";

} else {

mysql_query($add,$conn);
mysql_query($add2,$conn);

echo "You have signed up sucessfully! Click <a href='index.php'>here</a> to login.";
}


?>

also is there a better way to add those 2 things like for it to give an error message if they dont get put in the database, because right now it will says "you have signed up sucessfully" whether or not the two querys work, thx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-30-04, 10:34 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
try -->
PHP Code:

} else {


if (!
mysql_query($add,$conn)) { echo("error in query 1.<br>");}
if (!
mysql_query($add2,$conn)) { echo("error in query 2.<br>");}

echo 
"You have signed up sucessfully! Click <a href='index.php'>here</a> to login.";

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-30-04, 02:08 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
well too add to the suggestion before try

PHP Code:

mysql_query($add,$conn) or die(mysql_error() . ':' $add);

mysql_query($add2,$conn) or die(mysql_error() . ':' $add2); 
This will show you what is going on with your queries. It looks like your queries (both of them) are written wrong. But this will certainly tell if they are.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-01-04, 05:11 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by infinitylimit
well too add to the suggestion before try

PHP Code:

mysql_query($add,$conn) or die(mysql_error() . ':' $add);

mysql_query($add2,$conn) or die(mysql_error() . ':' $add2); 
This will show you what is going on with your queries. It looks like your queries (both of them) are written wrong. But this will certainly tell if they are.
this is defenetly better then my suggestion.. i didnt think about mysql_error().. probably becourse i usually dont use it.. and also i cant say anything about the querys.. i use a totally different style..
$add = "INSERT INTO info something='', name='$_POST[name]', pass='$_POST[pass]', email='$_POST[email]', race='$_POST[race]";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 01:12 AM
error when creating database tables with php script spiroth10 PHP 4 01-06-04 04:59 PM
Developer needed to database pre-written script twastudios Script Requests 0 11-19-03 02:16 PM
script that measures height of tables and vertically aligns nested tables amj01 Script Requests 1 07-04-03 02:20 PM


All times are GMT -5. The time now is 01:47 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.