473,320 Members | 1,926 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 Form data database insert

I'm a newbie when it come to things php and i'm having a bit of trouble.

I'm trying to insert data from an html form into a mysql database and can't get it to work.

Just a few bits about my setup, i'm running an sql server locally, i've created the database, table and fields. I think what i'm missing is something that actually runs the sql query when i hit the submit button. Also, i'm aware i haven't made the data being inserted safe, i just wanted to get it working first.

Thanks in advance

[php]
<?php
$dbid = mysql_connect ('localhost');
mysql_select_db("addresses",$dbid) or die ("Cannot find database");
$query = "INSERT INTO `book` (`aid`, `name`, `address`, `postcode`, `telephone`, `email`, `picture`) VALUES ('1 INT', $name text, $address text, $postcode text, $telephone int, $email text, $picture longblob)";
$result = mysql_query($query,$dbid);

$name = "($_REQUEST[name])";
$address = "($_REQUEST[address])";
$postcode = "($_REQUEST[postcode])";
$telephone = "($_REQUEST[telephone])";
$email = "($_REQUEST[email])";
$picture = "($_REQUEST[picture])";
}
?>

<html>
<head>
<title>Data submission - db version</title?
</head>
<body>
<form enctype="multipart/form-data" method="post">
<br>
<input name="name" value="Name"><br />
<input name="address" value="Address"><br />
<input name="postcode" value="Postcode"><br />
<input name="telephone" value="Telephone"><br />
<input name="email" value="Email"><br />
Picture:<br><input type="file" name="picture" size"80" value="Image"><br />

<br><input type="submit" action="data_input.php"></form><br>

</body>
</html>
[/php]
Mar 23 '07 #1
3 4716
ronverdonk
4,258 Expert 4TB
Please read the Posting Guidelines before you post in this forum!.

Especially the part about enclosing code within code or php tags!!!


moderator
Mar 23 '07 #2
Please read the Posting Guidelines before you post in this forum!.

Especially the part about enclosing code within code or php tags!!!


moderator
Oo-er! Sorry about that, i'd edit it but it doesn't look like i can edit my post. If one of your moderators could edit it so that it conforms to your rules. I'm very sorry, i've just noticed the guidelines on the right hand side of my screen. I was in a bit of a rush to get a post up i didn't really pay much attention.

Sorry
Mar 23 '07 #3
ronverdonk
4,258 Expert 4TB
You have so many errors in your script that I cannot possibly show them all. A few of them are:

- what about the userid and password in your mysql_connect?
- the </title statement misses the &gt.
- miss the action in the <form> statement
- no action in the submit input stmt
- no enclosing quotation marks in the POST array assignments
- how to upload the picture??
- how do you know that the form is submitted?
- what are the data types doing in the insert statement values?
- etc.

Btw: your script is heaven for a hacker! You can specify anything and you store it unchecked and unvalidated in your db!

So, instead of addressing all errors, I show you the code that works somehow (but not for the image upload). You'll have to adapt this to your own requirement.
[php]
<?php
if (isset($_POST['submitted'])) {
$name = trim(strip_tags($_POST['name']));
$address = trim(strip_tags($_POST['address']));
$postcode = trim(strip_tags($_POST['postcode']));
$telephone = trim(strip_tags($_POST['telephone']));
$email = trim(strip_tags($_POST['email']));
$picture = trim(strip_tags($_POST['picture']));
$dbid = mysql_connect ('localhost', 'xxx', 'yyy');
mysql_select_db("vwso",$dbid)
or die ("Cannot find database");
$query = "INSERT INTO `book` (`aid`, `name`, `address`, `postcode`, `telephone`, `email`, `picture`) VALUES (1, '$name', '$address', '$postcode', $telephone, '$email' , '$picture')";
$result = mysql_query($query,$dbid)
or die("INSERT error:".mysql_error());
echo 'Row inserted';
exit;
}
?>

<html>
<head>
<title>Data submission - db version</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Name: <input name="name" /><br />
Address: <input name="address" /><br />
Postcode: <input name="postcode" /><br />
Telno: <input name="telephone" /><br />
Email: <input name="email" /><br />
Picture:<br><input type="file" name="picture" size"80" /><br />

<br><input type="submit" name="submitted" value="Submit" ></form><br>

</body>
</html>
[/php]

Ronald :cool:
Mar 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Pete..... | last post by:
Hi all. I have made a webpage where there is a webform where people can fill in their personel information: The code is below: I want to transfer the data to a postgreSQL database ( I have...
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
7
by: | last post by:
I am having trouble figuring out to call a database INSERT procedure from a simple submit form. It appears I should use the onclick event to trigger the procedure called BUT when I do this I...
13
by: Schoo | last post by:
I have a VB.NET program called "Calendar" that has a menu on the top that opens up another form (like a pop-up box) on top of "Calendar". The pop-up box form is called "Memos" which is a...
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...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
4
by: marek zegarek | last post by:
Hello! I have strange and simple problem.... I am starting developer. I need to create webform, that will insert my data into SQL 2005 database. My idea is to make something like MS Access...
4
by: dac | last post by:
I am quietly going insane on this project. I've never worked on a project like this one before. All my previous sticky forms were for data entry, not editing. I don't know how to display the form...
1
by: fugaki | last post by:
Hi everyone I'm learning asp, and i downloaded this script to teach me how to post form data from a webpage to an access database. I put it on the server so i could make sure that it worked, and...
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: 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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.