Question

php generated form, how to insert into mySql? php5, mySql

Asked by: MHenry

I may be going about this all wrong...

I built a way to generate a form based on how many registrations a person has paid for. There are a bunch of different scenarios, so I built it to generate the form as a check to make sure they only get what they paid for. I also made it so that each field's id is auto increments.

So, the form generated looks like
id=firstName12
id=firstName13
id=lastName21
id=lastName22
etc.

Now, I need a way to insert the results of the form into a mySql table.

Is there a way to build a looping insert statement in php that is similar to an "insert where firstName is like..." like you can do in SQL?

Thanks,
MH

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-03-07 at 23:02:02ID24209732
Tags

php mysql

Topics

PHP Scripting Language

,

PHP and Databases

Participating Experts
2
Points
500
Comments
46

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. php mysql
    Please tell me the graphical tool to write code between php and mysql

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: agamalPosted on 2009-03-07 at 23:18:28ID: 23828319

sure there is a way  ... can i see a sample of your form code and i will send you a sample code to do you the looping insert

 

by: agamalPosted on 2009-03-07 at 23:21:10ID: 23828328

mainly we can use $_REQUEST['something']  to show the variables have been sent by the form

try

var_export($_REQUEST);

in the page receiving form data

 

by: MHenryPosted on 2009-03-07 at 23:30:32ID: 23828354

agamal,

Wasn't sure which sample you're looking for so...

Here's a sample of what generates the form:


switch ($data[1])
    {
    case ($data[1]= 60):
         while ($j <= $data[2]) {
                  echo '<tr align="center">
                        <td><input type="text" name="firstName'.$x.$j.'" size="10" id="firstName'.$x.$j.'">
                        <td><input type="text" name="lastName'.$x.$j.'" size="10" id="lastName'.$x.$j.'">
                        </td>
                        <td><input type="text" name="badgeName'.$x.$j.'" size="10" id="badgeName'.$x.$j.'">
                        </td>
                        <td><label>
                         <input name="membTye" type="text" id="membTye'.$x.$j.'" value="3-day Adult Pass">
                      </label>
                        <td><input type="text" name="emailAddr'.$x.$j.'" size="14" id="emailAddr'.$x.$j.'"></td>
                         </tr>
                        <br />';
             $j++;
             }
             $j=1;
             break;


And here's a sample of the form.

<tr align="center">
                        <td><input type="text" name="firstName11" size="10" id="firstName11">
                        <td><input type="text" name="lastName11" size="10" id="lastName11">
                        </td>

                        <td><input type="text" name="badgeName11" size="10" id="badgeName11">
                        </td>
                        <td><label>
                         <input name="membTye" type="text" id="membTye11" value="3-day Adult Pass">
                      </label>
                        <td><input type="text" name="emailAddr11" size="14" id="emailAddr11"></td>
                         </tr>
                        <br /><tr align="center">
                        <td><input type="text" name="firstName12" size="10" id="firstName12">

                        <td><input type="text" name="lastName12" size="10" id="lastName12">
                        </td>
                        <td><input type="text" name="badgeName12" size="10" id="badgeName12">
                        </td>
                        <td><label>
                         <input name="membTye" type="text" id="membTye12" value="3-day Adult Pass">
                      </label>
                        <td><input type="text" name="emailAddr12" size="14" id="emailAddr12"></td>
                         </tr>
<tr align="center">
                        <td><input type="text" name="firstName21" size="10" id="firstName21">
                        <td><input type="text" name="lastName21" size="10" id="lastName21">
                        </td>
                        <td><input type="text" name="badgeName21" size="10" id="badgeName21">
                        </td>
                        <td><label>
                         <input name="membTye" type="text" id="membTye21" value="3-day Student Pass">
                      </label>

                        <td><input type="text" name="emailAddr21" size="14" id="emailAddr21"></td>
                         </tr>
                        <br />
                        </div><tr align="center">
                        <td><input type="text" name="firstName22" size="10" id="firstName22">
                        <td><input type="text" name="lastName22" size="10" id="lastName22">
                        </td>
                        <td><input type="text" name="badgeName22" size="10" id="badgeName22">
                        </td>

                        <td><label>
                         <input name="membTye" type="text" id="membTye22" value="3-day Student Pass">
                      </label>
                        <td><input type="text" name="emailAddr22" size="14" id="emailAddr22"></td>
                         </tr>



Thanks,
MH

 

by: agamalPosted on 2009-03-07 at 23:52:01ID: 23828380

which way do you use post or get ???

 

by: MHenryPosted on 2009-03-07 at 23:53:35ID: 23828385

I was planning on using Post. Would there be a reason to use get instead?

 

by: agamalPosted on 2009-03-08 at 00:07:13ID: 23828407

just to know the right variable to use


you will need to build your insert statment using $query like
<pre class="programlisting">INSERT INTO <code>tbl_name</code> (col1,col2,col3,col4,col5) VALUES("$query[0],$query[1],$query[2],$query[3],$query[4],");

</pre>

<?php
$i = 0;
foreach ($_POST as $key => $value){
$query[] = $value;
if ($i == 4) {
//run the query here using $query[0] to $query[4]
 
 
$query = array();
$i = 0;
} else { $i++ ;}
}
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

 

by: agamalPosted on 2009-03-08 at 00:08:57ID: 23828411

BTW i think you need to work on your form ... because you have fileds with name="membTye" ... i believe 4 fields with the same name ... that will result in sending only the last one of them


if you want help in this i will be happy to help you in another question regarding this .......

 

by: NerdsOfTechPosted on 2009-03-08 at 05:24:02ID: 23829102

1.) You should consider using current best practices and drop the dependency on PHP derived IDs and use an auto increment column (database dependency) for your IDs

