d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Question Algorithym > Help
Add Reply New Topic New Poll
Member
Posts: 19
Joined: Sep 3 2013
Gold: 0.00
Sep 18 2013 07:59am
I want to ask a user a question they awnser and the page refreshes with a new question and the awnser is saved into a database,

http://test.dawsondesigns.org.uk/

that's how it's layed out but how would i go about creating a db and what code would i put in the HTML to make the page refresh & input data?
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Sep 18 2013 02:16pm
create a php file and pass it to your form's action...

so <form action="yourphp.php"/>

yourphp.php
Code
<?php
//Create a mysql connection
$con=mysqli_connect("yourhost.com","your_username","password123","your_database_name");
// Check connection
if (mysqli_connect_errno())
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

//query returns a boolean, true if successfull, false if it fails.
if(!mysqli_query($con,"INSERT INTO Answers (User, Answer)
VALUES ('$_POST[name]','$_POST[answer]')")){
 die('Error: ' . mysqli_error($con));
}

//redirect back to the page
header("location: http://test.dawsondesigns.org.uk/");

?>


Something like that should work
Member
Posts: 19
Joined: Sep 3 2013
Gold: 0.00
Sep 19 2013 08:36am
I've created the form in html at ' test.dawsondesigns.org.uk' and want whatever i submit there to go into a sql database, after submitting your name and contact info the page needs to re direct to questions on another page and they need to then go into the sql...

if anyone has any advice/links to get me filling a form to sql.
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Sep 19 2013 09:56am
Quote (Daawsy @ Sep 19 2013 10:36am)
I've created the form in html at ' test.dawsondesigns.org.uk' and want whatever i submit there to go into a sql database, after submitting your name and contact info the page needs to re direct to questions on another page and they need to then go into the sql...

if anyone has any advice/links to get me filling a form to sql.


You have to use php. Just look at the code I posted.

All you have to do is copy and paste and change the form ids (name, answer) to your form ids. And change the database name, username, password, table name, and columns to yours.

That's as simple as it gets. If you want more info, go here http://www.w3schools.com/php/php_mysql_insert.asp
Member
Posts: 19
Joined: Sep 3 2013
Gold: 0.00
Sep 20 2013 02:51am
I'm getting this error though?

Code
Failed to connect to MySQL: Access denied for user 'dawsonde_test'@'localhost' (using password: YES)Error:


using this

Code
<?php
//Create a mysql connection
$con=mysqli_connect("localhost","dawsonde_admin","pass1","dawsonde_survey");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

//query returns a boolean, true if successfull, false if it fails.
if(!mysqli_query($con,"INSERT INTO Answers (fullname, phone)
VALUES ('$_POST[name]','$_POST[answer]')")){
die('Error: ' . mysqli_error($con));
}

$sql="INSERT INTO Persons (fullname, phone)
VALUES
('$_POST[fullname]','$_POST[phone]')";

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

mysqli_close($con);
?>


E: this is a web sql i'm trying to loginto

This post was edited by Daawsy on Sep 20 2013 02:52am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll