Click to See Complete Forum and Search --> : What's Wrong?


houston08
11-13-2006, 11:21 PM
Ok, I've been working on my site, and I can't get this submit feild to work.

Two files, add.php, and insert.php. Add.php is where the user puts in the info. and insert.php inserts it into the db. I know that probably isn't the best way, but, I am still learning, and, any help on that subject is also greatly appreciated. :D

Now, I can't see where I am messing up here, could yall read over these codes and see where my error might be?

First, add.php


<form name="Add Form" action="insert.php" method="post" target="_blank">
<tr><p>Please fill in the following information:</p></tr>

<tr><td>First Name:</td>
<td><input type="text" name="name_first" size="30"></td>
</tr>

<tr><td>Last Name: </td>
<td><input type="text" name="name_second" size="30"></td>
</tr>

<tr><td>City:</td>
<td><input type="text" name="city" size="15">

State:
<select name="state">
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>


</td>
</tr>

<tr><td>Zip/Postal Code: </td>
<td><input type="text" name="zip_postal" size="30">
</td>
</tr>

<tr><td>Phone #: </td>
<td>
<input type="text" name="phone_1" size="1"> -
<input type="text" name="phone_2" size="1"> -
<input type="text" name="phone_3" size="2">
</td>
</tr>

<tr><td>Phone # (<i>Outside U.S.</i>): </td>
<td>
<input type="text" name="phone_forgeign" size="30">
</td>
</tr>

<tr><td>E-mail: </td>
<td><input type="text" name="email" size="30">
</td>
</tr>

<tr><td>Contact me by: </td>
<td>
<input type="checkbox" name="email" value="contact_email" checked="yes">E-mail
<input type="checkbox" name="phone" value="contact_phone" checked="yes">Phone

<tr></tr>

<td align=center colspan=2>
<input type=submit value=Submit>



Now, insert.php


<?
include ("settings.php");
include ("connect.php");

$name_first=$_POST['name_first'];
$name_second=$_POST['name_second'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip_postal=$_POST['zip_postal'];
$phone_1=$_POST['phone_1'];
$phone_2=$_POST['phone_2'];
$phone_3=$_POST['phone_3'];
$phone_forgeign=$_POST['phone_forgeign'];
$email=$_POST['email'];
$contact_email=$_POST['contact_email'];
$contact_phone=$_POST['contact_phone'];



$query = "INSERT INTO entries VALUES ('$name_first','$name_second','$city','$state','$zip_postal','$phone_1','$phone_2','$phone_3','$phone_forgeign','$email','$contact_email','$contact_phone')";
mysql_query($query);

mysql_close();
?>



I have gone over it a lot, I just can't find where I messing up. Thanks!

bretticus
11-14-2006, 01:39 AM
Could you further define, "messing up."

houston08
11-14-2006, 09:09 AM
Sorry about that, ;)

The values are never input into the DB. Nor do they show up on the page to display the values.

bretticus
11-14-2006, 10:11 PM
Ok, you're still going to have to be a bit more specific.

1. You need to post your table schema for entries.
2. You need to post an error message (if there is one) or describe what happens on the insert.php page after being posted to.

If you can provide these details, someone can help you better. It's not good enough to just post some of your code. For example, I don't know what is in

include ("settings.php");
include ("connect.php");

I just have to assume everything looks good in them. Actually I'm assuming that you are getting a mysql error and it has something to do with there being more fields in the table you are writing than you are providing values for. Since you are using the SQL INSERT statement without specifying table columns just the values. This is correct syntax, but if you're leaving out, say, a auto-incremented column, MySQL has no way of knowing with the syntax you are using. Again, I'm speculating and this brings us back to requirements above.

houston08
11-15-2006, 12:40 AM
well, you are right, I have an auto_increment.
I know the settings.php and connect.php are correct, I've used em since beginning of project, it's just db user, pass, table, stuff like that, and how to connect or show die message. Sorry I didn't post that.

So, how would i make that work with a auto_id? since, that sounds like that could be my problem? It worked before, I just added more fields, and, now it's not working. I don't get it. let me know if you need more, I'll post.

bretticus
11-15-2006, 02:15 AM
You need to specify the columns in addition to the values like so...

$query = "INSERT INTO entries (name_first,name_second,city,state,zip_postal,phone_1,
phone_2,phone_3,phone_forgeign,email,contact_email,contact_phone) VALUES
('$name_first','$name_second','$city','$state','$zip_postal',
'$phone_1','$phone_2','$phone_3','$phone_forgeign','$email','$contact_email',
'$contact_phone')";

Notice the group in () between "INTO entries" and "VALUES"? Since I do not know your actual table column names, you'll need to substitute them for the ones I guessed on.