2.) You should use [ and ] after the input
<input name="firstname[]">
This will effectively create an array

You can cycle through the arrays to obtain essentially "rows" to insert to a table (which of course you would loop it through a SQL INSERT per "row"

3.) Lastly you SHOULD reference the group in a way such that the group will control the offspring records

Example Structure:

*** first we auto increment the group ***
Group ID
GroupID, FirstName, LastName, Email // MAIN CONTACT
1, John, Doe, john@fake.com
2, John, Smith, john@fakes.com
3, Charlie, Brown, harlie@faker.com

*** Then we auto increment the attendees ***

where the badgeID is autoinremented by database automatically and the group can be referenced by groupID which was previously auto incremented by main contact.

tblGroup: // ATTENDEES
BadgeID, GroupID, FirstName, LastName, Email, TypePass
1, 1, John, Doe, john@fake.com, Adult 3-Day Pass
2, 1, Jane, Doe, jane@fake.com, Adult 3-Day Pass
3, 1, Johny, Doe, johny@fake.com, Student 3-Day Pass
4, 1, Janey, Doe, janey@fake.com, Student 3-Day Pass
5, 2, John, Smith, john@fakes.com, Adult 3-Day Pass
6, 2, Jake, Smith, jake@fakes.com, Student 3-Day Pass
7, 3, Charlie, Brown, charlie@faker.com, Student 3-Day Pass

This type of 1:M (1-to-many) structure is a reliable setup for this type of a job.

=NerdsOfTech

<input name="firstname[]">
<input name="lastname[]">
...

                                              
1:
2:
3:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-08 at 05:34:55ID: 23829136

Actually on second thought as far as the form generation goes I would just stick with one incrementing value for the sets and leave the ID creation to the database as mentioned before.

$x=0;
echo '<input name="firstname'.$x.'">';
$x++;

On the processing page:
Create group then
Loop through each set of names and insert badges

=NerdsOfTech

 

by: MHenryPosted on 2009-03-08 at 09:12:32ID: 23829836

NerdsOfTech,

I like your idear of the array, but just to be verify:

I tried sticking with just one value, but I have to loop through the switch/case statements in case the quantity is more than one. So that loop would create the same values.

For example, if the first case has quantity 2, it would do firstName1 and firstName2. Then if case 2 has quantity 1, because of the loop going through the second time, it would also generate firstName2.

Would the array you're talking about work inside this other loop? Or is there a better way for the case/switch?

Best,
MH

 

by: MHenryPosted on 2009-03-08 at 09:34:01ID: 23829944

agamal,

I'm not sure what you mean about membtye, looks like all of them have different names? I'll give your suggestion a shot and see if it works this afternoon.

Best,
MH

 

by: MHenryPosted on 2009-03-08 at 20:27:52ID: 23832954

agamal,


I've been trying the following but it doesn't appear to be working. I have a feeling it's the insert statement?

<?php

//Connect To Database
mysql_select_db($database_myConn, $myConn);
      
$i = 0;
foreach ($_POST as $key => $value){
$query[] = $value;
if ($i == 4) {
//run the query here using $query[0] to $query[4]
$query = 'INSERT INTO attendeenames (col1,col2,col3,col4,col5) VALUES("$query[0],$query[1],$query[2],$query[3],$query[4],")';
 
$query = array();
$i = 0;
} else { $i++ ;}
}
?>

Best,
MH

 

