hello i have two tables ,pelates(firstname,lastname,id_country) and country(country_name,id_country) and a form.i want to insert into tha pelates table the id_country from the other table but i can't.also in my form the countries appear with this code: - Country:<?php
-
require_once('../mysqli_connect.php');
-
$q= "SELECT * FROM country";
-
$r=mysql_query($q);
-
//var_dump($r);
-
?>
-
<select name="country_name" id="country_name">
-
-
<?php while ($row=mysql_fetch_assoc($r)) { ?>
-
<?php echo'<option value="' . $row['id_country'] . '" />' .$row['country_name'] . ' </option>';?>
-
<?php } mysql_close($link);
-
?>
-
-
</sele
what can i do?
4 1235 Luuk 1,047
Recognized Expert Top Contributor
Pleas change you code in Line#3 to contain the actual field names, like this (untested): -
$q= "SELECT id_country, country_name FROM country";
This gives better readable code, and it's more errorproof.
(You should NEVER use '*' in any sql-query!)
Back to your queston: "hello i have two tables ,pelates(firstname,lastname,id_country) and country(country_name,id_country) and a form.i want to insert into tha pelates table the id_country from the other table"
Hmmmz. so you want to insert id_country in the table "pelates(firstname,lastname, id_country)"
I seem to be missing the point.... ;)
thanks for the fast answer.
i have to insert into pelates a lot of things.actually a piece of my code is here: - if(empty($_POST['first_name'])) {
-
$errors[]='You forgot to enter your first name.';
-
}else{
-
$fn=mysql_real_escape_string(trim($_POST['first_name']));
-
}
-
if(empty($_POST['last_name'])) {
-
$errors[]='You forgot to enter your last name.';
-
}else{
-
$ln=mysql_real_escape_string(trim($_POST['last_name']));
-
}
-
if(empty($_POST['email'])) {
-
$errors[]='You forgot to enter your email.';
-
}else{
-
$e=mysql_real_escape_string(trim($_POST['email']));
-
}
-
if(!empty($_POST['pass1'])) {
-
if($_POST['pass1'] !=
-
$_POST['pass2']) {
-
$errors[]='Your password did not match the confirmed password.';
-
}else{
-
$p=mysql_real_escape_string(trim($_POST['pass1']));
-
}
-
}else {
-
$errors[]='You forgot to enter your password.';
-
}
-
if(empty($_POST['birth'])) {
-
$errors[]='You forgot to enter your birth.';
-
}else{
-
$b=mysql_real_escape_string(trim($_POST['birth']));
-
}
-
if(empty($_POST['address'])) {
-
$errors[]='You forgot to enter your address.';
-
}else{
-
$a=mysql_real_escape_string(trim($_POST['address']));
-
}
-
-
-
if(empty($_POST['tilefwno'])) {
-
$errors[]='You forgot to enter your tilefwno.';
-
}else{
-
$t=mysql_real_escape_string(trim($_POST['tilefwno']));
-
}
-
-
-
if(empty($errors)) {
-
-
$q= "INSERT INTO `pelates` (`first_name`, `last_name`, `email`, `pass`, `registration_date`, `birth`, `address`,`id_country`, `tilefwno`,`filename`) VALUES ('$fn','$ln','$e', MD5('$p'), NOW(),'$b','$a','$_POST[id_country]','$t','".mysql_real_escape_string($_FILES["upload"]["name"])."')";
-
$r=mysql_query($q,$link);
all it works but i can't put the id_country .any help??
Luuk 1,047
Recognized Expert Top Contributor
When you are handling other $_POST data you do it like this, i.e. on the address field:
$_POST['address']
Why do you think the insert can do it like this:
.....a','$_POST[id_country]','$.....
(hint: the single-quotes arround id_country are missing.
And you should do input-validation on that field too!
(you to check if it's a valid country_id.)
thanks for your repsonse but how i can display the id_country from the table country when the form is submitted??it doesn't take anything in thie field.here is my entire code: - <?php
-
$page_title='Register';
-
include ('includes/header.html');
-
-
-
if (isset($_POST['submitted'])){
-
if(isset($_FILES['upload'])) {
-
$allowed =array ('image/pjpeg','image/jpeg','image/JPG','image/X-PNG','image/PNG','image/png','image/x-png');
-
-
if (in_array($_FILES['upload'] ['type'], $allowed)){
-
-
if(move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/{$_FILES['upload']['name'] }")) {
-
echo '<p><em>The file has been uploaded..</em></p>';
-
}
-
}else{
-
echo '<p class="error">Please uploaad a JPEG or PNG image.</p>';
-
}
-
}
-
if ($_FILES['upload']['error']>0) {
-
echo '<p class="error">The file could not be uploaded because: <strong>';
-
-
switch($_FILES['upload']['error']){
-
case 1:
-
print 'The file exceeds the upload_max_filesize setting in php.ini.';
-
break;
-
case 2:
-
print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
-
break;
-
case 3:
-
print 'The file was only partially uploaded.';
-
break;
-
case 4:
-
print 'No file was uploaded.';
-
break;
-
case 6:
-
print 'No temporary folder was available.';
-
break;
-
case 7:
-
print 'Unable to write to the disk.';
-
break;
-
case 8:
-
print 'File uploaded stopped.';
-
break;
-
default:
-
print 'A system error occured.';
-
break;
-
}
-
print '</strong></p>';
-
}
-
if(file_exists($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']))
-
{
-
echo $_FILES["upload"]["tmp_name"] . " already exists. ";
-
}
-
else
-
{
-
move_uploaded_file($_FILES["upload"]["tmp_name"],
-
"upload/" . $_FILES["upload"]["tmp_name"]);
-
-
}
-
-
-
//var_dump($_POST);
-
require_once('../mysqli_connect.php');
-
-
$errors=array();
-
-
if(empty($_POST['first_name'])) {
-
$errors[]='You forgot to enter your first name.';
-
}else{
-
$fn=mysql_real_escape_string(trim($_POST['first_name']));
-
}
-
if(empty($_POST['last_name'])) {
-
$errors[]='You forgot to enter your last name.';
-
}else{
-
$ln=mysql_real_escape_string(trim($_POST['last_name']));
-
}
-
if(empty($_POST['email'])) {
-
$errors[]='You forgot to enter your email.';
-
}else{
-
$e=mysql_real_escape_string(trim($_POST['email']));
-
}
-
if(!empty($_POST['pass1'])) {
-
if($_POST['pass1'] !=
-
$_POST['pass2']) {
-
$errors[]='Your password did not match the confirmed password.';
-
}else{
-
$p=mysql_real_escape_string(trim($_POST['pass1']));
-
}
-
}else {
-
$errors[]='You forgot to enter your password.';
-
}
-
if(empty($_POST['birth'])) {
-
$errors[]='You forgot to enter your birth.';
-
}else{
-
$b=mysql_real_escape_string(trim($_POST['birth']));
-
}
-
if(empty($_POST['address'])) {
-
$errors[]='You forgot to enter your address.';
-
}else{
-
$a=mysql_real_escape_string(trim($_POST['address']));
-
}
-
-
-
if(empty($_POST['tilefwno'])) {
-
$errors[]='You forgot to enter your tilefwno.';
-
}else{
-
$t=mysql_real_escape_string(trim($_POST['tilefwno']));
-
}
-
-
-
if(empty($errors)) {
-
-
$q= "INSERT INTO `pelates` (`first_name`, `last_name`, `email`, `pass`, `registration_date`, `birth`, `address`,`id_country`, `tilefwno`,`filename`) VALUES ('$fn','$ln','$e', MD5('$p'), NOW(),'$b','$a','$_POST[id_country]','$t','".mysql_real_escape_string($_FILES["upload"]["name"])."')";
-
var_dump($q);
-
$r=mysql_query($q,$link);
-
-
if($r){
-
echo '<h1>Thank you.. <h1>
-
<p>You are now registered </p>';
-
}else {
-
echo '<h1>System Error..</h1>
-
<p class="error">You could not to be registered due to a system problem. Go back and fill the form again in: <a href="register.php">http://localohost/week3/htdocs/register.php</a> .</p>';
-
-
}
-
-
}else{
-
echo 'the following error occured:';
-
foreach($errors as $msg){
-
echo" =$msg<br />\n";
-
}
-
echo 'please try again';
-
}
-
-
mysql_close($link);
-
}
-
-
?>
-
-
-
<h1>Register</h1>
-
<form enctype="multipart/form-data" method="post" action="register.php">
-
-
<legend><b>Enter your information in the form below:</b></legend>
-
-
First Name: <input type="text" name="first_name" size="10" maxlength="20" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /><br/>
-
Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /><br/>
-
Email: <input type="text" name="email" size="20" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /><br/>
-
Password: <input type="password" name="pass1" size="10" maxlength="20" /><br/>
-
Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" /><br/>
-
Birth:<input type="date" name="birth" placeholder="(MM/DD/YYYY)" required><br>
-
Address: <input type="text" name="address" size="50" maxlength="80" /><br/>
-
Country:<?php
-
require_once('../mysqli_connect.php');
-
$q= "SELECT id_country,country_name FROM country";
-
$r=mysql_query($q);
-
//var_dump($r);
-
?>
-
<select name="country_name" id="country_name">
-
-
<?php while ($row=mysql_fetch_assoc($r)) { ?>
-
<?php echo'<option value="' . $row['id_country'] . '" />' .$row['country_name'] . ' </option>';?>
-
<?php } mysql_close($link);
-
?>
-
-
</select>
-
Tilefwno: <input type="text" name="tilefwno" size="30" maxlength="40" /><br/>
-
Upload :<legend>Select a JPEG or PNG image of 512KB or smaller to be uploaded:</legend>
-
<p><b>Filename:</b> <input type="file" name="upload" /></p>
-
<input type="submit" name="submit" value="Register" />
-
<input type="hidden" name="submitted" value="TRUE" />
-
</form>
-
</body>
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: G-Fit |
last post by:
Hello group,
I have several servers hosting SQL databases. On each of them, I have
several databases. All those databases have the same structure (even those
on different servers), only the data...
|
by: ZRexRider |
last post by:
Hi,
I have an application that uses MS-SQL Linked tables. I have a utility
routine that drops all links and re-establishes them. It works great
when my connection string is a DSN connection...
|
by: Ahmet Karaca |
last post by:
Hi.
myds.Reset();
mycommand.SelectCommand.CommandText=
"Select att1 from Ing as Ingredient, Pro as Product "+
"where Pro.ad='apple' and Pro.id=Ing.id";
mycommand.Fill(myds, "Product"); // Here...
|
by: peter.konda |
last post by:
Hello!
I have been busting my head with a problem, that goes like this:
1. with a first ajax call to the server(apache 2.0 + php), I create a
temporary table like this:
create temporary table...
|
by: Terry Jolly |
last post by:
Web Solution
Goal: Have a global database connection
Why: (There will be 30+ tables, represented by 30+ classes) I only want to
reference the database connection once.
I put the connection...
| |
by: Jim Stools |
last post by:
Hopefully this will make some sense.. I have a database that has around 50
tables - I thought about putting each table in a class and the data
connection in a class then I could manage the (tables)...
|
by: Jim Stools |
last post by:
Forget the re-post I had my clock set 12 hours earlier
Hopefully this will make some sense.. I have a database that has around 50
tables - I thought about putting each table in a class and the...
|
by: Venkata Narayana |
last post by:
Hi,
You all may be knowing that Connection.isClosed() does not tells us
if the underying DB connection is active or not; it only checks if
Connection.close() had been previously called or not....
|
by: Cintury |
last post by:
Hi all,
I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |