Welcome, Register for free! or Login below:
EduGeek.net RSS Feeds Register FAQ Members Social Groups User Map Calendar Search Today's Posts Mark Forums Read

Go Back   EduGeek.net Forums > Coding and Web Development > Coding
Reply
 
LinkBack Thread Tools Search Thread Language
Sponsored Links
Old 23-07-2008, 03:42 PM   #1
 
freakyleaks's Avatar
 
Join Date: Jul 2008
Location: Seaton Canoe
Posts: 1
uk
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 freakyleaks is an unknown quantity at this point
Cool php problems

Hi I am having a problem with this insert statement have I written it correctly please thanks in advance. All errors pointed out will be fantastic !!!



PHP Code:
if (isset($_POST['Add'])){ 
 
$hardwareid mysql_real_escape_string($_POST['hardwareid']); 
$departmentid mysql_real_escape_string($_POST['departmentid']); 
$roomid mysql_real_escape_string($_POST['roomid']); //insert
$equiptmenttype mysql_real_escape_string($_POST['equiptmenttype']); 
$serialnumber mysql_real_escape_string($_POST['serialnumber']); 
$suppilername mysql_real_escape_string($_POST['suppilername']);  
$price mysql_real_escape_string($_POST['price']); 
$present mysql_real_escape_string($_POST['present']); 

$query5 ="INSERT INTO hardware 
VALUES('','$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"



mysql_query("INSERT INTO hardware 
VALUES("",'$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"



  Reply With Quote
Old 23-07-2008, 03:50 PM   #2
 
penfold_99's Avatar
 
Join Date: Feb 2008
Location: East Sussex
Posts: 153
uk
Thanks: 12
Thanked 17 Times in 14 Posts
Rep Power: 5 penfold_99 will become famous soon enoughpenfold_99 will become famous soon enough
Default

Try adding the "." in to the queary then you will construct the string correctly

$query5 ="INSERT INTO hardware
VALUES('',' . $departmentid .',' .$roomid .',' . $equiptmenttype . ',' . $serialnumber . ',' . $suppilername .',' . $price .',' .$present')";
  Reply With Quote
Old 23-07-2008, 03:51 PM   #3
 
contink's Avatar
 
Join Date: Jul 2006
Location: South Yorkshire
Posts: 2,652
uk uk yorkshire
Thanks: 101
Thanked 92 Times in 73 Posts
Rep Power: 28 contink is a name known to allcontink is a name known to allcontink is a name known to allcontink is a name known to allcontink is a name known to allcontink is a name known to all
Default

PHP Code:
$query5 ="INSERT INTO hardware ('dept_id', 'room_id', 'equiptype', ... etc... , 'present') 
VALUES('','$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"


mysql_query($query5) or die(mysql_error()); 
That's the bit you're going to be having problems with...

I've setup the code as an example as you haven't listed the tables column headers/labels so you need to edit the
PHP Code:
('dept_id''room_id''equiptype', ... etc... , 'present'
bit accordingly...

It'll also provide you with an error as to why it didn't like it which is good debugging practice.



The suggestion re: the dots, etc... isn't necessary as you're using double quotes to enclose the $query5 string.. You would need to if you were using single quotes.

Last edited by contink; 23-07-2008 at 03:55 PM..
  Reply With Quote
Old 23-07-2008, 03:54 PM   #4
 
dhicks's Avatar
 
Join Date: Aug 2005
Location: Alton, Hampshire
Posts: 1,376
Thanks: 119
Thanked 91 Times in 86 Posts
Rep Power: 28 dhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to all
Default

Quote:
Originally Posted by freakyleaks View Post
Hi I am having a problem with this insert statement
You'll have to tell us what the problem you are having is. Do you get a PHP syntax error, or an SQL syntax error? Does the data go in to the database, just in the wrong way or a way you weren't expecting?

[quote]$query5 ="INSERT INTO hardware
VALUES('','$departmentid','$roomid','$equiptmentty pe','$serialnumber','$suppilername', '$price', '$present')";

mysql_query("INSERT INTO hardware
VALUES("",'$departmentid','$roomid','$equiptmentty pe','$serialnumber','$suppilername', '$price', '$present')";[/QUOTE

You construct the query string twice? Probably you meant to do something like:

$query5 = ...
print $query5; # For debugging purposes - does the SQL query string look like you expected?
mysql_query($query5);

--
David Hicks
  Reply With Quote
Old 23-07-2008, 04:26 PM   #5
 
srochford's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 1,100
uk
Thanks: 1
Thanked 113 Times in 98 Posts
Rep Power: 29 srochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to all
Default

Not sure what you're doing here, but if the data could already exist then this will either end up with duplicate records (bad :-() or just fail.

What I always do is try to delete the record based on key field and then do an insert.
  Reply With Quote
Old 23-07-2008, 07:28 PM   #6
PEO
 
PEO's Avatar
 
Join Date: Oct 2007
Posts: 1,020
uk uk england
Thanks: 93
Thanked 30 Times in 16 Posts
Rep Power: 10 PEO has a spectacular aura aboutPEO has a spectacular aura about
Default

comon chris, lets see it up and running
  Reply With Quote
Reply

Register now for FREE and post messages!


Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Birthday:      
Image Verification
  I agree to forum rules 

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP on IIS 6 Ryan Windows 1 27-05-2008 01:32 PM
PHP Help! Cravon Coding 2 20-11-2007 06:05 PM
CMS - PHP problems wesleyw How do you do....it? 6 12-07-2007 09:22 AM
Help with PHP Gatt Web Development 1 14-11-2006 10:01 PM
php help beeswax Windows 33 14-10-2005 04:51 PM



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search Thread
Search Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 09:06 AM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright EduGeek.net