by: MHenryPosted on 2009-03-08 at 20:32:33ID: 23832978

NerdsOfTech,

I'd like to try your idea as well, but I'm not sure how to start. Could you give me a sample?

Thanks,
MH

 

by: agamalPosted on 2009-03-09 at 09:30:45ID: 23837600

please give me a complete example code of form and i will tell you what i mean ???


sorry for being late

 

by: MHenryPosted on 2009-03-09 at 18:13:35ID: 23842796

Here's the form

<form action="submitReg.php"  method="POST">
<table border="0" cellspacing="0" cellpadding="2" width="80%" align="top">
<?php
mysql_select_db($database_myConn, $myConn);
$datax = array();
$datay = array();
$dataz = array();
$cartNumber = $_SESSION["CartId"];
$query = "SELECT tbl_cart.cart_custcart_ID AS cartNumber, tbl_cart.cart_sku_ID AS orderSKU, tbl_cart.cart_sku_qty AS quantity FROM tbl_cart WHERE tbl_cart.cart_custcart_ID = '$cartNumber'";

  if ($result = mysql_query($query)) {
$x=1;
$j=1;
while($data = mysql_fetch_array($result, MYSQL_NUM)) {
  $var_name='cartNumber'.$x;
  $$var_name = $data[0];
  $var_name='orderSKU'.$x;
  $$var_name = $data[1];
  $var_name='quantity'.$x;
  $$var_name = $data[2];
 
  switch ($data[1])
   {
   case ($data[1]= 60):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Adult Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />';
        $j++;
        }
        $j=1;
        break;
   case ($data[1]= 61):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Student Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />
               </div>';
        $j++;
        }
        $j=1;
        break;                        
   case ($data[1]= 62):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Child Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />
               </div>';
        $j++;
         }
        $j=1;
        break;
   case ($data[1]= 63):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="Friday Only Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />
               </div>';
        $j++;
        }
        $j=1;
        break;
   }

$x++;
           
}  
 }
?>
</table>
<input name="submitReg" type="button" value="submit" />
</form><form action="submitReg.php"  method="POST">
<table border="0" cellspacing="0" cellpadding="2" width="80%" align="top">
<?php
mysql_select_db($database_myConn, $myConn);
$datax = array();
$datay = array();
$dataz = array();
$cartNumber = $_SESSION["CartId"];
$query = "SELECT tbl_cart.cart_custcart_ID AS cartNumber, tbl_cart.cart_sku_ID AS orderSKU, tbl_cart.cart_sku_qty AS quantity FROM tbl_cart WHERE tbl_cart.cart_custcart_ID = '$cartNumber'";

  if ($result = mysql_query($query)) {
$x=1;
$j=1;
while($data = mysql_fetch_array($result, MYSQL_NUM)) {
  $var_name='cartNumber'.$x;
  $$var_name = $data[0];
  $var_name='orderSKU'.$x;
  $$var_name = $data[1];
  $var_name='quantity'.$x;
  $$var_name = $data[2];
 
  switch ($data[1])
   {
   case ($data[1]= 60):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Adult Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />';
        $j++;
        }
        $j=1;
        break;
   case ($data[1]= 61):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Student Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />
               </div>';
        $j++;
        }
        $j=1;
        break;                        
   case ($data[1]= 62):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Child Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />
               </div>';
        $j++;
         }
        $j=1;
        break;
   case ($data[1]= 63):
        while ($j <= $data[2]) {
           echo '<tr align="center">
               <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
               <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
               <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
               </td>
               <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
               </td>
               <td><label>
                <input name="membType" type="text" id="membType'.$x.$j.'" value="Friday Only Pass">
               </label>
               <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                </tr>
               <br />
               </div>';
        $j++;
        }
        $j=1;
        break;
   }

$x++;
           
}  
 }
?>
</table>
<input name="submitReg" type="button" value="submit" />
</form>

 

by: MHenryPosted on 2009-03-09 at 21:11:49ID: 23843545

And here's what I've been trying for the submit action

<?php

$i = 0;
foreach ($_POST as $key => $value){
$newQuery[] = $value;
if ($i == 4) {
//run the query here using $query[0] to $query[4]

$newQuery=mssql_query('INSERT INTO attendeenames (customerID_cart,firstName,lastName,badgeName,email,membType) VALUES ("$newquery[0]","$newquery[1]","$newquery[2]","$newquery[3]","$newquery[4]","$newquery[5]")');  

$newQuery = array();
$i = 0;
} else { $i++ ;}
}
?>

 

by: agamalPosted on 2009-03-09 at 23:48:24ID: 23843992

