Solved

PHP to submit values to MySQL

Posted on 2004-04-30
6
320 Views
Last Modified: 2010-04-17
I have a webpage which has lots of text boxes to enter information.  When pressing submit, that information is presented back to you on a second page.  As well as this, I want that data to be submitted into a MySQL database.  Does anyone know the code to make the data insert itself when pressing a submit button?

So far I have:



<form action="page2.php" method="POST">


Title:
<input type="text" name="title" size="4"/>
<br>
Firstname:
<input type="text" name="forname" size="56"/>
<br>

........

and

<input type="submit" value="Send"/>
0
Comment
Question by:j_byron
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:indigostark
ID: 10958688
$title = $_POST['title'];
$forname = $_POST['forname'];

// $host = hostname to the database
// $username = username to the database
// $password = password to the database
$dbLink = mysql_connect($host, $user, $password) or die ("Could not connect");;

// $sql = SQL INSERT STATEMENT (ie) INSERT INTO .... ... .. .
$result = mysql_query($sql, $dbLink);
0
 

Author Comment

by:j_byron
ID: 10958762
Do I need

$title = $_POST['title'];
$forname = $_POST['forname'];

as well as the

Title:
<input type="text" name="title" size="4"/>
<br>
Firstname:
<input type="text" name="forname" size="56"/>
<br>

Also, how do I get it do happen upon pressing the submit button?
0
 
LVL 4

Assisted Solution

by:indigostark
indigostark earned 125 total points
ID: 10959227
Have your HTML in a file called (for example) form.htm
===================================
<form name="form1" method="POST" action="nextpage.php" >
<input type="text" name="title" size="4"/>
<br>
Firstname:
<input type="text" name="forname" size="56"/>
<br>

etc .........

===========================
now in your file called nextpage.php
have the following

<?php
$title = $_POST['title'];
$forname = $_POST['forname'];

// $host = hostname to the database
// $username = username to the database
// $password = password to the database
$dbLink = mysql_connect($host, $user, $password) or die ("Could not connect");;

// $sql = SQL INSERT STATEMENT (ie) INSERT INTO .... ... .. .
$result = mysql_query($sql, $dbLink);

etc .........
?>
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:j_byron
ID: 10968000
There are no errors.  But the data is not getting into the database.

I have tried these two queries:

1)

$query = "INSERT INTO mytablename title,forname,...)VALUES('$title','$forname',....)";

Or

2)

$query = "INSERT INTO mytablename VALUES('$title','$forname',....)";

and in both cases:

$result = mysql_query($query,$conn);


Are those queries ok?
0
 

Author Comment

by:j_byron
ID: 10968013
1) I missed out the bracket:

$query = "INSERT INTO mytablename (title,forname,...)VALUES('$title','$forname',....)";
0
 
LVL 1

Accepted Solution

by:
darpangoel earned 125 total points
ID: 10975632
yeah the query looks ok

the syntax again is

$query = INSERT INTO $tablename VALUES ('$val1',$val2','$val3');
just put those value in the order of the fields .use  "describe $tablename;" or "select * from $tablename;"  to get the order of the fields.

you don't need the link_identifier ( the 2nd parameter )  use
if (!($result = mysql_db_query ( $query )))
            echo (mysql_error());
or do this
to test the query is working or not do this.
echo  the query and the copy paste it on the terminal. check if it works. if there are any errors rectify .

ne more doubts???
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now