Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP to submit values to MySQL

Posted on 2004-04-30
6
Medium Priority
?
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 375 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 375 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

610 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