Jump to content

Header with variable error. Please help


patheticsam

Recommended Posts

Hi...

 

I'm a little bit new to php and it seems I am getting a small issue that I am not able to resolve...

 

Basicly I just have a page in wich you see the account file of a customer and you can add notes into it.

 

Here's the account file script

 

<?php 

mysql_connect("localhost", "user", "pass") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 

if( ($_GET['cmd']=="view") && (is_numeric($_GET['id'])) )
     {


$id=$_GET['id'];

$data = mysql_query("select * from client_table WHERE id_client='$id'") 
or die(mysql_error());

while($info = mysql_fetch_array( $data ))

     {
     echo "
     	<table border=\"0\" celppadding=\"0\" cellspacing=\"0\" style=\"font-weight: bold; width: 820px;\">  
     	 <tr>
     	 	<td colspan=\"2\" style=\"height: 50px;\"><a href=\"../dashboard.php\">Panneau de controle</a> > <a href=\"clients.php\">clients</a> > <a href=\"view_client.php?cmd=view&id=".$info['id_client']."\">Fiche client</a> > Notes > ".$info['entreprise']."</td>
     	 </tr>
     	 <tr>
     	 	<td style=\"padding-left: 10px\">
     	 	NEQ : ".$info['neq']."<br />
     	 	<h2>Nom de l'entreprise : ".$info['entreprise']."<br /></h2>
		<h2>Telephone : ".$info['client_phone']."<br /></h2>
     		</td>
     	</tr>
     	</table>
      ";
     }
    }
?>
          	<form enctype="multipart/form-data" action="process/insert_note.php" method="POST" target="main">
     		<input type="hidden" name="id_client" value="<?php echo $id; ?>">
     		<input type="hidden" name="note_date" value="<?php echo date("Y-m-d"); ?>">
     		<input type="hidden" name="note_time" value="<?php echo date("G:i:s"); ?>">
     <table border="0" celppadding="0" cellspacing="0" style="font-weight: bold; width: 780px;">  
     <tr>
     	<td colspan="0" style="padding-left: 10px">Ajouter une note : <br /><textarea name="note" style="height: 80px;" cols="90"></textarea><br />
     	<input type="submit" value="Ajouter une note">
     	</td>
     </tr>
     </table>
     </form>

 

So when I add the note....the form data is passed to a php script to insert the note into the MySQL DB and I just want to be redirected back to the acount file page with the note on it....

 

Here's the insert script :

 

<?php
    header('location:../view_notes.php?cmd=view&id=$id_client');
require_once('../../auth.php');

$id_client = $_POST['id_client'];


$con = mysql_connect("localhost","user","pass");


$note_date = $_POST['note_date'];
$note_time = mysql_real_escape_string($_POST['note_time']);
$note = mysql_real_escape_string($_POST['note']);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("db", $con);
$sql="INSERT INTO notes_table ( id_client, note_date, note_time, note)
VALUES
('$id_client','$note_date','$note_time','$note')";if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

?>

 

The problem I have is that the HEADER part is working but the value :    header('location:../view_notes.php?cmd=view&id=$id_client'); is not passed so I am redirected to a blank page.....

 

I tried to find the info on google but can't seems to find what wrong...

 

Any help will be appreciated!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/
Share on other sites

Is the value in the browser's address field correct after the redirect? What happens if you use the full URL in the header() call header("Location: http://www.mysite.com/path/ etc. ?

Unfortunately, if output_buffering is turned on in your master php.ini, any php errors that are output before the header() redirect, won't be.

 

You are using the $id_client variable before you have even assigned a value to it.

 

You should only be redirecting after you have successfully performed all the logic on the page, not as the first thing on the page.

 

If output_buffering is turned on in your php.ini, you should turn it off ASAP, especially on your development system.

but the thing is a can't assign a value to the variable before the header cuz If I do i'm getting an header output error

 

It's not the assignment of the variable that is causing the header error, it is the referencing of a nonexistent variable that is producing a php error message that is causing the header error. You would need to fix the logic so that you don't attempt to reference an nonexistent variable in the first place.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.