Web Design Forums

Database Systems Help

Discussion and help on database systems such as MySQL, MSSql, SQLite, PostgreSQL

Redirect before mysql insert.. but after submit



Site of the Month Voting - Now Open. CAST YOUR VOTE NOW!

Reply
 
LinkBack Thread Tools
Old July 15 '04, 02:41 PM (#1)
AndrewWest is offline
New Member!
 
AndrewWest's Avatar
 
Join Date: July 2004
Posts: 5
AndrewWest is on a distinguished road
Redirect before mysql insert.. but after submit

This is a form of error handling. I can't seem to get it to work.

PHP Code:
<?php
   $path 
=  $_SERVER['PHP_SELF'];
   
$path_parts pathinfo($path);
   
$string $path_parts["basename"];
   
$exclude ".jpg.php";

   
$path substr("$string",0,strpos($string,$exclude));
   echo 
"Image: $path ";

if(isset(
$_POST['submit'])) {

$ip $HTTP_SERVER_VARS["REMOTE_ADDR"];

$query "SELECT last_ip FROM photographs WHERE name=$path";

if (
$query $ip) {
header("Location: error.php");
}


$link mysql_connect('localhost''andrew''1357908642');
if (!
$link) {
   die(
'Not connected : ' mysql_error());
}

$db_selected mysql_select_db('andrew_site'$link);

$message stripslashes(trim($message));
$message nl2br($message);
$message htmlentities($message);

$query "INSERT INTO photos (ip, comment, photo)
VALUES ('$ip', '$message', '$path')"
;
mysql_query($query);

mysql_close();

echo 
"Thanks $name your comment has been added";
}
   
?>
You can see the part that is wrong

PHP Code:
if ($query $ip) {
header("Location: error.php");

Headers can't be sent after submit has been made.. How can I redirect if it's wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 15 '04, 03:02 PM (#2)
Victor is offline
WDF Member
 
Victor's Avatar
 
Join Date: July 2004
Posts: 52
Victor is on a distinguished road
Send a message via AIM to Victor Send a message via MSN to Victor
First: if ($query = $ip) should be if ($query == $ip)
Second: redirection cant be done after you echoing something in the page. Get rid of echo before header and it will work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 15 '04, 03:52 PM (#3)
AndrewWest is offline
New Member!
 
AndrewWest's Avatar
 
Join Date: July 2004
Posts: 5
AndrewWest is on a distinguished road
I would prefer to keep that echo, so I can generate everyone the page as dynamic as possible is there any other way?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 15 '04, 04:01 PM (#4)
Victor is offline
WDF Member
 
Victor's Avatar
 
Join Date: July 2004
Posts: 52
Victor is on a distinguished road
Send a message via AIM to Victor Send a message via MSN to Victor
header will not work if the page is not complete empty.
And what are you trying to get here?
Quote:
if ($query = $ip) {
This is wrong definately.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 15 '04, 05:06 PM (#5)
AndrewWest is offline
New Member!
 
AndrewWest's Avatar
 
Join Date: July 2004
Posts: 5
AndrewWest is on a distinguished road
Yeah that was fixed. (Was an error I made in typing that in) and header worked fine once I moved the header above the echo opposed to removing it o-O
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 15 '04, 06:10 PM (#6)
visualAd is offline
Restructuring
 
visualAd's Avatar
 
Join Date: January 2003
Location: Slough, UK
Posts: 201
visualAd will become famous soon enough
If you include ob_start(); at the beginning, you can use the header function anywhere in the script.

The ob_start() function turns on the output buffer, which holds back all output, except headers uintil the end of the script.

Take a look here: http://uk.php.net/manual/en/ref.outcontrol.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » Database Systems Help

Bookmarks


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

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


 
User Infomation
Your Avatar

Site Of The Month
Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:00 PM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164