Script needed to add data via web page
Moderator: General Moderators
Script needed to add data via web page
I have a database, call it "data". There's a table in it called "movies". The parameters for the entries is :
Title varchar (50) not null, primary key
genre (enum - horror, action, comedy, etc)
format (enum - dvd, video, vcd, etc)
no of cd's (int 2 unsigned).
I have written a script whereby I enter the whole INSERT query and it works, but I am trying to write a script where I can just enter the values into a web page, hit submit, and it enters the values into the database. I have tried a variety of script attempts, but have got nowhere !!! I admit I am a complete noobie at this, and have been trying to learn this for a week (I hadent even tried html until last week).
Can anybody help, or even post a script that they use that I could edit ??
Thanks in advance.
Pha3dr0n
Title varchar (50) not null, primary key
genre (enum - horror, action, comedy, etc)
format (enum - dvd, video, vcd, etc)
no of cd's (int 2 unsigned).
I have written a script whereby I enter the whole INSERT query and it works, but I am trying to write a script where I can just enter the values into a web page, hit submit, and it enters the values into the database. I have tried a variety of script attempts, but have got nowhere !!! I admit I am a complete noobie at this, and have been trying to learn this for a week (I hadent even tried html until last week).
Can anybody help, or even post a script that they use that I could edit ??
Thanks in advance.
Pha3dr0n
make the fields in html...
call them
then put this between your <form> and </form>
and use this query/script
hope that helps
call them
Code: Select all
title
genre
format
noCode: Select all
<input type='hidden' name='ready'>Code: Select all
<?php
if(IsSet($ready))
{
$sql - mysql_query("insert into movies values('$title','$gener','$format','$no'");
}
?>Include this in your page that you're going to submit the data:-
Then have this code at the top of your form page:-
Then the data will be inserted!
Code: Select all
<form action="<?=$PHPSELF ?>" method="POST">
<input type="text" name="title">
<input type="text" name="genre">
<input type="text" name="format">
<input type="text" name="no">
<input type="hidden" name="ready">
<input type="submit" value="Submit!">
</form>Code: Select all
<?php
if(isset($_POSTї"ready"])) {
$sql = "INSERT INTO movies VALUES ('".$_POSTї"title"]."','".$_POSTї"genre"]."','".$_POSTї"format"]."','".$_POSTї"no"]."')";
mysql_query($sql);
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You probably want to change:
to
in case register globals is turned off either in your or your hosts version of PHP.
Mac
Code: Select all
<form action="<?=$PHPSELF ?>" method="POST">Code: Select all
<form action="<?php echo $_SERVERї'PHPSELF']; ?>" method="POST">Mac