| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#1 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Oct 2003
Lives in Dallas
Hosted on Pilot
13 posts
Gave thanks: 0
Thanked 0 times
|
What the F--- is going on here?
OK, i'm having a bit of a problem with a script and I need some help.
What I have is a form that sends the data entered into the form to a database. My query is written correctly, i've triple checked it, and the database is working just fine. What I think is happening is the data entered into the form is not being passed to the script that inserts it into the database. I have tested this by replacing the script that inserts the data into the dbase with a script that just displays the values of the variables sent from the form. When the form is filled out and sent to the testing script this no data being displayed. This also seems to be consistent with other problems i'm having in other sections of the site's scripts that use forms to select data to be changed or deleted. I don't see any problems with my html for the forms and I don't see any problems with my php. Is there something i'm missing? I had this script working perfectly on my own surpass hosting account a month or 2 ago, now that i'm implementing the scripts onto the client's hosting account here at surpass i'm having problems. Anyone have any idea what's going on? If I have been unclear about anything or if anyone has questions that could help me solve this problem I'll do my best to make sense of it. I really need to get this worked out because the client is ready have their site up and running after 2 months of problems on their end, I don't want to contribute to the frustration by not having my **** ready to go. Thanks. Code:
<?php
include ('../inc/setup.php');
$dbconnect =mysql_connect ("localhost", "$db_user", "$db_pass") or die ('I cannot connect to the database because: ' . mysql_error());
$db =mysql_select_db ("$db_name") or die("Could not select DB");
$sql="Select *
FROM type
ORDER by type_id asc";
$sqlresult=mysql_query($sql);
?>
<body style="margin:3em;">
<h1>Enter information in the following fields</h1>
<p><a href="index.php">Click here to go back to the Admin-Home </a></p>
<form method="POST" action="img_form.php">
Select Animal Type:<br>
<select name="type_id" size="1">
<option value="0"></option>
<? while($type_array=mysql_fetch_array($sqlresult))
{
?>
<option value="<?=$type_array['type_id']?>"><?= $type_array['name']?></option>
<? } ?>
</select><br>
HSNT ID:<br>
<input name="hsntid" type="text" size="14" maxlength="14"><br>
Name:<br>
<input name="name" type="text" size="20" maxlength="80" ><br>
Breed: <br>
<input name="breed" type="text" size="20" maxlength="120"><br>
Gender<br>
<select name="gender" size="1">
<option value="0">Select</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select> <br>
Age: <br><input name="age" type="text" size="4" maxlength="80">
<select name="unit" size="1">
<option value="0">Select</option>
<option value="Weeks">Weeks</option>
<option value="Months">Months</option>
<option value="Month">Month</option>
<option value="Year">Year</option>
<option value="Years">Years</option>
</select><br>
Discription of Animal:<br>
Some html may be needed in this field. <br>
Use <br> for line breaks and
<b> and </b> around text for <strong>bold</strong><br>
<textarea name="desc" cols="50" rows="15"></textarea><br>
<input type="submit" value="Submit">
</form>
|
|
|
|
|
|
#2 (permalink) |
|
minor deity
Super #1
Joined in Apr 2004
Lives in Georgia
Hosted on XEON
7,394 posts
Gave thanks: 28
Thanked 94 times
|
I'm not the hottest PHP coder in the world - probably the opposite... but, when you submit, you have to have an action page that actually fetches the variables that the form created and inserts them.
The top part of this script that you've posted only QUERIES the database and selects values. What does IMG_FORM.PHP look like?
__________________
Proud to be a Surmunity Mod! XEON Make a fundamental difference! My Sites: Curious about Brewing Beer? Join the community! >>>>> Some Change is GOOD! Keep your paycheck! Support the Fair Tax Get into an Art museum Victorian London It's your brain -ON WEB - mybrainhost.com (under development) What SHOULD Government do? Much Less than it Does! |
|
|
|
|
|
#3 (permalink) | |
|
Registered User
Fresh Surpasser
Joined in Oct 2003
Lives in Dallas
Hosted on Pilot
13 posts
Gave thanks: 0
Thanked 0 times
|
Quote:
PHP Code:
|
|
|
|
|
|
|
#4 (permalink) |
|
All Ur Base R Belong 2 Us
Excelling Contributor
Joined in Feb 2005
Lives in Vegas & New York
824 posts
Gave thanks: 2
Thanked 6 times
|
Your img_form script assumes that register globals is set to 1.
Register Globals registers your GPC (GET, POST, COOKIE) variables as independent variables. With register globals on, http://address.com/page.php?k=hello, the variable $k gets the value "hello", as well as $_GET['k'] and $HTTP_GET_VARS['k']; With register globals off, the variable $k does not get generated by the requested URL. Your current easiest solution is to add the following code: extract($_POST); above //sql extract will take all array variables (associative not numerical arrays) and create variables out of the array keys, with variables values being the complimenting array values. It essential does the same as: foreach($_POST as $key => $value) $$key = $value;
__________________
Nobody doing nothing |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Oct 2003
Lives in Dallas
Hosted on Pilot
13 posts
Gave thanks: 0
Thanked 0 times
|
thanks for the reply fern. while what you posted i'm sure works I don't exactly understand it :-)
I did however get a similar fix from a buddy of mine. He suggested I define each variable that was being inserted into the dbase before it is placed in the sql by using $_request. It seems to be a little more time consuming way of doing it as I will have to add $variable = $_request['variable']; for everything that is passed on by the form but it works. Again, thanks for the recommendation and I have much respect for your php knowledge. |
|
|
|
|
|
#6 (permalink) |
|
Surpass Fan
Super #1
Joined in Aug 2004
Hosted on SH58
1,688 posts
Gave thanks: 6
Thanked 7 times
|
$_REQUEST[] is also deprecated, I believe. For you, the easiest way would be to put the following at the top of img_form.php:
PHP Code:
__________________
- Evan Charlton | [site] | Server - SH58 |
|
|
|