weeman09 Posted December 9, 2010 Share Posted December 9, 2010 hey there, i have created a guestlist that is linked to a database for people to add some details and submit it off. The problem i am having is confusing because the server connects to the database fine but after 5 or so entries it goes to my echo comment which is "unbale to insert record" just after 5 entries and or if i use a different computer......it will be much appreciated if someone could help me this thankyou heres my code: ****************************************************************** <?php # FileName="conn_db.php" $hostname= "********"; $database= "*********"; $user = "********"; $pass ="********"; $mysql_link=mysql_connect($hostname,$user,$pass) or die("unable to connnect to the server"); mysql_select_db($database) or die ("unable to select the database"); ?> **************************************************************** <?php $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $phone=$_POST['phone']; $email=$_POST['email']; $guests=$_POST['guests']; if (($first_name == "") or ($last_name == "") or ($email == "") or ($guests == "")) { echo"<p>Required Field (s) missing....!!!! Go Back and Try Again...!!!</p>"; } elseif (!(strstr($email, "@")) or !(strstr($email, "."))) { echo"<p>Invalid Email....!!!! Go Back and Try Again...!!!</p>"; } else { //Connect to the server and add a new record require_once('conn_db.php'); $query = mysql_query("SELECT COUNT(*) as pcount FROM cust")or die(mysql_error()); $row= mysql_fetch_assoc($query); //echo 'current count:'.$row['pcount']; // if ($row['pcount'] >120) { echo "guest list is full"; } else { $query = "INSERT INTO cust Values ('$first_name', '$last_name', '$phone', '$email', '$guests')"; mysql_query($query) or die ("unable to insert the record"); mysql_close(); echo "<p><b>Record Addedd Successfully.....!!!!</p>"; echo"<p> <a href=../html/thankyou.html>Click Here to Return to the Guests Page</a></b></p>"; $message = "Thankyou for registering with us\ Your deatils are: \nName: $_POST[first_name] \nEmail: $_POST /nPhone: $_POST[phone] \nguests: $_POST[guests]\n"; mail ($email, "Website Email", $message); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/ Share on other sites More sharing options...
Buddski Posted December 9, 2010 Share Posted December 9, 2010 The issue is most probably linked to this.. If you do not specify a list of column names for INSERT ... VALUES or INSERT ... SELECT, values for every column in the table must be provided by the VALUES list or the SELECT statement. If you do not know the order of the columns in the table, use DESCRIBE tbl_name to find out. I suggest rewriting your query to include the column names like so (this is just an example because I dont know your table structure) $query = "INSERT INTO cust (first_name, last_name, phone, email, quests) Values ('$first_name', '$last_name', '$phone', '$email', '$guests')"; Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/#findComment-1144792 Share on other sites More sharing options...
weeman09 Posted December 10, 2010 Author Share Posted December 10, 2010 thank you for looking at it .. but thats not the problem one of the fields the form has is a drop down box with 5 options to choose from. once option 1-5 have been selected once and sumitted to the database if someone else submits their details with the same amount of guest as the first person ie: option one. it says unable to insert record. is their a way to fix this ? this is my table form structure: <form name="form1" method="post" action="register.php"> <table width="339" height="214" border="0" align="center"> <tr> <td width="163">First Name: </td> <td width="322"><input name="first_name" type="text" id="first_name" size="30" maxlength="15"></td> </tr> <tr> <td>Last Name: </td> <td><input name="last_name" type="text" id="last_name" size="30" maxlength="30"></td> </tr> <tr> <td>Email:</td> <td><input name="email" type="text" id="email" size="30" maxlength="30"></td> </tr> <tr> <td>Mob. Number: </td> <td><input name="phone" type="text" id="phone" size="30" maxlength="30"></td> </tr> <tr> <td>Guests:</td> <td><select name="guests" id="guests"> <option>1 Person</option> <option>2 People</option> <option>3 People</option> <option>4 People</option> <option>5 People</option> </select></td> </tr> <tr> <td height="80"><p> </p></td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset"> <br /> <br /> <span class="x">(Press Once Only) </span></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/#findComment-1145216 Share on other sites More sharing options...
Pikachu2000 Posted December 10, 2010 Share Posted December 10, 2010 None of your <option> tags have a value= attribute. Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/#findComment-1145219 Share on other sites More sharing options...
weeman09 Posted December 10, 2010 Author Share Posted December 10, 2010 i made the change .... but still it wont let me submit the same value from the drop down box if its been submitted before??? Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/#findComment-1145222 Share on other sites More sharing options...
Pikachu2000 Posted December 10, 2010 Share Posted December 10, 2010 Post the error that mysql_error() is returning. Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/#findComment-1145226 Share on other sites More sharing options...
PFMaBiSmAd Posted December 10, 2010 Share Posted December 10, 2010 It sounds like you guests column is defined as key in the table? You can use mysql_error() to tell you why the query is failing. Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/#findComment-1145227 Share on other sites More sharing options...
weeman09 Posted December 10, 2010 Author Share Posted December 10, 2010 yes i just exported the sql for the database and the primary key was guests. all fixed thanks again much appreciated guys!!! awesome forum! keep up the good work :D :D Quote Link to comment https://forums.phpfreaks.com/topic/221091-php-error-help-needed/#findComment-1145238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.