a complete data base dump please

 

by: MHenryPosted on 2009-03-10 at 06:59:15ID: 23846726

Not sure what you mean by database dump?

The table this is going into has no dependencies foreign keys or anything. It's just a floating table until I can figure out a better solution.

Right now, that table is empty and is staying empty because I can't get this insert to work! ;)

It has:
attendeeID as the ID field, customerID_cart, firstName, lastName, badgeName, email, membType

All the fields except for attendeeID are setup as varChar 150.

Is that enough?



Best,
MH

 

by: MHenryPosted on 2009-03-10 at 07:00:11ID: 23846736

The strange thing is when I hit submit, nothing happens. I mean nothing. No error message, doesn't attempt to go to another page. Just acts like a button with no code attached to it.

Best,
MH

 

by: NerdsOfTechPosted on 2009-03-10 at 14:43:39ID: 23851817

Yikes forget that!

1.) Output code improvement (less work = less errors)
What you need is a while loop with 1 switch for the sku inside of the loop.

2.) Next I would build the table as I suggested before with a tblGroup that will recieve the auto ID via the database and loop through the array to tblBadge (using the Group ID as a foregin key) for the individual badges.

3.) As I corrected myself earlier [ and ] won't work in this case becuase if one field is empty it will gap inside the array (giving an undesirable result); thus, I would say only reserve [ and ] for checkboxes (mulitple selection)

=NerdsOfTech

echo '<tr align="center">';
echo '<td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">';
 
$x=1;
while($data = mysql_fetch_array($result, MYSQL_NUM)) {
echo '<td><input type="text" name="firstName'.$x.'" size="10">
      <td><input type="text" name="lastName'.$x.'" size="10">
      </td>
      <td><input type="text" name="badgeName'.$x.'" size="10">
      </td>
      <td><label>';
 
 switch ($data[1]){
  case ($data[1]= 60):
   echo '<input name="membType'.$x.'" type="text" value="3-day Adult Pass">';
   break;
  case ($data[1]= 61):
   echo '<input name="membType'.$x.'" type="text" value="3-day Student Pass">';
   break;
  case ($data[1]= 62):
   echo '<input name="membType'.$x.'" type="text" value="3-day Child Pass">';
   break;
  case ($data[1]= 63):
   echo '<input name="membType'.$x.'" type="text" value="3-day Friday Pass">';
   break;
 }
 echo '</label>
       <td><input type="text" name="emailAddr'.$x.'" size="14"></td>
       </tr>
       <br />
       </div>';
 $x++;
}
echo '</table>
      <input name="submitReg" type="button" value="submit" />
      </form>';

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-10 at 14:49:38ID: 23851878

I added the maxRows input so that in your code you can double check the maximum "rows" you will need to insert to tblBadges.

Basically after you create your groupid in tblGroup (1 insert) you can loop the badges and insert into tblBadges the information (let the database auto increment BadgeID) letting the GroupID foreign key of tblBadges be the connection for your badges "group".

Previous Quote:
"
Example Structure:

*** first we auto increment the group ***
Group ID
GroupID, FirstName, LastName, Email // MAIN CONTACT
1, John, Doe, john@fake.com
2, John, Smith, john@fakes.com
3, Charlie, Brown, harlie@faker.com

*** Then we auto increment the attendees ***

where the badgeID is autoinremented by database automatically and the group can be referenced by groupID which was previously auto incremented by main contact.

tblGroup: // ATTENDEES
BadgeID, GroupID, FirstName, LastName, Email, TypePass
1, 1, John, Doe, john@fake.com, Adult 3-Day Pass
2, 1, Jane, Doe, jane@fake.com, Adult 3-Day Pass
3, 1, Johny, Doe, johny@fake.com, Student 3-Day Pass
4, 1, Janey, Doe, janey@fake.com, Student 3-Day Pass
5, 2, John, Smith, john@fakes.com, Adult 3-Day Pass
6, 2, Jake, Smith, jake@fakes.com, Student 3-Day Pass
7, 3, Charlie, Brown, charlie@faker.com, Student 3-Day Pass

This type of 1:M (1-to-many) structure is a reliable setup for this type of a job.
"

=NerdsOfTech

echo '<tr align="center">';
echo '<td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">';
 
