I have the following code. On failure i need to get the alert Already exists and redirect to te registration page. But on success i need to check the session and based on the role id i need to redirect the page but the alert and redirection is not happening in this case ... can you please tell where i am wrong
if ($referral_patient_id != NULL) {
echo "<script language='javascript'>
alert('Successfully Added');
if ($_SESSION['role_id'] != 6) {
echo 'window.location.href="../Laboratory_Home"';
} else {
echo 'window.location.href="../Billing_Home"';
} </script>";
} else {
echo "<script language='javascript'>
alert('Already Exists');
window.location.href = '../../LabAdd_Patients';
</script>";
}
<?php if ($referral_patient_id != NULL) { ?>
<script type='javascript'>
alert('Successfully Added');
<?php if ($_SESSION['role_id'] != 6) { ?>
window.location.href="../Laboratory_Home";
<?php } else { ?>
window.location.href="../Billing_Home";
<?php } ?>
</script>
<?php }else { ?>
<script type='javascript'>
alert('Already Exists');
window.location.href = '../../LabAdd_Patients';
</script>
<?php } ?>
Try this one dude.
Try this javascript code :
<script language='javascript'>
var referral_patient_id = '<?php echo $referral_patient_id; ?>';
if(referral_patient_id != null)
{
alert('Successfully Added');
var role_id = '<?php echo $_SESSION["role_id"]; ?>';
if (role_id != '6') {
window.location.href="../Laboratory_Home";
} else {
window.location.href="../Billing_Home";
}
}
else
{
alert('Already Exists');
window.location.href = '../../LabAdd_Patients';
}
</script>
You have mixed content. PHP and Javascript. Try this one
echo "<script language='javascript'>
alert('Successfully Added');
</script>";
if($_SESSION['role_id']!=6){
echo "<script language='javascript'>window.location.href='../Laboratory_Home'</script>";
} else {
echo "<script language='javascript'>window.location.href='../Billing_Home'</script>";
}
Or this one
echo "<script language='javascript'>
alert('Successfully Added');
if( ".$_SESSION['role_id']." !=6) {
window.location.href='../Laboratory_Home';
} else {
window.location.href='../Billing_Home';
}
</script>";
Related
im making a user profile edit page and i have added a profile pic upload option but it does not show error message when file size is above limit
if(isset($_POST["submits"]))
{
$target_dir = "uploads/";
$target_maxsize=2000000;
if(!($_FILES['fileToUpload']['name']==""))
{
$target_file = $target_dir.basename($_FILES['fileToUpload']['name']);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg")
{
$_SESSION['uperr']="Please select an image file (.jpg, .jpeg & .png)";
header('Location: http://localhost/VULCAN/dashboard.php?q=setting');
}
else
{
if($_FILES['fileToUpload']['size'] < $target_maxsize)
{
if(file_exists($target_file))
{
$_SESSION['uperr']="File Already Exists!";
header('Location: http://localhost/VULCAN/dashboard.php?q=setting');
}
else
{
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file))
{
$_SESSION['uperr']="File has been uploaded successfully!";
header('Location: http://localhost/VULCAN/dashboard.php?q=setting');
}
else
{
$_SESSION['uperr']="File could not be uploaded!";
header('Location: http://localhost/VULCAN/dashboard.php?q=setting');
}
}
}
else
{
$_SESSION['uperr']="File is too large!";
header('Location: http://localhost/VULCAN/dashboard.php?q=setting');
}
}
}
else
{
$_SESSION['uperr']="Please select a file first!";
header('Location: http://localhost/VULCAN/dashboard.php?q=setting');
}
}
this is what i use for displaying error message if any
<body>
<?php
if(isset($_SESSION['uperr'])/*$sesfilerr!=""*/)
{
?><script>
$( document ).ready(function() {
alert("<?php echo $_SESSION['uperr']; ?>");
});
</script><?php
unset($_SESSION['uperr']);
}
?>
</body>
help anybody?
also when i refresh the page the error message is displayed again. anything to prevent this?
Please try this below code
if(isset($_SESSION['uperr']))
{
?><script>
$( document ).ready(function() {
alert("<?php echo $_SESSION['uperr']; ?>");
});
</script><?php
unset($_SESSION['uperr']);
$_SESSION['sett']=1;
}
?>
I have this code that deletes a student record from the database, it deletes the student information as well as where an image is stored on the server however, I also want it to delete the image file itself, not just the record. How can I do this.
This code is where the user clicks to delete the student.
<a href="javascript:void();" onclick="deleteItem
(<?php echo $student_row->id;?>,<?php echo $_REQUEST['regNumber'];?>,
<?php echo $student_row->id;?>,'parent')">Delete</a>
This code is the JS code referenced above:
function deleteItem(registration_number,parent_id,id,type)
{
var parent_id = "<?php echo $_REQUEST['regNumber'];?>";
var url_pass="<?php echo get_site_url();?>/student-delete/?
regNoIndivid="+registration_number+
"&parentId="+parent_id+"&id="+id+"&type="+type;
if (confirm("Are you sure?")) {
window.location.href = url_pass;
}
return false;
}
This is from student-delete:
if($_REQUEST['type'] == "teacher")
{
$where=array("id"=>$_REQUEST['id']);
//echo "<pre>";print_r($where);echo "</pre>";
//$delete_row=$wpdb->delete('wp_new_student_user', $where);
$delete_row = $wpdb->query('DELETE FROM wp_new_student_user WHERE id
='.$_REQUEST['id']);
$wpdb->show_errors();
if($delete_row)
{
$url_location=get_site_url()."/my-account-teacher/?
regNumber=".$_REQUEST['parentId']."&type=tea&back_list=yes";
?>
<script type="text/javascript">
window.location.href="<?php echo $url_location;?>";
</script>
<?php
}
}
elseif ($_REQUEST['type'] == "parent") {
$where=array("id"=>$_REQUEST['id']);
//echo "<pre>";print_r($where);echo "</pre>";
//$delete_row=$wpdb->delete('wp_new_student_user', $where);
$delete_row = $wpdb->query('DELETE FROM wp_new_student_user WHERE id
='.$_REQUEST['id']);
$wpdb->show_errors();
if($delete_row)
{
$url_location=get_site_url()."/my-account-parent/?
regNumber=".$_REQUEST['parentId']."&type=par&back_list=yes";
?>
<script type="text/javascript">
window.location.href="<?php echo $url_location;?>";
</script>
<?php
}
}
Please use PHP UNLINK function to delete the file
if($delete_row)
{
unlink(Path to the file);
}
<?php if ($data == "") { ?>
<script type="text/javascript">
alert("review your answer1");
window.location.href = "index1.php";
</script>
<?php } else { ?>
<script type="text/javascript">
alert("review your answer2");
window.location.href = "index2.php";
</script>
<?php } ?>
Alert box is not showing in above code as well as page is also not redirecting.
What is wrong in it?
Do the other way around:
<script>
var data = <?php echo $data; ?>
if ( data === "" ) {
alert("review your answer1");
window.location.href = "index1.php";
} else {
alert("review your answer2");
window.location.href = "index2.php";
}
</script>
Improving your code, it may require some adaptation:
<script>
alert("review your answer<?echo $data;?>");
window.location.href = "index<?echo $data;?>.php";
</script>
I have a code which insert some values into a database table. It is working properly. I wont to get errors like database connecting errors,duplicate entry. Here is my code.
Untitled Document
<body>
<?php
require '../classes/dbconnect.php';
$PId=$_POST["PatientId"];
$pName=$_POST["NameOfPatient"];
$age=$_POST["AgeOfPatient"];
$lId=$_SESSION['username'];
$fbs=$_POST["FBS"];
$sc=$_POST["Serum"];
$bu=$_POST["urea"];
$sgot=$_POST["sgot"];
$sgpt=$_POST["sgpt"];
$sa=$_POST["SAP"];
$sp=$_POST["protein"];
$sea=$_POST["albumin"];
$globulin=$_POST["globulin"];
$date=$_POST["date"];
$_SESSION['FBS'] = $fbs;
$db = new Database("localhost", "root", "", "mlab");
$x = $db->insert("INSERT INTO blood_report VALUES
('$PId','$lId','$date','$pName','$age','$fbs','$sc','$bu','$sgot','$sgpt','$s a','$sp','$sea','$globulin')");
if($x == 1){
header("Location:../bloodreport.php");
}else{
$str = "error :" . $db->err();
?>
<script>
var erro= '<?php echo "error :" . $db->err(); ?>';
</script>
<?php
//echo $str;
echo '<script type="text/javascript">alert("Duplicate entry");history.go(-1);</script>';
}
echo $x;
?>
try this way
......
if($x == 1){
header("Location:../bloodreport.php");
}else{
$str = "error :" . $db->err();
?>
<script>
var erro= <?php echo '"error : ' . $db->err() . '"'; ?>;
</script>
......
You can wrap each critical statement in try...catch block and logging error.
try {
$db = new Database("localhost", "root", "", "mlab");
} catch (Exception $e) {
$errString = $e->getMessage();
}
try {
$x = $db->insert("INSERT INTO blood_report VALUES
('$PId','$lId','$date','$pName','$age','$fbs','$sc','$bu','$sgot','$sgpt','$s a','$sp','$sea','$globulin')");
} catch (Exception $e) {
$errString = $e->getMessage();
}
EDIT
Later do :
<?php if (isset($errString) && $errString !== '') { ?>
<script>
var error = "<?php echo 'error : ' . $errString; ?>";
alert(error);
</script>
<?php } ?>
Also validate post before insertion http://php.net/manual/en/function.filter-input.php
I am trying to set an alert message if the message has been sent successfully or if an error occurs.
This is the following error when I run and click the "Send Mail" button in my html page.
Error: Microsoft JScript runtime error: Unable to get value of the
property 'addClass': object is null or undefined
This is my PHP code snippet:
if(#mail($to,$subject,$message,$header)) $send = true; else $send = false;
if(isset($_POST['email'])){
if ($send)
{
echo '<script language="javascript">';
echo 'alert("Mail has been Sent Successfully")';
echo '</script>';
exit;
}
else
{
echo '<script language="javascript">';
echo 'alert("ERROR")';
echo '</script>';
exit;
}
This is my jQuery snippet:
function tfuse_custom_form(){
var my_error;
var url = jQuery("input[name=temp_url]").attr('value');
jQuery("#send").bind("click", function(){
my_error = false;
jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").each(function(i)
{
var surrounding_element = jQuery(this);
var value = jQuery(this).attr("value");
var check_for = jQuery(this).attr("id");
var required = jQuery(this).hasClass("required");
if(check_for == "email")
{
surrounding_element.removeClass("error valid");
baseclases = surrounding_element.attr("class");
if(!value.match(/^\w[\w|\.|\-]+#\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/))
{
surrounding_element.attr("class",baseclases).addClass("error");
my_error = true;
}
else
{
surrounding_element.attr("class",baseclases).addClass("valid");
}
}
if(check_for == "message")
{
surrounding_element.removeClass("error valid");
baseclases = surrounding_element.attr("class");
if(value == "" || value == "Write your message...")
{
surrounding_element.attr("class",baseclases).addClass("error");
my_error = true;
}
else
{
surrounding_element.attr("class",baseclases).addClass("valid");
}
}
if(required && check_for != "email" && check_for != "message")
{
surrounding_element.removeClass("error valid");
baseclases = surrounding_element.attr("class");
if(value == "")
{
surrounding_element.attr("class",baseclases).addClass("error");
my_error = true;
}
else
{
surrounding_element.attr("class",baseclases).addClass("valid");
}
}
}
First compare this code and then replace it simply if you want to jquery in php
add this code in php file.
1).
<?php echo '<script language="javascript">
alert("Mail has been Sent Successfully");
</script>';
?>
2).
if ($send)
{
echo '<script language="javascript">
alert("Mail has been Sent Successfully");
</script>';
exit;
}
else
{
echo '<script language="javascript">
alert("ERROR")'
</script>';
exit;
}