Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2004, 02:18 PM
Authorized User
 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to IP076
Default PHP Form Question

I have the following code which creates a form on a webpage:

<?php
require('config.php');

$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
 or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB,$conn);

$sql = "SELECT member_main.member_id, firstname, lastname FROM member_main
        INNER JOIN member_event_link ON member_event_link.member_id = member_main.member_id
        WHERE member_event_link.event_id='4'";

echo "<table border='1' width='70%'><form action='http://www.geft-online.org/testentry.php' method='POST'>
        <tr><th align='center'>Member</th><th align='center'>Number Correct</th><th align='center'>
        Elapsed Time</th></tr>";

$result=mysql_query($sql) or die(mysql_error());
while ($rows = mysql_fetch_array($result)) {
    $member_id = $rows['member_id'];
    $firstname = $rows['firstname'];
    $lastname = $rows['lastname'];
    $fullname = $firstname . " " . $lastname;

    echo "<tr>
    <td>$fullname</td>
    <td><input type='text' name='correct$member_id'></td>
    <td><input type='text' name='et$member_id'></td>
    </tr>";}

        echo "<tr><td colspan='3' align='center'><input type='submit' value='submit'>
    </td></tr></from></table>";
?>

This code generates a line on a form for each of the rows returned in the query.

I'm running into difficulty creating the page that will enter the information in the form into my database.

I know all I need to do is create a string that would fit into the VALUES section of an INSERT sql statement. I'm just a little confused as how to do this with a variable number of lines on the form. Any suggestions would be greatly appreciated.

Thank you!

 
Old December 8th, 2004, 05:12 AM
Authorized User
 
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Hmmmmmmm you could possibly generate the SQL INSERT statement on the fly, using a loop somehow, which goes by the number of lines in the form.

Many shoes,

Jamez/SiliconFuRy





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Installation question EnderX PHP How-To 0 November 9th, 2006 09:47 AM
Passing FORM to FORM to PHP AV1611 PHP Databases 1 August 17th, 2005 03:32 PM
PHP *hosting* question cutesneakers PHP How-To 3 January 5th, 2005 08:35 PM
PHP real question jimmychuck BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 September 14th, 2004 11:58 AM
php question hosefo81 PHP How-To 1 January 28th, 2004 02:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.