$x=1;
while($data = mysql_fetch_array($result, MYSQL_NUM)) {
echo '<td><input type="text" name="firstName'.$x.'" size="10">
      <td><input type="text" name="lastName'.$x.'" size="10">
      </td>
      <td><input type="text" name="badgeName'.$x.'" size="10">
      </td>
      <td><label>';
 
 switch ($data[1]){
  case ($data[1]= 60):
   echo '<input name="membType'.$x.'" type="text" value="3-day Adult Pass">';
   break;
  case ($data[1]= 61):
   echo '<input name="membType'.$x.'" type="text" value="3-day Student Pass">';
   break;
  case ($data[1]= 62):
   echo '<input name="membType'.$x.'" type="text" value="3-day Child Pass">';
   break;
  case ($data[1]= 63):
   echo '<input name="membType'.$x.'" type="text" value="3-day Friday Pass">';
   break;
 }
 echo '</label>
       <td><input type="text" name="emailAddr'.$x.'" size="14"></td>
       </tr>
       <br />
       </div>';
 $x++;
}
echo '</table>
      <input name="maxRows" type"hidden" value="'.($x-1).'">
      <input name="submitReg" type="button" value="submit" />
      </form>';

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-10 at 14:50:39ID: 23851891

CORRECTION (Table Names)"
Example Structure:

*** first we auto increment the group ***
tblGroup
GroupID, FirstName, LastName, Email // MAIN CONTACT
1, John, Doe, john@fake.com
2, John, Smith, john@fakes.com
3, Charlie, Brown, harlie@faker.com

*** Then we auto increment the attendees ***

where the badgeID is autoinremented by database automatically and the group can be referenced by groupID which was previously auto incremented by main contact.

tblBadges: // ATTENDEES
BadgeID, GroupID, FirstName, LastName, Email, TypePass
1, 1, John, Doe, john@fake.com, Adult 3-Day Pass
2, 1, Jane, Doe, jane@fake.com, Adult 3-Day Pass
3, 1, Johny, Doe, johny@fake.com, Student 3-Day Pass
4, 1, Janey, Doe, janey@fake.com, Student 3-Day Pass
5, 2, John, Smith, john@fakes.com, Adult 3-Day Pass
6, 2, Jake, Smith, jake@fakes.com, Student 3-Day Pass
7, 3, Charlie, Brown, charlie@faker.com, Student 3-Day Pass

This type of 1:M (1-to-many) structure is a reliable setup for this type of a job.
"

 

by: MHenryPosted on 2009-03-10 at 14:51:46ID: 23851907


NerdsOfTech,

Looks like I copied the form in there twice. Sheesh. Too many late nights on this...

I'm not sure exactly what you mean by #2?
2.) Next I would build the table as I suggested before with a tblGroup that will recieve the auto ID via the database and loop through the array to tblBadge (using the Group ID as a foregin key) for the individual badges.

I don't know how to do that. It sounds great but I don't know what you mean or how to do it. Could you show a sample or provide a link that shows how?

By the way, if they leave a blank field, I would like to insert a blank space just as a placeholder. On another page, I intend to build a edit/update for the data. Got a way to do that too?


Thanks,

MH

 

by: NerdsOfTechPosted on 2009-03-10 at 14:57:23ID: 23851967

Therefore after the form is submitted:
1.) determine total badge quantity
2.) insert main contact into tblGroup (1 insert)
3.) get tblGroupID via mysql_insert_id() command
4.) loop through badge input data and insert into tblBadge (make sure GroupID foreign key is equal to result from 3)

That's the deal.

=NerdsOfTech

 

by: NerdsOfTechPosted on 2009-03-10 at 14:58:40ID: 23851980

Therefore after the form is submitted:
1.) determine total badge quantity
2.) insert main contact into tblGroup (1 insert)
3.) get tblGroupID via mysql_insert_id() command
4.) loop through badge input data and insert into tblBadge (make sure GroupID foreign key is equal to result from 3) for each badge (multiple individual inserts)

=NerdsOfTech

 

by: NerdsOfTechPosted on 2009-03-10 at 15:02:20ID: 23852012

To build those tables you would use your Control Panel tool to get access to your actual table structure and create table, etc.

Yeah if they enter nothing the field will be "" (EMPTY) so you are ok there.

 

by: NerdsOfTechPosted on 2009-03-10 at 15:03:45ID: 23852025

Anyways it looks like attendees is what is established... so let me see if I can work with what you got.

 

by: NerdsOfTechPosted on 2009-03-10 at 15:37:04ID: 23852266

Doh I almost forgot the explicit complex array syntax!

Try this out instead!

You wont need max rows becuase php will translate it as a multi-dimensional (nexted-associative) array you can get a count from!

Wow.. simply amazing!

Next ill show the processing

=NerdsOfTech

echo '<tr align="center">';
echo '<td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">';
 
