Jump to content

PHP error help needed


weeman09

Recommended Posts

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);

  }

}

    ?>

Link to comment
Share on other sites

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')"; 

Link to comment
Share on other sites

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>

 

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.