patheticsam Posted February 11, 2012 Share Posted February 11, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/ Share on other sites More sharing options...
digibucc Posted February 11, 2012 Share Posted February 11, 2012 single quotes tell it it's a string, not variable. <?php header('location:../view_notes.php?cmd=view&id='. $id_client); ?> try that Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317010 Share on other sites More sharing options...
patheticsam Posted February 11, 2012 Author Share Posted February 11, 2012 Unfortunatly it seems it doesn'work...I get no error but I am still redirected to a blank page... Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317011 Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2012 Share Posted February 11, 2012 Is there anything at all? What about in the View-->Source of the page? Do you have the error_reporting = -1 and display_errors = On directives in your php.ini file? Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317012 Share on other sites More sharing options...
patheticsam Posted February 11, 2012 Author Share Posted February 11, 2012 yes error reporting is activated...The html displays correctly..there's no error but the values aren't passed from the header to view_notes.php..... Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317014 Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2012 Share Posted February 11, 2012 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. ? Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317017 Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2012 Share Posted February 11, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317019 Share on other sites More sharing options...
patheticsam Posted February 11, 2012 Author Share Posted February 11, 2012 I'm gonne turn it off...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....How can I assign the variable before the header?? Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317028 Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2012 Share Posted February 11, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317033 Share on other sites More sharing options...
patheticsam Posted February 12, 2012 Author Share Posted February 12, 2012 Got it! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/256901-header-with-variable-error-please-help/#findComment-1317192 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.