473,406 Members | 2,208 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,406 software developers and data experts.

Data Input

Hello
with this script I need to show the user (utenti) list and after I need to
input in the table RICHIESTA the field COGNOME e NOME.
This is the code but don't go. Someone can tell me where is the mistake???
Many Thanks!!
<select name="user" id="user">
<?
$q= mysql_query("select * from utenti order by user");
while ($res=mysql_fetch_array($q))
{
echo "<OPTION VALUE=\"$res[user]\">$res[user] --
$res[reparto]</OPTION>";
}
mysql_free_result($q);

$rs = mysql_query("SELECT * FROM utenti WHERE user = ".$user);

$cognome = mysql_result($rs, 0, "cognome");
$nome = mysql_result($rs, 0, "nome");
mysql_query("INSERT INTO richiesta (cognome,nome) VALUES
($cognome,$nome)");
?>
</select>
Jul 17 '05 #1
4 1708
Quijote wrote:
with this script I need to show the user (utenti) list and after I need to
input in the table RICHIESTA the field COGNOME e NOME. <select name="user" id="user">
<?
$q= mysql_query("select * from utenti order by user");

(snip)
Do some error-checking in your scripts!

For a SQL select action I do:

<?php
$conn = mysql_connect($host, $user, $pass)
or die('Impossible to connect to '.$host.' now: '.mysql_error());
$sql = 'select * from utenti order by user';
$q = mysql_query($sql)
or die('Error '.mysql_error().' in query '.$sql);
while ($res = mysql_fetch_array($q)) {
/* whatever */
}
// ...
?>

This way, if there's an error connecting or in the select string I get
feedback about it.

In your second query to the "utenti" table you are using a variable
named $user. Where did it come from?
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

"Pedro Graca" <he****@hotpop.com> ha scritto nel messaggio
news:c0*************@ID-203069.news.uni-berlin.de...

In your second query to the "utenti" table you are using a variable
named $user. Where did it come from?
--


Thanks Pedro, in the code there is a mistake the right line is

$rs = mysql_query("SELECT * FROM utenti WHERE user=".$_POST[user]);
Jul 17 '05 #3

"Pedro Graca" <he****@hotpop.com> ha scritto nel messaggio
news:c0*************@ID-203069.news.uni-berlin.de...

Do some error-checking in your scripts!

For a SQL select action I do:

<?php
$conn = mysql_connect($host, $user, $pass)
or die('Impossible to connect to '.$host.' now: '.mysql_error());
$sql = 'select * from utenti order by user';
$q = mysql_query($sql)
or die('Error '.mysql_error().' in query '.$sql);
while ($res = mysql_fetch_array($q)) {
/* whatever */
}
// ...
?>


Thanks, the problem for me is not to list the users (utenti) this is
possible but the problem is to update the fields COGNOME and NOME that are
in table UTENTI and I need to fill in table RICHIESTA connecting the posted
user with the table UTENTI ... I hope it's clear :-). Many many thanks again
....
Jul 17 '05 #4
Quijote wrote:
"Pedro Graca" <he****@hotpop.com> ha scritto nel messaggio
news:c0*************@ID-203069.news.uni-berlin.de...
Quijote wrote:

$rs = mysql_query("SELECT * FROM utenti WHERE user = ".$user);

$cognome = mysql_result($rs, 0, "cognome");
$nome = mysql_result($rs, 0, "nome");
mysql_query("INSERT INTO richiesta (cognome,nome) VALUES ($cognome,$nome)");
Do some error-checking in your scripts!
Do some error-checking in your scripts!
$rs = mysql_query("select * from utenti where user=".$_POST["user"]);
Are you sure? Why not doing some error-checking? :)
I guess $_POST["user"] is a string, and as such, should be enclosed in
single quotes.
mysql_query("INSERT INTO richiesta (cognome,nome) VALUES ($cognome,$nome)");


Are you sure? Why not doing some error-checking? :-))
Don't $cognome and $nome need to be enclosed in single quotes?
Thanks, the problem for me is not to list the users (utenti) this is
possible but the problem is to update the fields COGNOME and NOME that are
in table UTENTI and I need to fill in table RICHIESTA connecting the posted
user with the table UTENTI ... I hope it's clear :-). Many many thanks again


It helps to do error-checking.

Ii does not hurt your script noticeably (if at all) and it is a great
tool to aid in debugging when something goes wrong.
Happy Coding :-)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Randell D. | last post by:
Folks, Perhaps someone can figure this out - this is 'the process of my script' I have a form whereby I can add multiple contacts to a single address. There is only one...
2
by: Tavish Muldoon | last post by:
What a pain trying to insert data into a table from a stored proc. My webform asks for 16 pieces of data - which then gets written to the database. I found this easier than the crap below...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
5
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and...
5
by: DC Gringo | last post by:
I am having a problem reading a simple update to the database. Basically I'm testing a small change to the pubs database -- changing the price of the Busy Executive's Database Guide from 19.99 to...
3
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. ...
0
by: amrhi | last post by:
Hy Guys , Can anybody help me ? I try to make small web database in my unit. Some of fields have on change behaviour to get other data that automatically filled other text field. But when i try to...
3
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file....
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
3
by: planey | last post by:
Hi, I was reading topic about setters and getters (http://www.thescripts.com/forum/thread631267.html) and wanted to ask, how they should be used? I have noticed that a general data validators suck,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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 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.