473,320 Members | 1,848 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,320 software developers and data experts.

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="returnverifyform(this)">

<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>Computer Science
<option>Science
<option>English
<option>Maths
<option>Architecture
<option>Business
<option>Dentistry
<option>Earth, Ocean and Planetary Science
<option>Engineering
<option>European Studies
<option>History and Archaeology
<option>Journalism, Media and Cultural Studies
<option>Law
<option>Medicine
<option>Music
<option>Religious 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",$connection)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=$_POST['user_name'];
$password=$_POST['password'];

mysql_query("INSERT INTO info VALUES ('',
'$title','$last','$age',$subject','$year','$email' ,'$user_name','$password')",$connection);
mysql_close(connection);

?>

anyone know where im going wrong??
cheers

Mar 23 '06 #1
4 1416
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*********@kdetalk.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEIvpe3jcQ2mg3Pc8RAt0NAJ9zCcH4zABN2SaqpJaXNq yl7ES5xwCfZuXQ
JvMhkfm1TsIDwH3l+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
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...
1
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
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...
0
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...
2
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...
1
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...
4
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...
6
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
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...
2
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.