$x=1;
while($data = mysql_fetch_array($result, MYSQL_NUM)) {
echo '<td><input type="text" name="badge['.$x.'][firstName]" size="10">
      <td><input type="text" name="badge['.$x.'][lastName]" size="10">
      </td>
      <td><input type="text" name="badge['.$x.'][badgeName]" size="10">
      </td>
      <td><label>';
 
 switch ($data[1]){
  case ($data[1]= 60):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Adult Pass">';
   break;
  case ($data[1]= 61):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Student Pass">';
   break;
  case ($data[1]= 62):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Child Pass">';
   break;
  case ($data[1]= 63):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Friday Pass">';
   break;
 }
 echo '</label>
       <td><input type="text" name="badge['.$x.'][emailAddr]" size="14"></td>
       </tr>
       <br />
       </div>';
 $x++;
}
echo '</table>
      <input name="submitReg" type="button" value="submit" />
      </form>';

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-10 at 15:50:59ID: 23852373

PROCESSING PAGE:

<?
foreach ($_POST["badge"] as $badge){ // each badge is one array itself
 
$sql = 'INSERT INTO attendeenames (customerID_cart,firstName,lastName,badgeName,email,membType) '; 
 
$sql .= 'VALUES ("'.$_POST["customerID_cart"].'","'.$badge["firstName"].'","'.$badge["lasstName"].'","'.$badge["badgeName"].'","'.$badge["email"].'","'.$badge["membType"].'")';
 
mssql_query($sql);
 
}
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-10 at 15:52:10ID: 23852383

CORRECTION: PROCESSING PAGE:

Needed to add the ";" at the end ;)

=NerdsOfTech

Sweet Challenge!

<?
foreach ($_POST["badge"] as $badge){ // each badge is one array itself
 
$sql = 'INSERT INTO attendeenames (customerID_cart,firstName,lastName,badgeName,email,membType) '; 
 
$sql .= 'VALUES ("'.$_POST["customerID_cart"].'","'.$badge["firstName"].'","'.$badge["lasstName"].'","'.$badge["badgeName"].'","'.$badge["email"].'","'.$badge["membType"].'");';
 
mssql_query($sql);
 
}
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-10 at 15:53:10ID: 23852390

CORRECTION: PROCESSING PAGE:
last name field mistyped

=NerdsOfTech

<?
foreach ($_POST["badge"] as $badge){ // each badge is one array itself
 
$sql = 'INSERT INTO attendeenames (customerID_cart,firstName,lastName,badgeName,email,membType) '; 
 
$sql .= 'VALUES ("'.$_POST["customerID_cart"].'","'.$badge["firstName"].'","'.$badge["lastName"].'","'.$badge["badgeName"].'","'.$badge["email"].'","'.$badge["membType"].'");';
 
mssql_query($sql);
 
}
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-10 at 15:54:28ID: 23852396

FINAL VERSION:

use post ID # 23852266 for form output
use post ID # 23852390 for form processing

=NerdsOfTech

Thanks for the challenge!

 

by: MHenryPosted on 2009-03-10 at 16:02:51ID: 23852465

NerdsOfTech,

Thanks for your efforts!

I do like the way you cleaned up the form.

I'm still a little unclear on what you mean by the tables but I'll give it a shot this evening.

Glad you think it's a challenge. To me, it's been one helluva headache! I got in over my head, but I guess that's how we learn...

Thanks again for the help,
MH

 

by: MHenryPosted on 2009-03-10 at 20:07:16ID: 23853650

NerdsOfTech,

Well, I wish it was better news...

It still doesn't do anything. I press the button and nothing happens.

Worse though, as  items are added, it no longer gets the quantity. It only creates one line in the form for each SKU.

Is it because the form is being generated inside an echo? I don't know why it wouldn't work, but it isn't.

Still up for the challenge? ;)

Best,
MH

 

by: MHenryPosted on 2009-03-10 at 20:14:34ID: 23853682

Here's the way I had it setup before so that it would capture the different quantities. Without the double pasting this time!

<?php

         echo ' <form action="submitReg.php"  method="POST">
                  <table border="0" cellspacing="0" cellpadding="2" width="80%" align="top">
            <tr>
                  <td>&nbsp;</td>
                  <td>First Name</td>
                  <td>Last Name</td>
                  <td>Badge Name</td>
                  <td>Membership Type</td>
                  <td>E-mail Address</td>
                   </tr>';
                  
