icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » What the F--- is going on here?

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old December 2nd, 2005, 1:08 PM   #1 (permalink)
Registered User
Fresh Surpasser
 
Jonslice's Avatar
 
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 &lt;br&gt; for line breaks and
&lt;b&gt; and &lt;/b&gt; around text for <strong>bold</strong><br>
<textarea name="desc" cols="50" rows="15"></textarea><br>
<input type="submit" value="Submit">
</form>
Jonslice is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 2nd, 2005, 1:15 PM   #2 (permalink)
minor deity
Super #1
 
Bigjohn's Avatar
 
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 PASS60 PASS61
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!
Bigjohn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 2nd, 2005, 1:20 PM   #3 (permalink)
Registered User
Fresh Surpasser
 
Jonslice's Avatar
 
Joined in Oct 2003
Lives in Dallas
Hosted on Pilot
13 posts
Gave thanks: 0
Thanked 0 times
Quote:
Originally Posted by Bigjohn
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?
the top part of this script queries the database to get values that are used in the form. I will post the code for img_form.php blow

PHP 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 
$sql "INSERT INTO `adoption` ( `web_id` , `type_id` , `hsnt_id` , `name` , `breed` , `gender` , `age` , `age_unit` , `desc` , `pic` , `thumb`  ) 
        VALUES ( '', '$type_id', '$hsntid', '$name', '$breed', '$gender', '$age', '$unit', '$desc', '','' )"
;
        
//run query
$result mysql_query($sql);
if (!
$result) {
   die(
'Invalid query: ' mysql_error());
}
else {
?>
        <p>Information stored</p>
        <p>Now add a picture</p>
<?
    
}
?>
<h1>File upload and thumbnail image creation.</h1>
<p>This page allows you to add an image for the available pet you have just entered</p>
<p>Only files ending with a .jpg extension can be processed with this script.</p>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="process.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
    <input type="hidden" name="hsntid" value="<?= $hsntid ?>" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="toProcess" type="file" />
    <br><br>
    <input type="submit" value="Send File" />
</form>
Interesting side note. The bottom form on this script that uploads an image file works perfectly. The image is uploaded, processed and stored in the dbase with no problems.
Jonslice is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 2nd, 2005, 2:23 PM   #4 (permalink)
All Ur Base R Belong 2 Us
Excelling Contributor
 
mr_fern's Avatar
 
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
mr_fern is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 2nd, 2005, 2:58 PM   #5 (permalink)
Registered User
Fresh Surpasser
 
Jonslice's Avatar
 
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.
Jonslice is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 5th, 2005, 12:23 PM   #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:
extract$_POST ); 
and the results will the the same as doing $hello = $_POST['hello']; $foo = $_POST['foo']; etc, etc, etc.
__________________
- Evan Charlton | [site] | Server - SH58
Kickersny.com is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may 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