Jump to content

Table Stops Accepting Data


Stainystain

Recommended Posts

xampp 1.8.3-3

Mac OSX 10.9.1

 

Hello,

 

I'm creating a form using html and php, which when run uploads information into a locally hosted xampp database. 

 

The issue; sometimes the table simply refuses the information - it doesn't show up in the database when sent and continues to do so and I cannot get it working again. I'm given no errors when the data is submitted so it must be connecting, the info just doesn't show up.

 

Because of this I decided to start from the beginning again, creating a new database and table, and starting with one input (date) - it works. I add more and more fields and it continues to work... I add a couple of the dynamic name fields (see code below) and it continues to work. I get confident so add the rest of my fields - bam, it stops working. After it stops accepting data, I can't get it accepting again - even if I delete all fields so I just have "date".

 

Am I hitting some limit somehow? 

 

I do apologise if the code is appalling - this isn't my day job!

 

Any help anybody can give me will be greatly appreciated, and will stop me tearing my hair out! 

 

Many thanks

Simon

 



<?
$username="xxxxxx";
$password="xxxxxx";
$database="Final";

$date=$_POST['date'];
$group_name=$_POST['group_name'];
$cruise=$_POST['cruise'];
$no_adults=$_POST['no_adults'];
$no_half=$_POST['no_half'];
$no_free=$_POST['no_free'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$accommodation=$_POST['accommodation'];
$payment=$_POST['payment'];
$info=$_POST['info'];
$name_adult=$_POST['name_adult'];
$name_adult_2=$_POST['name_adult_2'];
$name_adult_3=$_POST['name_adult_3'];
$name_adult_4=$_POST['name_adult_4'];
$name_adult_5=$_POST['name_adult_5'];
$name_adult_6=$_POST['name_adult_6'];
$name_adult_7=$_POST['name_adult_7'];
$name_adult_8=$_POST['name_adult_8'];
$name_adult_9=$_POST['name_adult_9'];
$name_adult_10=$_POST['name_adult_10'];
$name_adult_11=$_POST['name_adult_11'];
$name_adult_12=$_POST['name_adult_12'];
$name_adult_13=$_POST['name_adult_13'];
$name_adult_14=$_POST['name_adult_14'];
$name_adult_15=$_POST['name_adult_15'];
$name_half=$_POST['name_half'];
$name_half_2=$_POST['name_half_2'];
$name_half_3=$_POST['name_half_3'];
$name_half_4=$_POST['name_half_4'];
$name_half_5=$_POST['name_half_5'];
$name_half_6=$_POST['name_half_6'];
$name_half_7=$_POST['name_half_7'];
$name_half_8=$_POST['name_half_8'];
$name_half_9=$_POST['name_half_9'];
$name_half_10=$_POST['name_half_10'];
$name_half_11=$_POST['name_half_11'];
$name_half_12=$_POST['name_half_12'];
$name_half_13=$_POST['name_half_13'];
$name_half_14=$_POST['name_half_14'];
$name_half_15=$_POST['name_half_15'];
$name_free=$_POST['name_free'];
$name_free_2=$_POST['name_free_2'];
$name_free_3=$_POST['name_free_3'];
$name_free_4=$_POST['name_free_4'];
$name_free_5=$_POST['name_free_5'];
$name_free_6=$_POST['name_free_6'];
$name_free_7=$_POST['name_free_7'];
$name_free_8=$_POST['name_free_8'];
$name_free_9=$_POST['name_free_9'];
$name_free_10=$_POST['name_free_10'];
$name_free_11=$_POST['name_free_11'];
$name_free_12=$_POST['name_free_12'];
$name_free_13=$_POST['name_free_13'];
$name_free_14=$_POST['name_free_14'];
$name_free_15=$_POST['name_free_15'];
$email_2=$_POST['email_2'];
$email_3=$_POST['email_3'];
$email_4=$_POST['email_4'];
$phone_2=$_POST['phone_2'];
$phone_3=$_POST['phone_3'];
$phone_4=$_POST['phone_4'];

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO final VALUES ('$date','$group_name','$cruise','$no_adults','$no_half','$no_free','$email','$phone','$accommodation','$payment','$info','$name_adult','$name_adult_2','$name_adult_3','$name_adult_4','$name_adult_5','$name_adult_6','$name_adult_7','$name_adult_8','$name_adult_9','$name_adult_10','$name_adult_11','$name_adult_12','$name_adult_13','$name_adult_14','$name_adult_15','$name_half','$name_half_2','$name_half_3','$name_half_4','$name_half_5','$name_half_6','$name_half_7','$name_half_8','$name_half_9','$name_half_10','$name_half_12','$name_half_13','$name_half_14','$name_half_15','$name_free','$name_free_2','$name_free_3','$name_free_4','$name_free_5','$name_free_6','$name_free_7','$name_free_8','$name_free_9','$name_free_10','$name_free_11','$name_free_12','$name_free_13','$name_free_14','$name_free_15','$email_2','$email_3','$email_4','$phone_2','$phone_3','$phone_4')";
mysql_query($query);

mysql_close();
?>


 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="robots" content="noindex" />

<title>Guest Entry Form - Friendship Rose</title>

<script language="JavaScript">
function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}
</script>

<script  src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var addDiv = $('#addinputadult');
var i = $('#addinputadult p').size() + 1;

$('#addNewadult').live('click', function() {
$('<p><input type="text" id="adult_' + i +'" value="" size="40" name="name_adult_' + i +'" value="" placeholder="Full Name (Adult)" /><a href="#adult" id="remname_adult">Remove</a> </p>').appendTo(addDiv);
i++;

return false;
});

$('#remname_adult').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});

</script>

<script type="text/javascript">
$(function() {
var addDiv = $('#addinputhalf');
var i = $('#addinputhalf p').size() + 1;

$('#addNewhalf').live('click', function() {
$('<p><input type="text" id="name_half_' + i +'" value="" size="40" name="name_half_' + i +'" value="" placeholder="Full Name (Half)" /><a href="#half" id="remname_half">Remove</a> </p>').appendTo(addDiv);
i++;

return false;
});

$('#remname_half').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});

</script>

<script type="text/javascript">
$(function() {
var addDiv = $('#addinputfree');
var i = $('#addinputfree p').size() + 1;

$('#addNewfree').live('click', function() {
$('<p><input type="text" id="name_free_' + i +'" value="" size="40" name="name_free_' + i +'" value="" placeholder="Full Name (Free)" /><a href="#free" id="remname_free">Remove</a> </p>').appendTo(addDiv);
i++;

return false;
});

$('#remname_free').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});

</script>

<script type="text/javascript">
$(function() {
var addDiv = $('#addinputemail');
var i = $('#addinputemail p').size() + 1;

$('#addNewemail').live('click', function() {
$('<p><input type="text" id="email_' + i +'" value="" size="40" name="email_' + i +'" value="" placeholder="Contact Email" /><a href="#email" id="remNewemail">Remove</a> </p>').appendTo(addDiv);
i++;

return false;
});

$('#rememail').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});

</script>

<script type="text/javascript">
$(function() {
var addDiv = $('#addinputphone');
var i = $('#addinputphone p').size() + 1;

$('#addNewphone').live('click', function() {
$('<p><input type="text" id="phone_' + i +'" value="" size="40" name="phone_' + i +'" value="" placeholder="Phone Number" /><a href="#phone" id="remNewphone">Remove</a> </p>').appendTo(addDiv);
i++;

return false;
});

$('#remphone').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});

</script>

<link href="guest_form.css" rel="stylesheet" type="text/css" />
</head>[/color][/color]

<body>

      <h1 style="padding-left:30px"> Friendship Rose Guest Info </h1>
        <p style="padding-left:30px"> <b>Note:</b> The Tab Button scrolls through the form fields (mouse click can also be used), the return key creates a new line for text in the text fields </hp> 
        <p> </p>
   <div class="form" style="float:left; padding:0 0 30px 30px">
     <form name="guest_form" action="guest_form.php" method="post" style="float:left">
     Cruise Date: dd/mm/yy (IMPORTANT)
       <br />
       <input type="date" name="date" size="30" onKeyPress="return disableEnterKey(event)" /><br /><br />
       
       Cruise
       <br />
       <input type="radio" name="cruise" value="tobagocays">Tobago Cays<br>
      <input type="radio" name="cruise" value="mustique">Mustique<br />
       <input type="radio" name="cruise" value="mayreau">Mayreau<br>
      <input type="radio" name="cruise" value="st_vincent">St Vincent<br />
       <input type="radio" name="cruise" value="bequia">Bequia<br>

       <p> </p>
       Group Name / Identification (Surname)
       <input type="text" id="group_name" size="40" name="group_name" value="" placeholder="Group Name" onKeyPress="return disableEnterKey(event)" />
     <p> </p>
       Number of Adults:<br />
       <input type="number" name="no_adults" min="1" onKeyPress="return disableEnterKey(event)" />
       <br /><br />
      Number of Kids - Half Price: (Use 0 for none)<br />
        <input type="number" name="no_half" min="0" onKeyPress="return disableEnterKey(event)" />
       <br /><br />
       Number of Kids - Free: (Use 0 for none)<br />
       <input type="number" name="no_free" min="0" onKeyPress="return disableEnterKey(event)" />
      <p> </p>
      
       Names of Adults:
