Need Help with simple php script using MySQLNeed help implementing this
Page 1 of 1
10 Replies - 567 Views - Last Post: 05 April 2009 - 10:23 PM
#1
Need Help with simple php script using MySQL
Posted 04 April 2009 - 02:32 PM
I want to know how it is possible to do the forms in php to submit it to the database?
Replies To: Need Help with simple php script using MySQL
#2
Re: Need Help with simple php script using MySQL
Posted 04 April 2009 - 03:00 PM
The form is to be posted on the same page.
When the form is not filled, it should show the empty form layout and after it is filled and posted, it should show the table. Here use if-else statement.
here is sample-
<?php
if (isset($_POST[posted])) {
Show the table
And a link to insert more data
} else {
?>
<h2>Please fill out this form</h2>
<form method="POST" action="<?php $PHP_SELF ?>">
<input type="hidden" name="posted" value="true">
Form Data
<input type="submit" value="Send Info">
</form>
<?php
}
?>
#3
Re: Need Help with simple php script using MySQL
Posted 04 April 2009 - 03:02 PM
#4
Re: Need Help with simple php script using MySQL
Posted 04 April 2009 - 03:05 PM
#5
Re: Need Help with simple php script using MySQL
Posted 05 April 2009 - 06:10 PM
<?php
// GET?
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
// Show form
echo ("<html>");
echo ("<head></head>");
echo ("<body>");
echo("<h1>New Course</h1>");
echo("Enter a new course");
echo ("<br><br>");
echo("<form method = POST action = courses.php>");
echo("ID: ");
echo("<input type = text name = ID ");
echo("<br>");
echo ("Dept:");
echo("<input type = text name = Dept ");
echo("<br>");
echo ("Num:");
echo("<input type = text name = Num ");
echo("<br>");
echo ("Title:");
echo ("<input type = text name = title ");
echo("<br>");
echo ("Instructor:");
echo("<input type = text name = instruct ");
echo("<br>");
echo("<input type =submit value = save>");
echo("</body>");
echo ("</html>");
}
else
{
// POST
$hostname = 'taz';
$username = 'fmccown';
$password = 'frank';
mysql_connect($hostname, $username, $password);
$database = 'fmccown';
mysql_select_db($database);
// Insert
$query = "INSERT INTO courses VALUES ($_POST[courseid], $_POST[dept] ...etc...";
$query = "SELECT * FROM courses order by dept";
$result = mysql_query($query) or die(mysql_error() . "<br>query = $query<br>");
print "<table border=1>";
// Same thing using an associative array
while ($row = mysql_fetch_array($result))
echo "<tr><td>$row[courseid]</td><td>$row[dept]</td><td>$row[num]</td></tr>\n";
print "</table>";
print "<p>That's it.</p>";
}
#6
Re: Need Help with simple php script using MySQL
Posted 05 April 2009 - 06:45 PM
echo("<form method = POST action='$_SERVER[PHP_SELF]' ");
Instead of
echo("<form method = POST action = courses.php>");
#7
Re: Need Help with simple php script using MySQL
Posted 05 April 2009 - 06:46 PM
This post has been edited by Zerobu: 05 April 2009 - 06:47 PM
#8
Re: Need Help with simple php script using MySQL
Posted 05 April 2009 - 06:52 PM
#9
Re: Need Help with simple php script using MySQL
Posted 05 April 2009 - 06:58 PM
like in the example
I'm having trouble with the SQL statements to insert tables and place data in the table
This post has been edited by Zerobu: 05 April 2009 - 06:56 PM
#10
Re: Need Help with simple php script using MySQL
Posted 05 April 2009 - 06:58 PM
#11
Re: Need Help with simple php script using MySQL
Posted 05 April 2009 - 10:23 PM
Like SQL to create a table
CREATE TABLE tablename (varname1 VARCHAR(10), varname2 VARCHAR(10), varID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY)
or do you want PHP or both?
This post has been edited by TechWar: 05 April 2009 - 10:25 PM
|
|

New Topic/Question
Reply




MultiQuote





|