Jump to content


Photo

Inserting Data


  • Please log in to reply
6 replies to this topic

#1 smti

smti
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 31 July 2006 - 09:51 PM

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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 31 July 2006 - 09:58 PM

Change this:
<?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();
?>
to
<?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());
?>
and tell us what error message is displayed.

Ken


#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 31 July 2006 - 09:59 PM

Are you sure your server supports short tags? try changing <? to <?php

#4 smti

smti
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 31 July 2006 - 10:28 PM

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

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 31 July 2006 - 10:31 PM

You have 11 columns defined and only 10 values.

#6 smti

smti
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 31 July 2006 - 10:56 PM

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

#7 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 31 July 2006 - 11:33 PM

Menu options should have a closing tag </option> after the option text.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users