473,569 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php - inserting info into a database

hey guys, can anyone see where im going wrong in my code below? i am
making a registration form on a webpage before using php to send the
input data into a mySQL database. first off is the code for the
registration form:
<form method = "POST" action="display .php"
onSubmit="retur nverifyform(thi s)">

<h1> Please fill in all fields below to register: </h1> Title:

<select name = "title">
<option selected>Please select..
<option>Mr
<option>Mrs
<option>Miss
</select><br>

<br>First name: <input type ="text" name = "first">
<font color = "black"></font><br>

<br>Last name: <input type = "text" name = "last">
<font color="black"></font><br>

<br>Age:
<select name = "age">
<option selected>Please select..
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
<option>31
<option>other
</select><br>

<br>Subject:
<select name ="subject">
<option selected>Please select..
<option>Compute r Science
<option>Scien ce
<option>Engli sh
<option>Maths
<option>Archite cture
<option>Busines s
<option>Dentist ry
<option>Earth , Ocean and Planetary Science
<option>Enginee ring
<option>Europea n Studies
<option>Histo ry and Archaeology
<option>Journal ism, Media and Cultural Studies
<option>Law
<option>Medicin e
<option>Music
<option>Religio us and Theological Studies
<option>Welsh
<option>Other
</select><br>

<br>Initial Year of Study:
<select name = "year">
<option selected>Please select..
<option>1990
<option>1991
<option>1992
<option>1993
<option>1994
<option>1995
<option>1996
<option>1997
<option>1998
<option>1999
<option>other
</select><br>

<br>Email Address: <input type = "text" name = "email">
<font color="black"></font><br>

<br>User Name: <input type = "text" name = "user_name" >
<font color="black"></font><br>

<br>Password: <input type = "password" name = "password">
<font color="black"></font><br>

<br><input type="submit" name = "Send" value = "Send">

</form>

next off is the code using php:
<?php

$connection =
mysql_connect(" sentinel.cs.cf. ac.uk","scm5sjc ","my_password_ here");
mysql_select_db ("sjcdb",$conne ction)or die("failed!");

$title=$_POST['title'];
$first=$_POST['first'];
$last=$_POST['last'];
$age=$_POST['age'];
$subject=$_POST['subject'];
$year=$_POST['year'];
$email=$_POST['email'];
$user_name=$_PO ST['user_name'];
$password=$_POS T['password'];

mysql_query("IN SERT INTO info VALUES ('',
'$title','$last ','$age',$subje ct','$year','$e mail','$user_na me','$password' )",$connection) ;
mysql_close(con nection);

?>

anyone know where im going wrong??
cheers

Mar 23 '06 #1
4 1441
Did you account for every field in the table? There must be as many
values as their are fields or the query will fail.

Mar 23 '06 #2
Extract the query into a string (i.e. $query = "..."), and replace
mysql_query() with
the following:

if( !mysql_query( $query, $connection ) )
{
exit( mysql_error( $connection ) . "<br>Query: <br><pre>" . $query .
"</pre>" );
}

You can wrap all your query calls in a function, as it enables basic
debugging any time a query might fail
function my_query( $query, $connection, $DEBUG = 0 )
{
$query_worked = mysql_query....
if( !$query_worked && $DEBUG )
{
// do the exit and output here, or just output and return
$query_worked
}
else
{
return $query_worked;
}
}

}

Mar 23 '06 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

comp_guy wrote:
anyone know where im going wrong??


You're wrong in not using a "value" attribute in the <option> tags, and
you're wrong in trusting the posted values without checking or escaping
them first.

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_********* *************** *@hotmail.com
Jabber:iv****** ***@jabber.org ; iv*********@kde talk.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEIvpe3jc Q2mg3Pc8RAt0NAJ 9zCcH4zABN2Saqp JaXNqyl7ES5xwCf ZuXQ
JvMhkfm1TsIDwH3 l+mWYCp4=
=F2QF
-----END PGP SIGNATURE-----
Mar 23 '06 #4
For debugging purposes, storing the query in a variable (which you will
use as bobzimuta said eg. mysql_query( $query, $connection ))and
echoing it to the screen will often show up sql syntax errors.

Mar 24 '06 #5

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

Similar topics

14
4050
by: Miranda | last post by:
Hi, I have a ASP/vbscript program that generates random passwords. The problem is I need to insert those passwords into an Access database of 327 clients. I have the random password program generating the 327 passwords, but have had no luck inserting them. =============================================== Here is the code that generates the...
1
4122
by: Azel | last post by:
Hi, I am trying to learn ADO.net and I keep running into problems trying to insert data into my Access Database: data.mdb. here is my code: <code> // Database Variables
4
1138
by: Bruno Alexandre | last post by:
Hi guys, I have a web application that insert Clients info into the Database, the Apllication is accesed by several user at the same time, the Client Info is divide by 3 tables (Client, Product and 1 that combine the Client and Product and having all info for how the client bought the product) My question is: HOW can I know for sure that...
0
2993
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted. Where Peter is the value...
2
4708
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First question. I have a web survey that I am working on and have successfully dynamically taken the info from a database, displayed it on the screen and then...
1
1647
Ajm113
by: Ajm113 | last post by:
Ok, when I was new to this I had this problem and I bet a lot of other people did when they where new to PHP and Mysql. So this mite be your question; "Ok, no errors or warnings in mysql and php so why isn't the script entering info into my row?". Well to awnser your question most servers that you pay for monthly or own will have a anti mysql...
4
2230
by: Markus | last post by:
Hello I use a table to cache some informations which need lots of resources to be composed. The first time the info is needed, it will be composed and written to the cache table ($db in the example is a PEAR DB object; the question is the same for other ways of accessing the database): // Retrieve info if present $details =...
6
1887
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
2
3067
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
2
3102
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate record. My code inserts records one by one using addnew-updatebatch. If there is a duplicate in the db, it will display "already exists" and if it is...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7677
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
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 we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.