mysql_select_db($database_myConn, $myConn);
$datax = array();
$datay = array();
$dataz = array();
$cartNumber = $_SESSION["CartId"];
$query = "SELECT tbl_cart.cart_custcart_ID AS cartNumber, tbl_cart.cart_sku_ID AS orderSKU, tbl_cart.cart_sku_qty AS quantity FROM tbl_cart WHERE tbl_cart.cart_custcart_ID = '$cartNumber'";

  if ($result = mysql_query($query)) {
$x=1;
$j=1;
 while($data = mysql_fetch_array($result, MYSQL_NUM)) {
   $var_name='cartNumber'.$x;
   $$var_name = $data[0];
   $var_name='orderSKU'.$x;
   $$var_name = $data[1];
   $var_name='quantity'.$x;
   $$var_name = $data[2];
   

   
  switch ($data[1])
    {
    case ($data[1]= 60):
         while ($j <= $data[2]) {
                  echo '<tr align="center">
                        <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
                        <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
                        <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
                        </td>
                        <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
                        </td>
                        <td><label>
                         <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Adult Pass">
                      </label>
                        <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                         </tr>
                        <br />';
             $j++;
             }
             $j=1;
             break;
    case ($data[1]= 61):
         while ($j <= $data[2]) {
                  echo '<tr align="center">
                        <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
                        <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
                        <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
                        </td>
                        <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
                        </td>
                        <td><label>
                         <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Student Pass">
                      </label>
                        <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                         </tr>
                        <br />
                        </div>';
             $j++;
             }
             $j=1;
         break;                                    
    case ($data[1]= 62):
         while ($j <= $data[2]) {
                  echo '<tr align="center">
                        <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
                        <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
                        <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
                        </td>
                        <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
                        </td>
                        <td><label>
                         <input name="membType" type="text" id="membType'.$x.$j.'" value="3-day Child Pass">
                      </label>
                        <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                         </tr>
                        <br />
                        </div>';
             $j++;
             }
             $j=1;
         break;
    case ($data[1]= 63):
         while ($j <= $data[2]) {
                  echo '<tr align="center">
                        <td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">
                        <td><input type="text" name="firstName[]" size="10" id="firstName'.$x.$j.'">
                        <td><input type="text" name="lastName[]" size="10" id="lastName'.$x.$j.'">
                        </td>
                        <td><input type="text" name="badgeName[]" size="10" id="badgeName'.$x.$j.'">
                        </td>
                        <td><label>
                         <input name="membType" type="text" id="membType'.$x.$j.'" value="Friday Only Pass">
                      </label>
                        <td><input type="text" name="emailAddr[]" size="14" id="emailAddr'.$x.$j.'"></td>
                         </tr>
                        <br />
                        </div>';
             $j++;
             }
             $j=1;
         break;
    }

$x++;
                  
}  
  }
 
  echo '</table>
<input name="submitReg" type="button" value="submit" />
</form>'
 
?>

 

by: NerdsOfTechPosted on 2009-03-11 at 09:55:15ID: 23859475

Doh! I forgot to mention that the form code was a partial replacement. Here is the COMPLETE form (below):

<?php
 
         echo ' <form action="submitReg.php"  method="POST">
                  <table border="0" cellspacing="0" cellpadding="2" width="80%" align="top">
            <tr>
                  <td>&nbsp;</td>
                  <td>First Name</td>
                  <td>Last Name</td>
                  <td>Badge Name</td>
                  <td>Membership Type</td>
                  <td>E-mail Address</td>
            </tr>';
                  