<div id="addinputadult" style="line-height:0px">
   <p>
   <a href="#adult" id="addNewadult">Add</a><br />
    <input type="text" id="name_adult" size="40" name="name_adult" value="" placeholder="Full Name (Adult)" />
   </p>
</div>


Names of Kids - Half:
<div id="addinputhalf" style="line-height:0px">
   <p>
   <a href="#half" id="addNewhalf">Add</a><br />
    <input type="text" id="name_half" size="40" name="name_half" value="" placeholder="Full Name (Half)" />
   </p>
</div>


Names of Kids - Free:
<div id="addinputfree" style="line-height:0px">
   <p>
   <a href="#free" id="addNewfree">Add</a><br />
    <input type="text" id="name_free" size="40" name="name_free" value="" placeholder="Full Name (Free)" />
   </p>
</div>
<p> </p>
Contact Email/s:
<div id="addinputemail" style="line-height:0px">
   <p>
   <a href="#email" id="addNewemail">Add</a><br />
    <input type="email" id="email" size="40" name="email" value="" placeholder="Contact Email" />
   </p>
</div>

Contact Phone Number/s:
<div id="addinputphone" style="line-height:0px">
   <p>
   <a href="#phone" id="addNewphone">Add</a><br />
    <input type="number" id="phone" size="40" name="phone" value="" placeholder="Phone Number" />
   </p>
</div>
       <p> </p>
       Accommodation:
       <br />
       <textarea name="accommodation" rows="5" cols="60" input type="text"></textarea>
       <p> </p>
       Payment Status:
       <br />
       <textarea name="payment" rows="2" cols="40" input type="text"></textarea>
       <p> </p>
       Extra Info / Dietry Requirements: 
       <br />
       <textarea name="info" rows="10" cols="60" input type="text"></textarea>
       <br />
       <p> </p>
       <input type="Submit" value="Submit" />
     </form>
    </div>

</body>

</html>

Edited by Stainystain
Link to comment
Share on other sites

Well, you're not checking for errors on the query, so you really don't know if there were errors or not. You're only checking for errors on the DB connection. Also, I don't know what you mean by "adding fields". Are you talking about adding fields to the DB schema or are you talking about adding fields to the INSERT query (which already exist in the table)?

 

Run this and if there is an error you will see the query and the error:

$query = "INSERT INTO final VALUES
          ('$date', '$group_name', '$cruise', '$no_adults', '$no_half', '$no_free', '$email', '$phone',
           '$accommodation','$payment', '$info', '$name_adult', '$name_adult_2', '$name_adult_3',
           '$name_adult_4', '$name_adult_5', '$name_adult_6', '$name_adult_7', '$name_adult_8',
           '$name_adult_9', '$name_adult_10', '$name_adult_11', '$name_adult_12', '$name_adult_13',
           '$name_adult_14', '$name_adult_15', '$name_half', '$name_half_2', '$name_half_3', '$name_half_4',
           '$name_half_5', '$name_half_6', '$name_half_7', '$name_half_8', '$name_half_9', '$name_half_10',
           '$name_half_12', '$name_half_13', '$name_half_14', '$name_half_15', '$name_free', '$name_free_2',
           '$name_free_3', '$name_free_4', '$name_free_5', '$name_free_6', '$name_free_7', '$name_free_8',
           '$name_free_9', '$name_free_10', '$name_free_11', '$name_free_12', '$name_free_13', '$name_free_14',
           '$name_free_15', '$email_2', '$email_3', '$email_4', '$phone_2', '$phone_3', '$phone_4')";
mysql_query($query) or die("Query: {$query}<br>Error: " . mysql_error());

But, yeah, you need to normalize your database. Specifically you should not have $name_adult, $name_adult2, $name_adult3, etc. You should instead have separate tables for the values where you will have "multiples" and have individual records with a foreign key reference back to the parent records.

Edited by Psycho
Link to comment
Share on other sites

Barand - any advice on how to normalise the database?  I presume you have an issue with the names... Each entry is one group - how would you then record each passengers name in that group? A table inside a table? How would that make it better?

 

Thanks for your reply,

Link to comment
Share on other sites

Barand - any advice on how to normalise the database?  I presume you have an issue with the names... Each entry is one group - how would you then record each passengers name in that group? A table inside a table? How would that make it better?

 

Thanks for your reply,

 

Well, to start, give your table a meaningful name, let's say reservations. That table will include the information specific to the reservation and has a one-to-one correlation such as the date, phone payment etc. Then have another table for passengers. Also, you should not store values such as number of adults, you should calculate those values from the database

 

Example:

 

reservations table

 

