header location not working on live but working in localhost - php

include "include/connection.php";
$date= date("Y-m-d H:i:s");
$profile_comment="INSERT INTO `infotown_test`.`profile_comments` (`id`, `user_id`, `name`, `email`, `comments`, `date_and_time`) VALUES (NULL, '".$_REQUEST['user_id']."', '".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['comment']."', '".$date."')";
mysql_query($profile_comment);
header("location:company-profile.php?id=2");(why it's not working?)

Make the "location" Capital to "Location",
header("Location:company-profile.php?id=2");

Related

MYSQL Column Count error in sql query of project in PHP

$logquery="INSERT INTO new_data_entry_log (directory,ip,description,state,status,instituteid,email,category,bandwidth,project,institutehead,contactnumber,landlinenumber,latitude,longitude,clientip,added by,added on,added at) VALUES ('$directory','$ipaddress','$description','$state','$status','$instituteid','$contactemail','$bandwidth','$institutehead','$contactNumber','$contactlandlinenumber','$latitude','$longitude','$clientip','$name','$currentdate','$currenttime')";
I can see there is a mismatch of columns count and related values count. Probably it might be the issue.
Did you try with removing the single quates of the variables?
I have formated your query.
Formated Query
$logquery="INSERT INTO `new_data_entry_log`(
`directory`,
`ip`,
`description`,
`state`,
`status`,
`instituteid`,
`email`,
`category`,
`bandwidth`,
`project`,
`institutehead`,
`contactnumber`,
`landlinenumber`,
`latitude`,
`longitude`,
`clientip`,
`added by`,
`added on`,
`added at`
) VALUES(
'$directory',
'$ipaddress',
'$description',
'$state',
'$status',
'$instituteid',
'$contactemail',
'$bandwidth',
'$institutehead',
'$contactNumber',
'$contactlandlinenumber',
'$latitude',
'$longitude',
'$clientip',
'$name',
'$currentdate',
'$currenttime'
)";
In your code
new_data_entry_log(19 property)
But
VALUES(17 values)
This is the main reason. Another reason can be data type issue.
Because you set all values as String/Varchar
Note: best practice(underscore) for database fields
`added by` --> 'added_by'
`added on` --> 'added_on'
`added at` --> 'added_at'

how to insert current date in database

I have a date field with CURRENT_TIMESTAMP attribute. and I am trying to insert date in the database but the value storing as '0000-00-00 00:00:00'.
My code:
<?php
if (isset($_POST['submit'])) {
$amount = $_POST['amount'];
$sql = "insert into `od_request` (`username`, `amount`, `status`, `date`) values ('$login_session', '$amount', 'Request', 'NOW()')";
$retval = mysql_query($sql);
if($retval) {
$success= "OD Request Sucessfully Sent!";
} else {
$error = "Sorry! Make sure you have entered all the Fields Correctly.";
}
}
?>
Use this request :
INSERT INTO `od_request` (`username`, `amount`, `status`, `date`) VALUES('$login_session', '$amount', 'Request', NOW())
You don't need to put ' around NOW() because is an SQL function
Syntax to insert date is wrong:
use NOW() not 'NOW()'
$sql = "insert into `od_request` (`username`, `amount`, `status`, `date`) values ('$login_session', '$amount', 'Request', NOW())";
date("Y-m-d H:i:s") is the MySQL datetime format
eg.
$sql = "insert into `od_request` (`username`, `amount`, `status`, `date`) values ('$login_session', '$amount', 'Request', '".date("Y-m-d H:i:s")."')"
what about this?
$sql = "insert into 'od_request' ('username', 'amount', 'status', 'date') values ('$login_session', '$amount', 'Request', NOW())"

sing Variable in MySQL

Using Variable in MySQL
I have tried many possibilities and consulted a number of sources but still not have been
able to insert a string into a MySQL command in php.
Code below works well
$SQL = 'INSERT INTO tb_addressbook (`ID`, `First_Name`, `Last_Name`, `Address`) VALUES (\'24\', \'JJ\', \'Gates\', \'Microsoft\');';
Code below does not work
$SQL = 'INSERT INTO tb_addressbook (`ID`, `First_Name`, `Last_Name`, `Address`) VALUES (\'27\', \''.'"$first"'.'\''.', \'Gates\', \'Microsoft\');';
Can you help?
P.S. Is there a special way to insert a string for numbers?
Hugh
hugh#hahaggerty.com
Try like this :
$SQL = "INSERT INTO tb_addressbook (ID, First_Name, Last_Name, Address) VALUES ('27', '".$first."', 'Gates', 'Microsoft')";

Why doesn't my SQL insert into work?

I know questions like this exist all over, but I can't see what's wrong with my code. The DB works and I run an update query just fine earlier on in the code.
Query 1:
mysql_query("INSERT INTO `login_history` (`memberid`, `ip`, `host`, `location`, `status`, `date`) VALUES ('".$login."', '".$ip."', '".$details->hostname."', '".$loc."', 'success', NOW()");
Query 2:
mysql_query("INSERT INTO `login_history` (`memberid`, `ip`, `host`, `location`, `status`, `date`) VALUES ('".$login."', '".$ip."', '".$details->hostname."', '".$loc."', 'failure', NOW()");
Here is an echo of the string as requested:
INSERT INTO `login_history` (`memberid`, `ip`, `host`, `location`, `status`, `date`) VALUES ('AAL', '**.60.**.**', 'c-174-**-**-**.hsd1.**.comcast.net', 'Town, US', 'success', NOW()
Looks like you are missing the final closing ). Also use prepared statements. Much cleaner and safer. Here is a quick example of what a Prepared Statement would look like (adapted from here) (you wold also need to make other changes to your PHP script to start using them)
$stmt = $mysqli->prepare("INSERT INTO `login_history` (`memberid`, `ip`, `host`, `location`, `status`, `date`) VALUES (?, ?, ?, ?, ?, NOW())")
$stmt->bind_param('sssss', $login, $ip, $details->hostname, $loc, 'failure');
$stmt->execute()

Why my database do not get vars sent from mysql_query();?

My connection to database works properly, but when I Send some information it does not update.
$name = mysql_escape_string($_POST['name']);
$mail = mysql_escape_string($_POST['mail1']);
$pass = mysql_escape_string($_POST['pass1']);
mysql_query("INSERT INTO `usrs` (`id`, `username`, `email`, `password`) VALUES (`NULL`, `$name`, `$mail`, `$pass`)");
I use to check data tables by:
MariaDB [BattleShip]> SELECT * FROM usrs;
output from this:
EMPTY set (0.00sec)
If your id is auto increment, don't include this column in query
...and replace value quote by '
mysql_query("INSERT INTO `usrs` (`username`, `email`, `password`) VALUES ('$name', '$mail', '$pass')");

Categories