Jump to content

Archived

This topic is now archived and is closed to further replies.

smti

Inserting Data

Recommended Posts

Hello,

I am attempting to insert data into a mysql database. Below is a copy of my code. At the present time, it appears that my code never executes the if statement. I am not sure why. Earlier today, someone helped me repair that, but it does not appear to be working again. Please see the code below:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

                   
                    <fieldset>
<legend>Basic Information</legend>
                    <table>
<tr>
                         
<td><font size="1">Building Location:</font></td>

<td><select name="building_location">
<option value=blank selected=selected>
<option value=bo>Business Office
<option value=us>Upper School
<option value=ms>Middle School
                    <option value=ls>Lower School
                    </select> &nbsp; &nbsp;</td>
                   
                   
                    <td><font size="1">Room Number:</font></td>
                    <td><input type="text" id="room_location" name="room_location"/> &nbsp;&nbsp;</td>



                        <td><font size="1">Serial Number:</font></td>
                        <td><input type="text" id="serial_number" name="serial_number"/></td>
</table>
                    </fieldset>
                   
                   
<br>
                       
<fieldset>
<legend>Item Information</legend>
           
<p><label for="make"><font size="1">Computer Make:</font></label>
                        <input type="text" id="make" name="make"/>

                        <p><label for="model"><font size="1">Computer Model:</font></label>
                        <input type="text" id="model" name="model"/>

                        <p><label for="cpu"><font size="1">Processor Specs:</font></label>
                        <input type="text" id="cpu" name="cpu"/>
                       
<p><label for="Storage Capacity"><font size="1">Storage Capacity:</font></label>
<input type="text" id="storagecap" name="storage"/>

<p><label for="OS"><font size="1">Operating System:</font></label>
<input type="text" id="OS" name="os"/>

<p><label for="mac"><font size="1">MAC Address:</font></label>
<input type="text" id="mac" name="mac"/>
</fieldset>

                        <br><br>
                       

                        <input type="submit" name="submit" value="Add Asset"/> &nbsp; &nbsp; <input type="reset"     name="reset_data"/>
                        <input type="hidden" name="submit_information" value=true/>

                        </form>
              <?
           
//Get Data
           
$building_location=$_REQUEST['$building_location'];
$room_location=$_REQUEST['room_location'];
$serial_number=$_REQUEST['serial_number'];
$make=$_REQUEST['make'];
$model=$_REQUEST['mode'];
$cpu=$_REQUEST ['cpu'];
$storage=$_REQUEST['storage'];
$os=$_REQUEST['os'];
$domain=$_REQUEST['domain'];
$mac=$_REQUEST['mac'];


 
              if (isset($_POST['submit_information']))
                { 
include("includes/connection.inc.php");
                 
$result = mysql_query("insert into computers(building_location, room_location, serial_number, make, model, cpu, storage,os, domain, make, notes) Values('$building_location','$room_location','$serial_number','$make','$model','$cpu','$storage','$os','$domain','$mac')") or die();


Thanks in advance,

Jared

Share this post


Link to post
Share on other sites
Change this:
[code]<?php
$result = mysql_query("insert into computers(building_location, room_location, serial_number, make, model, cpu, storage,os, domain, make, notes) Values('$building_location','$room_location','$serial_number','$make','$model','$cpu','$storage','$os','$domain','$mac')") or die();
?>[/code]
to
[code]<?php
$q = "insert into computers(building_location, room_location, serial_number, make, model, cpu, storage,os, domain, make, notes) Values('$building_location','$room_location','$serial_number','$make','$model','$cpu','$storage','$os','$domain','$mac')";
$result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>[/code]
and tell us what error message is displayed.

Ken

Share this post


Link to post
Share on other sites
Are you sure your server supports short tags? try changing <? to <?php

Share this post


Link to post
Share on other sites
Hello,

It looks as though it is not entering the building location into the database. I am not sure why this is the case. Here is the output:

Problem with the query: insert into computers(building_location, room_location, serial_number, make, model, cpu, storage,os, domain, make, notes) Values('','room 1','serial 123','comp make','comp model','comp specs','comp cap','comp os','sby','comp mac')
Column count doesn't match value count at row 1

<td><select name="building_location">
<option value="blank" selected=selected>
<option value="bo">Business Office
<option value="us">Upper School
<option value="ms">Middle School
<option value="ls">Lower School
</select> &nbsp; &nbsp;</td>

If you look closely, you will see a coma before room one. This is what makes me think that the building location is the issue. It appears that it is not pulling any data for that field, but all the others work.

Thanks,

Jared

Share this post


Link to post
Share on other sites
You have 11 columns defined and only 10 values.

Share this post


Link to post
Share on other sites
thorpe,

Yes I am aware of that. I cannot figure out why it, that is the query is not pulling data from the building_location drop down box. That is why the query is failing. Any ideas on how to fix this?

- Jared

Share this post


Link to post
Share on other sites

×

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.