Reputation: 797
I am not sure what is happening with my code, My project is running smoothly under XAMPP Server, i am able to make connection between mysql and php, But when i moved this to another system, which has mysql community server, their the code is not working, i mean database is connecting, but not able to fetch data from the database.
Sample Code is as follows:
$host='localhost'; // Host name
$username='root'; // Mysql username
$password=''; // Mysql password
$db_name='test'; // Database name
$connect=@mysql_connect($host,$username,$password) or die("Cannot Connect to database");
@mysql_select_db($db_name,$connect) or die ("Cannot find database");
app Code:
$sql="SELECT * FROM test.userdet WHERE emailId='$uName' and pwd='$pwd'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
according to $count i am redirecting it to other page.
I able to run it on other systems which has XAMPP itself, but its not running with mysql community server.
//Thanks to NullPointer, i got it by PDO, from now onwords i will continue with PDO for transactions.
Now i facing a new problem, i am calling a php_db script via ajax, after executing all PDO statements its not returning to ajax, Code snippet is below:
ajax call:-
$.ajax({
type: "POST",
url: "common/dbPhpScripts/updateEvent.php",
data: 'json=' + det,
dataType: 'json',
cache: false,
success: function () {
$('#cal').fullCalendar('refetchEvents');
$('#edit_event').dialog('close');
}
});
sample php code after using PDO:
$stringData = $_POST['json'];
$mynewarray = json_decode($stringData, true);
$title=$mynewarray['title'];
$start= $mynewarray['start'];
$end= $mynewarray['end'];
$createDate=$mynewarray['createDate'];
$insertQuery=$db->exec("INSERT INTO calendar (User_Id, StartDateTime, EndDateTime, Event_Title, Create_Date) VALUES ('07','$start','$end','$title','$createDate')");
where i am going wrong?
Upvotes: 1
Views: 1357
Reputation: 57322
its good to see what you getting in
success: function (data) {
alert("data");
}
also you need to echo result in common/dbPhpScripts/updateEvent.php
not redirect if you redirect you wont get result in ajax
Upvotes: 1
Reputation: 45124
It defiantly should be your credentials. Make sure your Username and Password are correct as well as the Database name and the Host. Different server have different credentials.
EG :
WAMP
$username='root'; // Mysql username
$password=''; // Mysql password
MAMP
$username='root'; // Mysql username
$password='root'; // Mysql password
Given remove the @
sign. Don't suppress warnings using @SuppressWarnings
Upvotes: 0