Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-09-2006, 07:27 AM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,525
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Problem with script structure ??

I am having a problem getting my script to continue processing after calling (request_once) another script.

There are three scripts involved.
Main one (Homes_add.php) calls the second (a_picts.php) which is a form validating script - which ofcourse calls its form (a_picts_fm.php)

Again - it is clear that the problem is not in returning from a_picts_fm back to a_picts - BUT the problem is returning from a_picts back to the main script ( homes_add script.)

I wonder if there is a fundamental structural problem ?

The main script (homes_add)
calls ( require_once ) the a_picts which processes the form.
The form itself on submisson re-runs the a_picts which when finshed should return to the main script (homes_add) and continue from where it left the off.

To summarise the problem is that the a_pict.php stops at the last line afer executing this :

echo " *** and got here";

IT DOESN'T RETURN TO HOMES_ADD.PRG

- dont know why ???

I have stripped a lot of the code to try and make it clearer.

If anyone can help solve this - I'd much appreciate it as I am a bit stuck !


HERE IS THE MAIN - HOMES_ADD.PHP SCRIPT
IT CALLS THE PICTURE HANDLING SCRIPT


PHP Code:
<?php
/*
* homes_add.php
*
* Called by : homes_ad_btn.php
*
* Call a_picts.php to get the pictures
*
* processes the homes_add_fm.php which is the
* FORM for adding a home.
*/

if (!isset($_POST['run_mn'])){

PREPARES DATA AND CALLS THE MAIN FORM NOT PICTURE FORM)

else { 
// BIG else - SO MAIN FORM HAS RUN

VALIDATES FORM DATA

/*
* Now we get the pictures.
*/
if( $pict == "y"){
require_once(
"a_picts.php"); // < -- HERE IS THE CALLING
exit(); // < -- I TRIES TAKING THIS OUT
// endif
else{
$N_pix1=$N_pix2=$N_pix3=$N_pix4=$N_pix5="none";
// end else

// I WANT TO RETURN BACK HERE

$sql "UPDATE homes SET
pix1 = '$N_pix1',
pix2 = '$N_pix2',
pix3 = '$N_pix3',
pix4 = '$N_pix4',
pix5 = '$N_pix5'

WHERE ad_ref = '$A_ref' "
;

mysql_query($sql)
or die(
"could not execute HOMES UPDATE PICTURES query");

/*
* Update the client table
*/
ETC ETC

// end BIG else

?>




THIS IS THE SECOND SCRIPT THAT CALLS AND THEN PROCESSES
THE FORM


PHP Code:
if(isset($_POST['run'])){ // BIG IF

PROCESSES THE PICT_FM.PHP FORM

echo "got here";
// end BIG IF

else {
$message1 "none";
$message2 "none";
require_once (
"a_picts_fm.php"); // CALLS THE FORM
exit();
// end else

echo " *** and got here"// THIS WHERE IT STOPS

?> 


AND THIS IS THE FORM THAT THE ABOVE REQUIRES


PHP Code:
<?php
/*
* picts_fm.php
*
* Called by : picts.php
* IT THEN GOES BACK TO PICTS.PHP
*
* FORM for adding images.
*
*/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html>
<
head>
<
script type="text/javascript">


<
form name="main_fm" enctype ="multipart/form-data" action="a_picts.php" method="POST">
<
input type 'hidden' name='run' value="on">
<
input type="hidden" name ="MAX FILE SIZE" value="500000">
<
input type 'hidden' name='adref' value="<?php echo $A_ref ?>">

<
div style='position:absolute; left:40px; top:320px' >
<
b>First image:</b><br />
<
input type="file" size="50" id "u1" name="upLoad1" onchange="showImg1()"><br />
<
input type="text" size="50" id "n1" name="fName1" readonly>
<
input type="button" value ="Clear" onclick="document.main_fm.upLoad1.value='';document.main_fm.fName1.value='';document.getElementById('image1') .src='';document.getElementById('image1').style.display='none'">
</
div>

<
div style='position:absolute; left:500px; top:262px' >
<
img height='160' width='160' id="image1" style='display:none' />
</
div>
</
form>
</
body>
</
html>
jeddi is offline   Reply With Quote
Old 06-09-2006, 11:10 AM   PM User | #2
takin
New Coder

 
Join Date: May 2006
Location: Australia
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
takin is an unknown quantity at this point
From what you've shown above, the code is being fully executed. It seems to me that in most cases, there's nothing to query. Even on the first pass where you have to show the form, you're running a query. That query will probably be

UPDATE homes SET
pix1 = '',
pix2 = '',
...
WHERE ad_ref='xxx';

The best way to test this is to echo the query to the screen before you run it. Even better, wrap your queries in a function so that you can do that automatically for every query (and 'sanitise' it) then remove for all queries once you're satisfied with your code.
takin is offline   Reply With Quote
Old 06-09-2006, 02:23 PM   PM User | #3
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,525
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Hi - thanks for the response

You wrotr something very interesting that I need to learn about

Quote:
Even better, wrap your queries in a function so that you can do that automatically for every query (and 'sanitise' it) then remove for all queries once you're satisfied with your code.
Can you please give me an example on this type of function and how I should use it ?

Thanks
jeddi is offline   Reply With Quote
Old 06-09-2006, 02:36 PM   PM User | #4
takin
New Coder

 
Join Date: May 2006
Location: Australia
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
takin is an unknown quantity at this point
My general function is like this:

PHP Code:
function query($query) {
 if (!
$result[0] = mysql_query($query)) {
  die (
"query failed: $query\n" . echo mysql_error());
 }
 
$result[1] = mysql_num_rows();
}

...

$query "SELECT ...";
$result query($query);
if (
$result[1]) {
 while (
$row mysql_fetch_assoc($result[0])) {
  ...
 }

But you could always put an 'echo $query' in the first line of the function and even a strip_slashes($query) before that.
takin is offline   Reply With Quote
Old 06-09-2006, 04:23 PM   PM User | #5
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,525
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Thanks

- just one bit I don't follow

what does this mean ?
if ($result[1]) {
jeddi is offline   Reply With Quote
Old 06-10-2006, 02:28 AM   PM User | #6
takin
New Coder

 
Join Date: May 2006
Location: Australia
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
takin is an unknown quantity at this point
In the function, I said
PHP Code:
$result[1]=mysql_num_rows() 
to check whether there were any results.

In the main body, I use that variable to check whether I should process the data or not. I often find myself getting errors early in a databases life because there's nothing to process.

Come to think of it, you don't need the if ($result[1]) if you're using a while loop. Only if you jump straight into the processing.
takin is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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 not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:23 AM.


Advertisement
Log in to turn off these ads.