What the webpage would do is after clicking "SUBMIT" button, a php script will be use to add records into my database. But for now i do not know where to put the "signupinsert.php" into the html and to make it run. I have try putting it at form action = "signupinsert.php".

The HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Text Processing</title>
<link type="text/css" rel="stylesheet"  href="scripts/mainstyle.css" />
</head>
<body>

<table width="100%" border="0">
  <tr>
    <td width="200"><img src="images/logo.png" /></td>
    <td>
<div id='formbox'> 
<form action="signupinsert.php" method="post">
<strong>User Account Request Form</strong><br /><br />
<table width="600" border="0">
  <tr>
    <td width="200">Name:</td>
    <td><input name="name" type="text" size="30"/></td>
    <td>Department:</td>
    <td><input name="department" type="text" size="30"/></td>
  </tr>
  <tr>
    <td width="200">E-mail Address:</td>
    <td><input name="email" type="text" size="40"/></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td width="200"><input name="submitbtn" type="button" value="Submit" /></td>
    <td><input name="cancelbtn" type="button" value="Cancel" /></td>
    <td></td>
    <td></td>
  </tr>
</table>
</form>
</div> 
    </td>
  </tr>
</table>
</body>
</html>

The PHP Script "signupinsert.php" that connects the database and input some data

<html>
<body>

<?php
$con = mysql_connect("localhost:3306","root","12345678");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("team18", $con);

$sql="INSERT INTO userprofile (name, department, email_pk)
VALUES
('$_POST[name]','$_POST[department]', '$_POST[email]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?>

</body>
</html>

Please Help, im stuck in this for week and could not find the right solution to it.
Thanks

Recommended Answers

All 5 Replies

In your HTML, change the input type from "button" to "submit".

<input name="submitbtn" type="submit" value="Submit" />

Thank you JorgeM. The button is working now, and submission to Mysql is successful.

But there is another problem which i encounter. After running the php script and data's been transferred to Mysql, the web page will be on the same page.

How should i "href" or put a link to it so that the page will be automatically change to for example "index.html" ?

But you have some logic in the PHP page to provide the user with feedback regarding the SQL, "1 record added".

If you automatically redirect the user, the user isn't going to see this message. Or are you thinking to redirect the user after a few seconds? What is the flow you are trying to achieve?

Hmm, i think the delay of a few seconds before redirection is a good suggestion, so that the user know that records has been sucessfully added before redirecting.

But how should i code it or where should i code it ? PHP or HTML ?
Confused..

is a good suggestion

Not necessarily saying this is the best course of action in my opinion after submitting a form, but that really depends on the application and what you are doing for the user. Some users are anoyed when you redirect them. Others can be anoyed if you dont provide enough info on the page and they dont know what to do next, so its up to you.

If you want to redirect a user after a certain amount of time, you can easily do it using javascript. Take a look at this recent discussion which was related to redirecting the user to a random page. You can use this example, minus the logic for the random part. It also includes a timer and a progress bar.

http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/467181/delayed-auto-redirect-to-a-random-url.-just-a-little-help-needed

I also have a link there to a demo so you can see how it was used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.