Jump to content

mysql database and html fields


Scud

Recommended Posts

Hey guys;

i dont have much knowledge about mysql and php as such, however i was wondering if it was possible and how to do it, so that if a user enters details in a form field on my webpage, what code i need to send this data to the database as well as if someone wants to call up their data by entering a code and it bring up the info stored in a field in the database. Please as simple as possible, lol

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/97047-mysql-database-and-html-fields/
Share on other sites

Simply Google PHP tutorials and start reading for a couple of hours, past programming experience would be a bonus (VB, C++, Java) as the language is similar to these. I could post a script, but if you want to implement it correctly and understand how it works your much better learning the tutorials and coming up with your own script. What your asking is a very easy thing to learn, it gets more complex when you have to learn about Security, etc.

You should read up on some simple SQL Tutorials

 

Assuming you have a Database and are connected. The database has a table with users (ID,Name,Surname)

And you have a form that directs to the folowing PHP file. The form has the fields "Name" and "Surname" and submits using "POST".

$name = $_POST["Name"];
$surname = $_POST["Surname"];
$query = "INSERT INTO users (Name,Surname) VALUES ('$name','$surname')";
mysql_query($query) or die("Error inserting ".mysql_error());
echo "Your magic user ID is: ".mysql_inser.id();

 

To get the user info let them input their ID (in a form field named id) and post the form to a PHP file like this:

 

$id = $_POST["id"]
$query = "SELECT * FROM users WHERE ID='$id'";
$result = mysql_query($query) or die("Error reading Data! ".mysql_error());
$values = mysql_fetch_assoc($result);
echo "You are ".$values["Name"]." ".$values["Surname"]; 

 

Dont use the above script for a Public site though as it is Vunerable to all sorts of Malious attacks (MySQL Injection, etc). YOu'd have to parse the data sent by the user first in order for it to be put in a database securely.

thanks for the quick responses. i have vb experience only.  its all so confusing, could somebody please write up a pretty secure script so i can read and write to the database, im lost! also what code do i put in the html file to say when the submit button is clicked send the data to database?

could somebody please write up a pretty secure script so i can read and write to the database, im lost!

 

i think that's a job for the Freelance section of these forums.. this section is for people who want's to make their own script but need some guidance

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.