Jump to content

Recommended Posts

For some reason the below is always redirecting to ./index.php?usercp=ideas&message=error

 

I'm assuming it's something to do with mysql_affected_rows.

 

<?php
session_start();
require_once 'db_select.php';
require_once 'func.php';
$donor_id=$_POST['donor_id'];
$donor_id=sanitize($donor_id);
$username=$_POST['username'];
$username=sanitize($username);
$name=$_POST['name'];
$name=sanitize($name);
$amount=$_POST['amount'];
$amount=sanitize($amount);
$idea_message=$_POST['idea_message'];
$idea_message=sanitize($idea_message);
$_SESSION['idea_message']=$idea_message;
$subject=$_POST['subject'];
$subject=sanitize($subject);
$_SESSION['subject']=$subject;
$confirm_agreement=$_POST['confirm_agreement'];
$confirm_agreement=sanitize($confirm_agreement);


if($subject==""){
$error0=1;
}
else{
$error0=0;
}

if($idea_message==""){
$error1=1;
}
else{
$error1=0;
}

if(($confirm_agreement!="no" && $confirm_agreement!="yes") || $confirm_agreement=="no"){
$error2=1;
}
else{
$error2=0;
}

$error="".$error0."".$error1."".$error2."";

if($error!="000"){
header("Location: ./index.php?usercp=ideas&error=".$error."");
}
else{
$sql="INSERT INTO $tbl_name5 (message_number, donor_id, username, name, amoutn, message) VALUES ('$message_number', '$donor_id', '$username', '$name', '$amount', '$message')";
mysql_query($sql);
if(mysql_affected_rows()==1){
header("Location: ./index.php?usercp=ideas&message=submitted");
unset($_SESSION['idea_message']);
unset($_SESSION['subject']);
}
else{
header("Location: ./index.php?usercp=ideas&message=error");
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/251340-not-redirecting-correctly/
Share on other sites

Well, your code says that if mysql_affected_rows() != (does not equal) 1, then it will use the header url of the one you specified. So that indicates mysql_affected_rows() is not equaling 1, when you think it should be.

 

Ask yourself why that is?

 

TIP: mysql_query($sql) or die(mysql_error());

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.