res_id | date       | group_name | cuise   | email               | phone
 1       2014-02-04   Anderson     Bahamas   anderson@gmail.com   123-456-7890
 2       2014-03-21   Roberston    Alaska    robertson@gmail.com  213-456-7890

 

passengers table

 

pass_id | res_id | name       | type   | email | phone
 1         1       David        adult    
 2         1       Terry        adult    
 3         1       Alan         adult    
 4         1       Michael      adult    
 5         1       Jane         half    
 6         1       Julie        adult    
 7         1       Alex         free    
 8         1       Joseph       free    
 9         1       Chris        half    
 10        1       Louis        half    
 11        1       Randy        adult    
 12        1       Wendy        free   
Link to comment
Share on other sites

Physco, thanks so much for your help and advice.

 

I must stress, this is all just a tester, thus the local host and name of database and table - i'm still very much fiddling with the best way to do this!

I will very much take on your advice and normalise the tables, but for the time being I have simplified it to get to the bottom of the current issue...

 

It's giving me the following error:

 

Error: Column count doesn't match value count at row 1

<?
$username="xxxxxx";
$password="xxxxxx";
$database="Final";
 
$date=$_POST['date'];
$group_name=$_POST['group_name'];
$cruise=$_POST['cruise'];
$no_adults=$_POST['no_adults'];
$no_half=$_POST['no_half'];
$no_free=$_POST['no_free'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$accommodation=$_POST['accommodation'];
$payment=$_POST['payment'];
$info=$_POST['info'];
 
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
 
$query = "INSERT INTO guest VALUES ('$date','$group_name','$cruise','$no_adults','$no_half','$no_free','$email','$phone','$accommodation','$payment','$info')";
mysql_query($query) or die("Query: {$query}<br>Error: " . mysql_error());
 
 
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="robots" content="noindex" />
 
<title>Guest Entry Form - Friendship Rose</title>
 
<script language="JavaScript">
function disableEnterKey(e)
{
     var key;
 
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
 
     if(key == 13)
          return false;
     else
          return true;
}
</script>
 
 
<link href="guest_form.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
 
<h1 style="padding-left:30px"> Friendship Rose Guest Info </h1>
        <p style="padding-left:30px"> <b>Note:</b> The Tab Button scrolls through the form fields (mouse click can also be used), the return key creates a new line for text in the text fields </hp> 
        <p> </p>
   <div class="form" style="float:left; padding:0 0 30px 30px">
     <form name="guest_form" action="guest_form.php" method="post" style="float:left">
     Cruise Date: dd/mm/yy (IMPORTANT)
       <br />
       <input type="date" name="date" size="30" onKeyPress="return disableEnterKey(event)" /><br /><br />
       
     Cruise
       <br />
       <input type="radio" name="cruise" value="tobagocays">Tobago Cays<br>
  <input type="radio" name="cruise" value="mustique">Mustique<br />
       <input type="radio" name="cruise" value="mayreau">Mayreau<br>
  <input type="radio" name="cruise" value="st_vincent">St Vincent<br />
       <input type="radio" name="cruise" value="bequia">Bequia<br>
 
       <p> </p>
       Group Name / Identification (Surname)
       <input type="text" id="group_name" size="40" name="group_name" value="" placeholder="Group Name" onKeyPress="return disableEnterKey(event)" />
     <p> </p>
       Number of Adults:<br />
       <input type="number" name="no_adults" min="1" onKeyPress="return disableEnterKey(event)" />
       <br /><br />
Number of Kids - Half Price: (Use 0 for none)<br />
        <input type="number" name="no_half" min="0" onKeyPress="return disableEnterKey(event)" />
       <br /><br />
       Number of Kids - Free: (Use 0 for none)<br />
       <input type="number" name="no_free" min="0" onKeyPress="return disableEnterKey(event)" />
      <p> </p>
      
 
Contact Email:<br />
 
    <input type="email" id="email" size="40" name="email" value="" placeholder="Contact Email" onKeyPress="return disableEnterKey(event)" /><Br /><Br />
 
 
 
Contact Phone Number:<Br />
 
    <input type="number" id="phone" size="40" name="phone" value="" placeholder="Phone Number" onKeyPress="return disableEnterKey(event)" /><br /><br />
 
 
       <p> </p>
       Accommodation:
       <br />
       <textarea name="accommodation" rows="5" cols="60" input type="text"></textarea>
       <p> </p>
       Payment Status:
       <br />
       <textarea name="payment" rows="2" cols="40" input type="text"></textarea>
       <p> </p>
       Extra Info / Dietry Requirements: 
       <br />
       <textarea name="info" rows="10" cols="60" input type="text"></textarea>
       <br />
       <p> </p>
       <input type="Submit" value="Submit" />
     </form>
    </div>
 
</body>
</html>
Edited by Stainystain
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.