mysql_select_db($database_myConn, $myConn);
$datax = array();
$datay = array();
$dataz = array();
$cartNumber = $_SESSION["CartId"];
$query = "SELECT tbl_cart.cart_custcart_ID AS cartNumber, tbl_cart.cart_sku_ID AS orderSKU, tbl_cart.cart_sku_qty AS quantity FROM tbl_cart WHERE tbl_cart.cart_custcart_ID = '$cartNumber'";
 
  if ($result = mysql_query($query)) {
$x=1;
$j=1;
 
echo '<tr align="center">';
echo '<td><input type="hidden" name="customerID_cart" value="'.$cartNumber.'">';
 
$x=1;
while($data = mysql_fetch_array($result, MYSQL_NUM)) {
 
   $var_name='cartNumber'.$x;
   $$var_name = $data[0];
   $var_name='orderSKU'.$x;
   $$var_name = $data[1];
   $var_name='quantity'.$x;
   $$var_name = $data[2];
 
echo '<td><input type="text" name="badge['.$x.'][firstName]" size="10">
      <td><input type="text" name="badge['.$x.'][lastName]" size="10">
      </td>
      <td><input type="text" name="badge['.$x.'][badgeName]" size="10">
      </td>
      <td><label>';
 
 switch ($data[1]){
  case ($data[1]= 60):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Adult Pass">';
   break;
  case ($data[1]= 61):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Student Pass">';
   break;
  case ($data[1]= 62):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Child Pass">';
   break;
  case ($data[1]= 63):
   echo '<input name="badge['.$x.'][membType]" type="text" value="3-day Friday Pass">';
   break;
 }
 echo '</label>
       <td><input type="text" name="badge['.$x.'][emailAddr]" size="14"></td>
       </tr>
       <br />
       </div>';
 $x++;
}
 
  echo '</table>
<input name="submitReg" type="button" value="submit" />
</form>'

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-11 at 09:56:54ID: 23859499

Backup your database if necessary and backup submitReg.php as a different name. Make this code submitReg.php (below):

<?php
foreach ($_POST["badge"] as $badge){ // each badge is one array itself
 
$sql = 'INSERT INTO attendeenames (customerID_cart,firstName,lastName,badgeName,email,membType) '; 
 
$sql .= 'VALUES ("'.$_POST["customerID_cart"].'","'.$badge["firstName"].'","'.$badge["lastName"].'","'.$badge["badgeName"].'","'.$badge["email"].'","'.$badge["membType"].'");';
 
mssql_query($sql);
 
}
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: NerdsOfTechPosted on 2009-03-11 at 09:58:43ID: 23859520

Try that out and let me know. Thanks.

 

by: MHenryPosted on 2009-03-11 at 09:59:22ID: 23859529

NerdsOfTech,

Yeah, I figured that out. It still didn't work. Like I said, your version doesn't collect multiple quantities. If someone orders three of the 3-day pass, your version only prints out one line in the form.

That and I can't get it to process the form. It still just sits there without generating any errors or anything. Just looks like no code is being run.

Best,
MH

 

by: MHenryPosted on 2009-03-11 at 19:42:20ID: 23864324

ok, so it looks like my real problem is that the form won't submit. I don't know if it will insert or not.

Until I figure out why it won't process, I can't find out if it will insert.

So, I'm going to open another question just for that. Hopefully, I can come up with an answer for that and then move back here for the submit.

Thanks,
MH

 

by: MHenryPosted on 2009-03-11 at 20:52:24ID: 23864627

So the problem was the submit button. I had it named as type=button.

Jeez....


But it's still not working. Now it submits, but nothing is going into the database.

Best,
MH

 

by: MHenryPosted on 2009-03-11 at 21:27:00ID: 23864814

NerdsOfTech,

Hey, it's almost working!

I think you've done your part. I am getting data errors, but that's after I fill out the form. And it does input.


Thanks for all your help!

Best,
MH

 

by: NerdsOfTechPosted on 2009-03-12 at 14:49:33ID: 23874048

Awesome! Your welcome. One word of advise also to finalize your processing page:
You should also secure the submitted form values against injection attacks and other sql type attacks.

Basically instead of inputting the raw values into the database CHECK the VALUES and UNESCAPE any INVALID chartacters so that someone doesn't input their first name as:
'; WHERE 1; DELETE * FROM'

etc.

Best Wishes,
=NerdsOfTech

 

by: MHenryPosted on 2009-03-12 at 15:27:59ID: 23874413

NerdsOfTech,

Could you point me in the direction of a decent tutorial or something that illustrates that? I have been reading up on it but most seem to require magic quotes or other extras. I'm not sure if that's going to be an option in this case.

Thanks again. After I went through it more carefully, I noticed I had a missing [ after one of the fields. When I put that in, it worked just fine.

Well, after I changed the mssql to mysql! Seeing that didn't make me feel quite so bad about hosing the submit button! ;)

Best,
MH

 

by: NerdsOfTechPosted on 2009-03-12 at 15:46:58ID: 23874555

mysql_real_escape_string($string) should work; also additional value formatting may be useful in the case of a format to field types (numbers only for number fields, etc.). Use your best judgment.

http://en.wikipedia.org/wiki/SQL_injection

Good luck,
=NerdsOfTech

//sample real escape
$query = sprintf("SELECT * FROM Users where UserName='%s' and Password='%s'", 
                  mysql_real_escape_string($Username), 
                  mysql_real_escape_string($Password));
mysql_query($query);
                                              
1:
2:
3:
4:
5:

Select allOpen in new window

 

by: MHenryPosted on 2009-03-12 at 15:50:47ID: 23874582

NerdsOfTech.

Thanks again. Your help was invaluable. I really appreciate the way you hung in there. You're one of the examples of why this site works!

Best,
MH

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...