Jump to content

Recommended Posts

Hi Guys,

 

I am trying to build a form in php to insert data into mysql database.

 

The fields can be name, staff number, department for a start.

 

Can some one please give me a script to do this and also to display the data from the database on to a php page.

 

Any help much appreciated. Please help.

 

Thanks Guys.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/86630-php-form/
Share on other sites

What a horrible bunch. I can't believe how unhelpful that is...

Anyway, here you go:

 

name

staff number

department

 

<?php
$db_host = "localhost";
$db_user = "Database Username Here";
$db_pwd = "Database Password Here";
$db_name = "Database Name Here";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>

<h2>Database Submission Form</h2>

  <?php
if (!isset($_POST['submit'])) {
?>

<form action="" method="post">

<p>Name:<br>
<input type="text" name="name" id="name"></p>

<p>Staff Number:<br>
<input type="text" name="staffnumber" id="staffnumber"></p>

<p>Department:<br>
<input type="text" name="department" id="department"></p>

<input type="submit" name="submit" value="Submit New Item">
<input name="reset" type="reset" id="reset2" value="Clear Form">

</form>

<?php
} else {
$name = $_POST['name'];
$staffnumber = $_POST['staffnumber'];
$department = $_POST['department'];
mysql_query("INSERT INTO `tablenamehere` (name, staffnumber, department) VALUES ('$name', '$staffnumber', '$department')");
echo "Successfully Submitted!";
}
?>

 

The Above code is a simple form that submits data to the chosen database and table. Change the values where needed.

 

OK, so now we need to SHOW the data that is in the database.

I'm not sure what format you want this in, so I'll put it in a table.

 

ILL FINISH THIS LATER

Link to comment
https://forums.phpfreaks.com/topic/86630-php-form/#findComment-442860
Share on other sites

Thanks a million Malevolence...i am a new bie to php and learning it still. I had an urgent need of this form though simple but me completely clueless. I understand the other 2 they just wanted me to learn which i am. Atleast i know i can get help is some form. Again thank you thank you thank you guys.

Link to comment
https://forums.phpfreaks.com/topic/86630-php-form/#findComment-443328
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.