Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
Can someone please take a look at my code- Its so close, but doesn't quite work.. :(
Old 12-15-2010, 05:00 AM Can someone please take a look at my code- Its so close, but doesn't quite work.. :(
Novice Talker

Posts: 5
Name: Josh
Trades: 0
Hi all!

I have a database set up and have a form to collect data. The database works, and the HTML form works. Bu tthe php code doesnt...

Here it is...
PHP Code:
<?php
$con 
mysql_connect("localhost","testdatabase","******");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("web165-josh"$con);

$sql="INSERT INTO `qtsdispatches` (`item`, `itemValue`, `shipTo`, `building`, `street`, `townCity`, `postCode`, `refNum`, `collectionDate`, `location`, `courierName`, `consignmentNum`)
VALUES
('
$_POST[item]','$_POST[item_value]','$_POST[ship_to]','$_POST[building]','$_POST[street]','$_POST[town_city]','$_POST[post_code]','$_POST[ref_num]','$_POST[collection_date]','$_POST[location]','$_POST[courier_name]','$_POST[consignment_num]')";

if (!
mysql_query($sql,$con))
  {
  die(
'Error: ' mysql_error());
  }
echo 
"<h1><b>Database has been updated with one record.</h1></b>";

mysql_close($con)
?>
*** The password, database name, table name ect is all correct. Infact the script runs to the end and displays the message "Database has been updated with one record".

When I look at my database I can see that a new row has been added to it, but EVERY SINGLE field is EMPTY. None of the data from the form was passed onto the database. Why would this be?

So the scripts runs fine, the database has been communicated with in some way because it adds a new row of data (but an empty one!).

I have been scratching my head for days and would very much appreciate it if someone could help me .

Thanks in advance!! .

Last edited by NullPointer; 12-15-2010 at 07:43 PM.. Reason: Added PHP tags
sword07 is offline
View Public Profile
 
 
Register now for full access!
Old 12-15-2010, 05:14 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Do the keys in the _POST array match form field names? Do an echo $_POST[item_value] before the query - is the value there?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
View Public Profile
 
Old 12-15-2010, 05:19 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Novice Talker

Posts: 5
Name: Josh
Trades: 0
Hello, thanks for you quick reply! .

All of the _POST do match my field names. When i echoed the _POST item_value before the query it didn't show. It just said the same: "Database updated with one record".

Thanks again.
sword07 is offline
View Public Profile
 
Old 12-15-2010, 05:25 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by sword07 View Post
When i echoed the _POST item_value before the query it didn't show. It just said the same: &quot;Database updated with one record&quot;.

Thanks again.
Just to make sure, try: echo ""***** " . $_POST["ship_to"] . " *****
\n";
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
View Public Profile
 
Old 12-15-2010, 05:28 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
all on one line of course! And just one " , not two ( echo "")
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 12-15-2010 at 05:29 AM..
PaulW is offline
View Public Profile
 
Old 12-15-2010, 10:49 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Novice Talker

Posts: 5
Name: Josh
Trades: 0
Sorry for my late reply..

I'm not too sure what you want me to do from what you post3d on your most recent reply...

Cold you please explain this to me in more detail?

Many Thanks.
sword07 is offline
View Public Profile
 
Old 12-15-2010, 07:41 PM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
PHP Code:
echo "1 *****" $_POST["ship_to"] . "*****  \n";echo "2 *****" $_POST[ship_to] . "*****\n"
Put those lines in your code before you do the query and reply here with the output.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 12-15-2010 at 07:48 PM..
PaulW is offline
View Public Profile
 
Old 12-17-2010, 04:19 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Novice Talker

Posts: 5
Name: Josh
Trades: 0
HI again,

OK I added that line before the query and this is what the output was...

1 ********** 2 **********
Database has been updated with one record.


Does that help?

Cheers.
sword07 is offline
View Public Profile
 
Old 12-17-2010, 06:34 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
It does indeed -- it tells us that the variables values are not being passed over in $_POST. Either that, or the names don't match the HTML form elements -- which you say they do, or you don't have method="POST" on the form. . Check the form again. (Can you post the HTML here?)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
View Public Profile
 
Old 12-17-2010, 07:53 AM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Novice Talker

Posts: 5
Name: Josh
Trades: 0
Ah ok thats good then.

Yeah sure, here it is:

<html>
<head>
<title>Dispatches Form</title>
</head>
<body>
<h1>Quayside Technical Services Dispatch Form</h1>
<u><i>Please fill in to the best of your knowledge!</i></u>
<form action="process.php" method="post">
<table>
<tr>
<td>Item:</td>
<td><input type="text" id="item"></td>
</tr><tr>
<td>Item Value (£)::</td>
<td><input type="text" id="item_value"></td>
</tr><tr>
<td>Shipping To:</td>
<td><input type="text" id="ship_to"></td>
</tr><tr>
<td>Business or House Name or Number:</td>
<td><input type="text" id="building"></td>
</tr><tr>
<td>Street:</td>
<td><input type="text" id="street"></td>
</tr><tr>
<td>Town or City:</td>
<td><input type="text" id="town_city"></td>
</tr><tr>
<td>Post Code:</td>
<td><input type="text" id="post_code"></td>
</tr><tr>
<td>Reference Number:</td>
<td><input type="text" id="ref_num"></td>
</tr><tr>
<td>Collection Date: </td>
<td><input type="text" id="collection_date"></td>
</tr><tr>
<td>Collection Location:</td>
<td><input type="text" id="location"></td>
</tr><tr>
<td>Courier Name:</td>
<td><input type="text" id="courier_name"></td>
</tr><tr>
<td>Consignment Number:</td>
<td><input type="text" id="consignment_num"></td>
</tr><tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>


Thanks again!
sword07 is offline
View Public Profile
 
Old 12-17-2010, 08:12 PM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
You need to add name attributes to the form fields -- the id isn't what causes the value to be submitted. The string in $_POST["str"] is the value from name=
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 12-17-2010 at 08:13 PM..
PaulW is offline
View Public Profile
 
Old 12-17-2010, 08:26 PM Re: Can someone please take a look at my code- Its so close, but doesn't quite work..
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
By the way, if someone submits the form with various values unset, your query will insert an empty string for those columns in a record. Is this what you want or should they be set to NULL?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
View Public Profile
 
Closed Thread     « Reply to Can someone please take a look at my code- Its so close, but doesn't quite work.. :(
 

Thread Tools Search this Thread
Search this 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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.87396 seconds with 12 queries