Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6736809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:10:26+00:00 2026-05-26T11:10:26+00:00

I have drawn up the following PHP code which processes the data from a

  • 0

I have drawn up the following PHP code which processes the data from a form in the following way:

  1. Adds all of the names entered to an array.
  2. Checks if any of the names are in a MySQL table.
  3. If not, returns an error.
  4. If so, adds data to a column called ‘workshop’ in the table for the names submitted.
$emailFrom = "";
$emailTo = "";
$subject = "Booking(s) for Workshop";

$body = "The following people have booked their workshops:" . "\n\n";

$row_count = count($_POST['name']);
if ($row_count > 0) {

mysql_select_db($database, $connection);
$name = array();
$workshop = array();

for($i = 0; $i < $row_count; $i++) {
// variable sanitation...
$name[$i] = mysql_real_escape_string(ucwords($_POST['name'][$i]));
$workshop[$i] = mysql_real_escape_string($_POST['workshop'][$i]);
}
$names = "('".implode("','",$name)."')";
$query = "SELECT 1 FROM conference WHERE Name In $names"; 
$result = mysql_query($query);

if ($result) {
    $rowcount = mysql_num_rows($result);

if ($rowcount == 0) {
      $errorString = "No bookings found"; 
} 
else {
for($i = 0; $i < $row_count; $i++) {
$sql = "UPDATE conference SET Workshop = '$workshop[$i]' WHERE Name LIKE '$name[$i]'";
mysql_query($sql);
      }
    }
  }
}

include 'workshops.php';

// send email 
$success = mail($emailTo, $subject, $body, "From: <$emailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks-workshop.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
//}

The issue I am now facing is how to add more sophisticated error checking. I want the PHP to check each name submitted on the form. If it finds all of the names, submit the data to the workshop column. If any names are not found, the error message would read “The following names have not been found on our database: [names listed]”. The user would then be forced to enter the correct names or remove the offending names, before the form could be submitted. I have got my head into a bit of tangle trying to work out how to achieve this though.

Should I run a separate query on the first loop for each name, and then if the name is not found in the table, add that name to a variable which would then be included in the error message? Then, if after all of the loops the error variable is “”, the form could be submitted (because all names have been found), but if not the error message would show the names that need amending?

Would this be the best method, or is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:10:27+00:00Added an answer on May 26, 2026 at 11:10 am

    I need to say sorry. I assumed you are sending all names thru POST.

    Here is second solution, try it:

    $not_in = Array();
    
    // lets say all names doesn't exist in `conference`
    foreach($name as $value) {
        // names in array are keys, not values
        $not_in[$value] = true;
    }
    
    
    $query = mysql_query("SELECT Name FROM conference WHERE Name IN $names"); 
    while(list($dbname) = @mysql_fetch_row($query)) {
        // delete those name from $not_in who exists
        unset($not_in[$dbname]);
    }
    
    // names in $not_in array are keys, not values
    $not_in = array_keys($not_in);
    
    if(empty($not_in)) {
        // its ok, all names have been found. do the magic.
    }else{
        $errorString = 'The following names have not been found on our database: '.join(', ',$not_in);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, <?php class Templater { static $params = array(); public
I have the following code which calculates the median of a group of numbers
In the following code I have 5 TextViews in which I try to set
If I have a sprite, with which I have drawn some stuff, how do
I have several user drawn controls on a form, unfortunately when the form is
I have the following: An image - a hand drawn map - of an
I have the following code to draw a custom picker. Unfortunately when the view
I have designed the following GUI in which there are an axes. I want
I'm facing the following problems: We have meta data for items, each item can
I am trying to mimic the following PHP code in C# <?php if (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.