Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-01-2004, 07:16 PM   PM User | #1
briintex1
New Coder

 
Join Date: Dec 2003
Location: texas
Posts: 96
Thanks: 1
Thanked 0 Times in 0 Posts
briintex1 is an unknown quantity at this point
Adding to a database

I was wondering where I might have gone wrong on adding information to a database, the country_id is an autonumber, so I don't have to add it. But when a user puts in a name of the country, it adds it to the database, once they click the submit button, and it returns them back to this page. It passes the variable through the url I think but I am not for sure about that one either? But any suggestions are helpful...

PHP Code:
<?php
$db 
mysql_connect("localhost""tableName""PW")or die(mysql_error());

mysql_select_db("database")or die(mysql_error());

$obj mysql_query("SELECT * FROM country");
$obj=mysql_fetch_array($obj);

INSERT INTO COUNTRY (country_idcountry_nameVALUES($country?>

}

echo '</select>';
}
?>  
 <html>
<head
</head>
<title><? echo $obj[1?></title>

<FORM ACTION="index.php" METHOD=POST>
Please enter the name of the country to put into the database.
<p>TITLE:<INPUT TYPE="text" NAME="country" SIZE=25 MAXLENGTH=25>
<p><INPUT TYPE="submit">
</FORM>

<?php echo $country ?>
<body>
</body>
</html>
__________________
thanks
bri

Last edited by Spookster; 06-03-2004 at 12:25 AM.. Reason: In the future please surround your code with [php] [/php] tags
briintex1 is offline   Reply With Quote
Old 06-02-2004, 09:55 PM   PM User | #2
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
Quote:
Originally Posted by briintex1

INSERT INTO COUNTRY (country_id, country_name) VALUES($country) ?>

}

I might just be being dumb here, but any particular reason why this line isn't in a mysql_query() function?
MrShed is offline   Reply With Quote
Old 06-03-2004, 12:13 AM   PM User | #3
boeing747fp
Regular Coder

 
Join Date: Oct 2003
Posts: 599
Thanks: 1
Thanked 1 Time in 1 Post
boeing747fp is an unknown quantity at this point
Quote:
$db = mysql_connect("localhost", "tableName", "PW")or die(mysql_error());
try this......

PHP Code:

<?php
$db 
mysql_connect("localhost""ServerUserName""ServerPassWord");
mysql_select_db("DatabaseName",$db);

$select mysql_query("SELECT * FROM `country`");
$obj=mysql_fetch_array($select);

mysql_query("INSERT INTO `country` (`country_id`, `country_name`) VALUES ('','$country')") or die(mysql_error()); 

}

echo 
'</select>';
}
?> 
<html>
<head>
</head>
<title><? echo $obj[1]; ?></title>

<FORM ACTION="index.php" METHOD=POST>
Please enter the name of the country to put into the database.
<p>TITLE:<INPUT TYPE="text" NAME="country" SIZE=25 MAXLENGTH=25>
<p><INPUT TYPE="submit">
</FORM>

<?php echo $country?>
<body>
</body>
</html>
One question, tho..... where did u set $country ? you should have somewhere above the INSERT thing a line like $country = $_POST['country'];

Last edited by boeing747fp; 06-03-2004 at 02:47 AM.. Reason: In the future please surround your code with [php] [/php] tags
boeing747fp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:17 AM.


Advertisement
Log in to turn off these ads.