PHP - Connecting To Google Api V3
Hey all
I'm working on a script which needs to connect to the Google Calendar API, but when I run the code I get
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'' in /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php:341 Stack trace: #0 /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php(300): Google_Auth_OAuth2->refreshTokenRequest(Array) #1 /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php(230): Google_Auth_OAuth2->refreshTokenWithAssertion() #2 /home/public_html/cal_test/google-api-php/src/Google/Service/Resource.php(171): Google_Auth_OAuth2->sign(Object(Google_Http_Request)) #3 /home/public_html/cal_test/google-api-php/src/Google/Service/Calendar.php(1133): Google_Service_Resource->call('list', Array, 'Google_Service_...') #4 /home/public_html/cal_test/index.php(34): Google_Service_Calendar_CalendarList_Resource->listCalendarList() #5 {main} thrown in /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php on line 341The code i'm using is <?php error_reporting(-1); ini_set('display_errors', 'On'); require_once "google-api-php/src/Google/Client.php"; require_once "google-api-php/src/Google/Service/Calendar.php"; // Service Account info $client_id = 'CLIENT_ID'; $service_account_name = 'EMAIL'; $key_file_location = 'FILE_LOC'; // Calendar id $calName = 'CAL_ID'; $client = new Google_Client(); $client->setApplicationName("Calendar test"); $service = new Google_Service_Calendar($client); $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/calendar.readonly'), $key ); $client->setAssertionCredentials($cred); $cals = $service->calendarList->listCalendarList(); //print_r($cals); //exit; $events = $service->events->listEvents($calName); foreach ($events->getItems() as $event) { echo $event->getSummary(); } ?>i've spent serveral hours trying to locate a fix on Google, but so far i'm stuggling Can anyone help me? Thanks Edited by dweb, 09 October 2014 - 06:58 AM. Similar TutorialsHi there, I'm working on a project already started, and using WAMP+WINDOWS7+SQL2008R2, At this point it's connecting to a MSSQL DATABSE LIKE THIS: $dns = "TempGes2"; $con = odbc_connect($dns, $user, $pwd); This works fine, but i can't find where is the TempGes2 configured, it isn't in the odbcad32.exe, Any ideas, i need to point this to another DATABASE, Thank you in advance So I'm currently watching this tutorial : http://youtu.be/9E0s4gsUeU0 And am trying to build the sample application shown there. However I do seem to run into some problems, so if someone could take the time to help me out; I would be very grateful! --- The application is a simple HTML form, which takes the data input and stores it into a MySQL database table. My project is organized as this : The actual form is stored on the insert.php file. Code: [Select] <?php include_once('resources/init.php'); if (isset($_POST['title'], $_POST['post'])) { // functions go here! } ?> <html> <head> <title> Post something! </title> </head> <body> <div id="form"> <form method="POST" action= " "> <label for="title">Title:</label><br> <input type="text" name="title" id="title" /><br> <label for="post">Post:</label><br> <textarea name="post" id="post" rows="15" cols="50"></textarea><br> </form> </div> </body> </html> The config.php and init.php are the configuration and initialize files. config.php Code: [Select] <?php $config['DB_HOST'] = 'localhost'; $config['DB_USER'] = 'root'; $config['DB_PASS'] = ''; $config['DB_NAME'] = 'form'; //foreach ( $config as $k => $v ) { // define(strtouper($k), $v); //} ?> init.php Code: [Select] <?php include_once('config.php'); mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); ?> --- When I try this in my browser I get the error : Code: [Select] Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'DB_HOST' (11004) in C:\xampp\htdocs\form\resources\init.php on line 5 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\form\resources\init.php on line 6 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\xampp\htdocs\form\resources\init.php on line 6 Could someone tell me what is wrong? Thanks in advance! Hi all.
My database just stopped connecting? I have tried everything i could but no way! What could have happened and what can i do? I even went as far as creating the database connection inside the page to see if it will work but still no way!
Thanks Hi, my school say not to use XAMPP, and I already have PHP installed, MySQL installed, Apache I am not sure, but assuming if I have it installed, how do I connect to localhost b/c beforer when I use XAMPP, the default for where to get php/mysql running was: C:\xampp\htdocs\ Please any help appreciated! Can someone tell me why in the following code, in the 'try' section, this code works: (first line after 'try')
$conn = new PDO("mysql:host=$servername;dbname=$dbasename", $username, $password); even though I have not declared a variable named $dbname,
but if I change it to "$databasename", which I have declared, it doesn't work. I don't understand that.
<code>
<?php Windows 2012 R2 Web Farm IIs 8.5 PHP 7.2
I am trying to create a logon page using PHP create a database on my SQL 2014 server. Installed the PHP SQL Server Drivers for PHP 7.2
<?php
// Connect to MSSQL
if (!$link) { I get an HTTP 500 internal server error cant get past this one Any thing else I can provide to help us fix this let me know
Thank you
Tom I have the following code created, however when i run it it doesn't come back as saying connected successfully?
<?php $host = "localhost"; $my_user = "root"; $my_password = ""; $my_db = "notes_db" $con = mysqli_connect("localhost","my_user","my_password","my_db"); echo ("Connected Successfully"); ?> Hello again guys! What if i have 2 databases, db1 and db2. i want to read raw data from db1 and match it's content with data from db2, then produce some information. How can i do it at the same time? I know that to be able to access mysql data, we have to use the mysql_connect() and mysql_select_db(). mysql_select_db() only allows to connect to single database. what should i do? thanks for your help in advance. Dear All, I am having 2 different DB on 2 different hosts. I am running MySQL Server on my local PC where the user is entering data in the tables. I have a website which has the identical DB on the web. I am able to connect to the database by using the codes on the server. I want to update the server DB with the local system DB by running one update command. I get the error "-SELECT command denied to user 'localusername'@'localhost' for table 'pst_data'" Given below is the code used for the process : //connecting the remote system DB $link = mysql_connect('IPAddress:3306', 'remoteusername', 'Password'); if (!$link) { die('Not connected : ' . mysql_error()); } $db_selected = mysql_select_db('remotedb', $link); if (!$db_selected) { die ('Can\'t use Remote System DB: ' . mysql_error()); } //connecting the local database on the webstite $weblink = mysql_connect("localhost","localusername","password"); if (!$weblink) { die('Not connected : ' . mysql_error()); } $webdb_selected = mysql_select_db('localwebdb', $weblink); if (!$webdb_selected) { die ('Can\'t use WebServer Database : ' . mysql_error()); } //query to fetch the records from remote ystem and insert into local website database $upd_Query=mysql_query("INSERT INTO localwebdb.`table` SELECT * FROM remotedb.`table` where field=' some condition' "); --------------------------------------------------- I have tested that I have connected the remote DB by running queries on the webserver. Could anyone bail me out so that i can copy the DB from remote to local Any help would be appreciated So I've followed this code, corrected about 12 error, talked to my hosting and I am so done. I have tried everything but the error won't go away. The code is pasted below. As it's really late any help would be appreciated that would make my day the next day...
<?PHP Hi. For a uni assignment I am turning my static prototype into a dynamic prototype and adding various features like templates, log in system and the ability to add/delete information stored on the database and view the information on the website. I have running into a problem though, I am having difficulties getting connected to the database, I don't know if this is something to do with the log in information though, below I have quoted the files. update.php (the script I use to connect to the database) Quote <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $name = $_POST['name']; $sname = $_POST['sname']; $address = $_POST['address']; $number = $_POST['number']; mysql_connect("localhost", "", "") or die ('error: ' .mysql_error()); mysql_select_db ("bza410_test"); $query="INSERT INTO testTable (id, firstname, surname, address, phone)VALUES ('NULL','".$name."', '".$sname."', '".$address."', '".$number."')"; mysql_query($query) or die ('error updating database'); echo "database updated with: " .$name. " ".$sname." ".$address." ".$number ; ?> after localhost I am aware password/username goes there, just removed them for obvious reasons. home.php Quote <?php $pagetitle = 'Welcome to ENSI'; require 'template/header.php'; ?> <p> This web page page was created on <strong> <?php echo date('l F jS \a\t Y h:i:s A \,'); if (date('H') < 12) { echo ' RISE AND SHINE!!!,'; } else { echo ' TIME TO SLEEP!!!,'; } ?> </strong> on the computer that is running on PHP. </p> <div> <p><strong>Please enter your name and birthday:-</strong></p> <form method="post" action="update.php"> <fieldset> <legend>Details</legend> <label>First Name:</label> <input type="text" name="name" /> <br/> <label> Surname:</label> <input type="text" name="sname" /> <br/> <label> Address </label> <input type="text" name="address" /> <br/> <label>Phone</label> <input type="text" name="number" /> <br/> <input type="submit" name="submit" value="submit" /> <input type="reset" name="reset" value="reset" /> </fieldset> </form> <?php if(isset ($_POST['submit'])) { $name = $_POST['name']; $sname = $_POST['sname']; $address = $_POST['address']; $number = $_POST['number']; echo htmlentities ($text); echo 'Hello, your first name is ' .$name; echo ' Your surname is ' .$sname; echo ' Your address is - ' .$address; echo ', Your phone number is - ' .$number; } ?> </div> <?php require 'template/footer.php'; ?> When I fill in the form and then press submit it goes to "error updating database" from the script, so have I got the server information wrong? Thanks Will. I have "UPC" setup as a system dsn, type "CodeBaseOdbcStand", and I can connect to it from access. However, I am not having success yet using php. This is a connection to .dbf /.cdx files for data associated with our inventory program. ERROR Code: [Select] PHP Warning: odbc_connect() [<a href='function.odbc-connect'>function.odbc-connect</a>]: SQL error: [Simba][SimbaEngine ODBC Driver][DRM File Library]No such database., SQL state 08004 in SQLConnect in C:\Inetpub\wwwroot\test.php on line 6 CODE Code: [Select] <html> <body> <?php $conn=odbc_connect('UPC','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM ARUPC"; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table><tr>"; echo "<th>UPC</th>"; echo "<th>ITEM</th></tr>"; while (odbc_fetch_row($rs)) { $UPC=odbc_result($rs,"UPC"); $ITEM=odbc_result($rs,"ITEM"); echo "<tr><td>$UPC</td>"; echo "<td>$ITEM</td></tr>"; } odbc_close($conn); echo "</table>"; ?> </body> </html> I am moving a site from another server to a new one. I have changed all the code snippets to reflect the new server and the new database but for some reason when I come to login it will not take me further. I know that the code has connected to the database as I have a userlog table on there telling me I when I logged in last. elow is my login.php (there is obviously more than the code included) Code: [Select] <? require 'include/common.inc.php'; require 'include/session.inc.php'; if(($u_username != "") || ($u_password != "")) { $funcResult = authenticateUser($u_username, $u_password, $chkRemember); if(!$funcResult->returnValue) { header("Location: login.php?msg=" . $funcResult->errorMessage); echo "ERROR: " . $funcResult->errorMessage; } else { if($artid!="") { header("Location: news/readarticle.php?artid=$artid"); } else { if($funcResult->errorMessage == "M") { header("Location: members/index.php"); exit; } elseif($funcResult->errorMessage == "B") { header("Location: business/index.php"); exit; } $msg = "Invalid UserName/Password"; } } } ?> <html> <head> <title>Welcome to Newquay Uncovered</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="images/style.css" rel="stylesheet" type="text/css"> <script language="Javascript"> <!-- function validate(frm) { for(i=0;i<frm.length;i++) { if((frm.elements[i].type == "text" || frm.elements[i].type == "password") && frm.elements[i].value == "") { alert("Please fill in the required details"); frm.elements[i].focus(); return false; } } return true; } //--> </script> Here is Common Code: [Select] <? require '/home/xmasphot/public_html/www.newquayuncovered.com/include/db.inc.php'; // require '/dump/ldev/newquayuncovered/revamped/include/db.inc.php'; // USER UPLOAD FOLDER $uploaddir = "/home/xmasphot/public_html/www.newquayuncovered.com/members/uploads/"; // $uploaddir = "/dump/ldev/newquayuncovered/revamped/members/uploads/"; $pic_path = "/members/uploads/"; $nophoto = "/images/nophoto.jpg"; $pending = "/images/pending.jpg"; $fromemailaddresss = "help@newquayuncovered.com"; global $sportspicpath; global $sports_rpicpath; // $sports_rpicpath = "/dump/ldev/newquayuncovered/revamped/admin/sports/images/"; // $sports_picpath = "/newquayuncovered/revamped/admin/sports/images/"; $sports_rpicpath = "/home/xmasphot/public_html/www.newquayuncovered.com/admin/sports/images/"; $sports_picpath = "/admin/sports/images/"; if ($uid == "") { $uid = 0; } function sendErrorPage($mesg) { echo "Error Generated: <BR>$mesg"; exit; } function getDateString() { /* The function getDateString() returns the current date in the * format YYYY-MM-DD. This function is used when inserting date * columns into MySQL table */ return date(Y-m-d); } function getCountry($chk) { $query = "SELECT c_cid, c_cname FROM nq_country ORDER BY c_cname"; $results = mysql_query($query); echo "<option value=''><-- Select --></option>"; while($row = mysql_fetch_object($results)) { if($chk == $row->c_cid) { echo "<option value='$row->c_cid' selected>$row->c_cname</option>\n"; } else { echo "<option value='$row->c_cid'>$row->c_cname</option>\n"; } } } function getGender($chk) { echo "<option value=''><-- Select --></option>\n"; if($chk != "" && $chk == 0) { echo "<option value=0 selected>Female</option>\n"; } else { echo "<option value=0>Female</option>\n"; } if($chk == 1) { echo "<option value=1 selected>Male</option>\n"; } else { echo "<option value=1>Male</option>\n"; } } function getSexuality($chk, $type="") { $arrVals = array( "R" => "Rather Not Say", "S" => "Straight", "O" => "Open Minded", "G" => "Gay/Lesbian", "B" => "BiSexual" ); if($type == 1) { echo $arrVals[$chk]; return; } echo "<option value=''><-- Select --></option>\n"; foreach($arrVals as $abbr=>$val) { if($abbr == $chk) { echo "<option value='" . $abbr . "' selected>" . $val . "</option>\n"; } else { echo "<option value='" . $abbr . "'>" . $val . "</option>\n"; } } } function getDOB_Date($chk) { echo "<option>--</option>\n"; for($i=1; $i<=31; $i++) { if($chk == $i) { echo "<option value=$i selected>$i</option>\n"; } else { echo "<option value=$i>$i</option>\n"; } } } function getDOB_Month($chk) { echo "<option>--</option>\n"; $arr_Month = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $i = 1; foreach ($arr_Month as $temp) { if($chk == $i) { echo "<option value=$i selected>$temp</option>\n"; } else { echo "<option value=$i>$temp</option>\n"; } $i++; } } function getDOB_Year($chk) { echo "<option>--</option>\n"; for($i=1960; $i<=1999; $i++) { if($chk == $i) { echo "<option value=$i selected>$i</option>\n"; } else { echo "<option value=$i>$i</option>\n"; } } } function getDBConnection() { global $hostName, $databaseName, $userName, $password, $con; // Get a persistent database connection if(!($link = mysql_pconnect($hostName, $userName, $password))) { return new Function_Result("Internal Error: Could not open database connection", null); } // Select mysql database if(!mysql_select_db($databaseName, $link)) { return new Function_Result("Internal Error: Could not select database",null); } return new Function_Result(null, $link); } function logout() { global $uid; global $username; global $isAuthenticated; global $userType; session_start(); global $REMOTE_ADDR; // Get DB Connection $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $updStmt = "UPDATE nq_userlog SET ul_online_status=0 ,ul_last_logout=now() ,ul_last_logon_ip='$REMOTE_ADDR' WHERE ul_ulid='$uid'"; if(!mysql_query($updStmt, $link)) { return new Function_Result("Cannot update log.", null); } session_unregister("uid"); session_unregister("username"); session_unregister("isAuthenticated"); session_unregister("userType"); return new Function_Result(null, true); } class Function_Result { var $errorMessage; var $returnValue; function Function_Result($errMessage, $retValue) { $this->errorMessage = $errMessage; $this->returnValue = $retValue; } } function validateusername($u_username){ $u_username = trim($u_username); $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectUserStmt = "SELECT u_uid,u_password,u_email FROM nq_user WHERE u_username='$u_username'"; if(!($result = mysql_query($selectUserStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query", null); } if(!($row = mysql_fetch_object($result))) { return new Function_Result("Invalid UserName", null); } return new Function_Result(null,$row); } function dynamicpictures() { $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectUserStmt = "SELECT * FROM nq_pictures LEFT JOIN nq_user on pic_uid=u_uid WHERE pic_approval=1 AND pic_folder=0 AND pic_adult=0 AND pic_filename!='' AND pic_default=1 ORDER BY pic_date DESC LIMIT 5"; if(!($result = mysql_query($selectUserStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query", null); } return new Function_Result(null,$result); } function msgStatus($uid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT COUNT(*) FROM nq_message WHERE msg_to_uid=$uid AND msg_status=0"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } if(!($row = mysql_fetch_row($result))) { return new Function_Result("Internal Error: Could not assign record", null); } return new Function_Result(null, $row); } function getContact_country() { $query = "SELECT c_cname FROM nq_country ORDER BY c_cname"; $results = mysql_query($query); echo "<option value=''><-- Select --></option>"; while($row = mysql_fetch_object($results)) { echo "<option value='$row->c_cname'>$row->c_cname</option>\n"; } } function getState($ud_cid) { if ($ud_cid==130) { $qry = "limit 0, 54 " ;} elseif ($ud_cid==127) { $qry= "limit 55, 66"; } else { echo "<option value=''><-- Not Applicable --></option>"; return; } $query = "SELECT s_sid, s_sname FROM nq_state $qry" ; echo "<option value=''><-- Please Choose --></option>"; $results = mysql_query($query); while($row = mysql_fetch_object($results)) { echo "<option value='$row->s_sid'>$row->s_sname</option>\n"; } } function selectedstates($ud_cid, $chk) { if ($ud_cid==130) { $qry = "limit 0, 54 " ;} elseif ($ud_cid==127) { $qry= "limit 55, 66"; } else { echo "<option value=''><-- Not Applicable --></option>"; return; } $query = "SELECT s_sid, s_sname FROM nq_state $qry" ; echo "<option value=''><-- Please Choose --></option>"; $results = mysql_query($query); while($row = mysql_fetch_object($results)) { if($chk == $row->s_sid) { echo "<option value='$row->s_sid' selected>$row->s_sname</option>\n"; } else { echo "<option value='$row->s_sid'>$row->s_sname</option>\n"; } } } function getindexpagecontent($indexpageid) { $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectStmt = "Select * from nq_config where con_conid='$indexpageid'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query $selectStmt", null); } return new Function_Result(null,$result); } function getTop_latest_news($limit=2) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt_Top_latest_news = "SELECT *, CONCAT(LEFT(nwa_content, 90), '...') AS nwa_content FROM nq_newsarticle WHERE (nwa_topstories in (1,2,3)) and nwa_status='1' ORDER BY nwa_topstories ASC limit 0,". $limit; if(!($result_Top_latest_news = mysql_query($selectStmt_Top_latest_news, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt_Top_latest_news", null); } return new Function_Result(null, $result_Top_latest_news); } function Display_Admin_lst_evt() { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt_lst_evt = "SELECT *, DATE_FORMAT(evt_from_date, '%b %d, %Y %h:%i %p') AS evt_fromdate, DATE_FORMAT(evt_to_date, '%b %d, %Y %h:%i %p') AS evt_todate FROM nq_events WHERE evt_uid=0 order by evt_evtid desc limit 0,2"; if(!($result_lst_evt = mysql_query($selectStmt_lst_evt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query $result_lst_evt", null); } return new Function_Result(null, $result_lst_evt); } function get_News_links($name,$limit) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt_Newslink = "SELECT *, CONCAT(LEFT(nwa_content, 50), '...') AS content, CONCAT(LEFT(nwa_title, 50), '...') AS title FROM nq_newsarticle left join nq_newscategory on nwc_nwcid=nwa_nwcid WHERE nwc_name='$name' order by nwa_createdate desc limit 0 , ". $limit; if(!($result_Newslink = mysql_query($selectStmt_Newslink, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt_Newslink", null); } return new Function_Result(null, $result_Newslink); } function getNightlife_title() { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife WHERE nl_parent !=0 ORDER BY nl_lastupdated desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getNightlife_details($nl_nlid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife where nl_parent !=0 AND nl_nlid = '$nl_nlid'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getNightlife_homepage_details($nl_nlid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife where nl_parent !=1 AND nl_nlid = '$nl_nlid'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getNightlife_title_topten() { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife where nl_parent !=0 ORDER BY nl_lastupdated desc limit 0,10"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getSection($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_section where sec_secid='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTop_sectionStories($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionstory WHERE ssty_secid='$id' and ssty_position !='0' ORDER BY ssty_sstyid desc limit 0,3"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopLink($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks WHERE slnk_secid='$id' ORDER BY slnk_lastupdated desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllStories($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionstory WHERE ssty_secid='$id' ORDER BY ssty_lastupdated desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getStorydetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionstory where ssty_sstyid='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllLink($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks left join nq_section on sec_secid=slnk_secid WHERE slnk_secid='$id' ORDER BY slnk_slnkid desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getLinkdetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks WHERE slnk_slnkid='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopBeaches($limit) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; if ($limit == "") { $selectStmt = "SELECT * FROM nq_beaches where bch_position !='0' order by bch_position asc"; } else { $selectStmt = "SELECT * FROM nq_beaches where bch_position !='0' order by bch_position asc limit 0, $limit"; } if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getBeachDetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_beaches where bch_bchid ='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopBeachsafety($limit) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; if ($limit == "") { $selectStmt = "SELECT * FROM nq_beachsafety where bs_position !='0' order by bs_position asc"; } else { $selectStmt = "SELECT * FROM nq_beachsafety where bs_position !='0' order by bs_position asc limit 0, $limit"; } if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getBeachSafetyDetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_beachsafety where bs_bsid ='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopSectionCategory($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectioncategory WHERE scat_secid='$id' and scat_position !='0' ORDER BY scat_position asc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllSectionCategory($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectioncategory left join nq_section on scat_secid=sec_secid WHERE scat_secid='$id' and scat_position !=0 ORDER BY scat_position asc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllSectionArticle($id,$cat) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks left join nq_section on sec_secid=slnk_secid WHERE slnk_secid='$id' and slnk_scatid='$cat' ORDER BY slnk_slnkid desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getUserTypeCheck($name) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_user where u_username='$name'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } if(!($row = mysql_fetch_object($result))) { return new Function_Result("Could not assign records.", null); } return new Function_Result(null, $row); } function getBigAdd($secid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT count(*) as rcount FROM nq_assingbanner LEFT JOIN nq_banner ON ban_banid=ab_banid WHERE ban_bannertype=1 AND ab_secid='".$secid."'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } $rowad = mysql_fetch_object($result); if ($rowad->rcount > 0) { $rd = rand(0,$rowad->rcount)-1; if($rd < 0){ $rd = 0; } $sqlad = "SELECT * FROM nq_assingbanner LEFT JOIN nq_banner ON ban_banid=ab_banid WHERE ban_bannertype=1 AND ab_secid='".$secid."' limit $rd,1"; $resultad = mysql_query($sqlad); if(mysql_num_rows($resultad) > 0) { $rowad = mysql_fetch_object($resultad); if($rowad->ban_target == "n"){ $target = "_blank"; } else { $target = "_self"; } $ret_value="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr height=\"18\"><td height=\"62\" align=\"center\" valign=\"middle\"><a href =\"".$rowad->ban_page."\" target=\"".$target."\"><img src=\""; if($rowad->ban_image !='') { $ret_value.="/admin/images/ads/".$rowad->ban_image; } else { $ret_value.=$rowad->ban_url; } $ret_value.="\" border=\"0\" alt=\"".$rowad->ban_alttext."\"></a></td> </tr> </table>"; } return new Function_Result(null,$ret_value); } else { return new Function_Result(null,"<br>"); } } function getTwoSmallAdd($secid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $sqlad = "SELECT * FROM nq_assingbanner LEFT JOIN nq_banner ON ban_banid=ab_banid WHERE ban_bannertype=2 AND ab_secid='".$secid."' order by rand() limit 0,2"; $resultad = mysql_query($sqlad); $ret_value="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; while($rowad = mysql_fetch_object($resultad)) { if($rowad->ban_target == "n"){ $target = "_blank"; } else { $target = "_self"; } $ret_value.="<tr><td height=\"20\" valign=\"top\"><img src=\"/images/spcr.gif\" width=\"1\" height=\"1\"></td></tr><tr><td valign=\"top\"><a href=\"".$rowad->ban_page."\" target=\"".$target."\"><img src=\""; if($rowad->ban_image !='') { $ret_value.="/admin/images/ads/".$rowad->ban_image; } else { $ret_value.=$rowad->ban_url; } $ret_value.="\" border=\"0\" alt=\"".$rowad->ban_alttext."\"></a></td></tr>"; } $ret_value.="</table>"; return new Function_Result(null,$ret_value); } ?> And finally session Code: [Select] <? function setUserSession($u_uid, $u_username, $type) { global $uid; global $username; global $isAuthenticated; global $userType; session_start(); session_register("uid"); session_register("username"); session_register("isAuthenticated"); session_register("userType"); $uid = $u_uid; $username = $u_username; $isAuthenticated = true; $userType = $type; return true; } /***** SESSION HANDLING - ENDS HERE *****/ function authenticateUser($u_username, $u_password, $chkRemember) { $u_username = trim($u_username); $u_password = trim($u_password); $chkRemember=($chkRemember); if(($u_username == "") || ($u_password == "")) { sendErrorPage("The username/password you have entered is invalid. Please try again."); exit; } //$cryptPassword = crypt($u_password, CRYPT_STD_DES); // Get DB Connection $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectUserStmt = "SELECT u_uid, u_username, u_type FROM nq_user WHERE u_username='$u_username' AND u_password='$u_password' and u_status!='U'"; if(!($result = mysql_query($selectUserStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query", null); } if(!($row = mysql_fetch_row($result))) { return new Function_Result("Invalid UserName/Password", null); } else { if ($chkRemember==1){ setcookie("newquay",$row[1],time()+60*60*24*30); } else { setcookie("newquay","",time()+60*60*24*30); } setUserSession($row[0], $row[1], $row[2]); global $REMOTE_ADDR; $updStmt = "UPDATE nq_userlog SET ul_last_updated=now(), ul_last_logon_ip='$REMOTE_ADDR', ul_online_status=1 WHERE ul_ulid=$row[0]"; if(!mysql_query($updStmt, $link)) { return new Function_Result("Cannot update log.<BR>$updStmt", null); } return new Function_Result($row[2], true); } } ?> The site isn't doing anything when I enter username and password, just bringing me back to the same page. Also I am unable to access the areas of the site that are only for registered members. Any help here would be greatly apprecaited, I have spent days on this now. Thanks in advance! There are a few other bugs that need ironing out too. You can view the site at www.newquayuncovered.com How we can make the connection to ODBC in PHP If any shares the coding part then it would be great. (Table to database) Hi, I found the following tutorial on a list of Top 20 tutorials. However, I have gone through code and there doesn't seem to be any form database connection or config.php fille. So how does this code write to a database if it doesn't connect to a database? http://www.99points.info/2010/07/facebook-style-wallpost-and-comments-system-using-jquery-ajax-and-php-reloaded/ For some reason Im not able to connect to mysql database, when i fill in the form and select search, it just basically refreshes the page but does not come up with no error messages or any results from my database. any help is appreciated. HTML Code Code: [Select] <table id="tb1"> <tr> <td><p class="LOC">Location:</p></td> <td><div id="LC"> <form action="insert.php" method="post"> <select multiple="multiple" size="5" style="width: 150px;" > <option>Armley</option> <option>Chapel Allerton</option> <option>Harehills</option> <option>Headingley</option> <option>Hyde Park</option> <option>Moortown</option> <option>Roundhay</option> </select> </form> </div> </td> <td><p class="PT">Property type:</p></td> <td><div id="PS"> <form action="insert.php" method="post"> <select name="property type" style="width: 170px;"> <option value="none" selected="selected">Any</option> <option value="Houses">Houses</option> <option value="Flats / Apartments">Flats / Apartments</option> </select> </form> </div> </td><td> <div id="ptype"> <form action="insert.php" method="post"> <input type="radio" class="styled" name="ptype" value="forsale"/> For Sale <p class="increase"> <input type="radio" class="styled" name="ptype" value="forrent"/> To Rent </p> <p class="increase"> <input type="radio" class="styled" name="ptype" value="any"/> Any </p> </form> </div> </td> </tr> </table> <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <form action="insert.php" method="post"> <select name="number of bedrooms"> <option value="none" selected="selected">No Min</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> to <select name="number of bedrooms"> <option value="none" selected="selected">No Max</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </form> </div> </td> <td><p class="PR">Price range:</p></td> <td><div id="PR"> <form action="insert.php" method="post"> <select name="price range"> <option value="none" selected="selected">No Min</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> to <select name="price range"> <option value="none" selected="selected">No Max</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> </form> </div> </td> </tr> </table> PHP Code Code: [Select] <?php $server = ""; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use $result = mysql_query("SELECT * FROM tablename"); // Query database while($row = mysql_fetch_array($result)) { // Loop through results echo "<b>" . $row['id'] . "</b><br>\n"; // Where 'id' is the column/field title in the database echo $row['location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo $row['property_type'] . "<br>\n"; // as above echo $row['number_of_bedrooms'] . "<br>\n"; // .. echo $row['purchase_type'] . "<br>\n"; // .. echo $row['price_range'] . "<br>\n"; // .. } mysql_close($con); // Close the connection to the database after results, not before. ?> To connect to my database I an entering mysql database details just at the first top lines server,username,password and database. is thats correct? Thank You for your help in adavance. hello,
uhm, im trying to make a log-in page that will connect to the areas wifi. i can make a log-in page using php and mysql but i was wondering how to make so that when the user "logs in" he/she will be connected to a certain areas wifi.
for example, our school has a wifi hot spot in which, when you try to connect to it your'e sent to a log-in page to determine whether your'e a student (or facilitator). if you are, once you log - in your'e sent to google page and then you can use the schools wifi. if you aren't then you can't connect to it.
so now my question is how to i make a log-in page that will allow a user to connect to wifi? do i have to contact the company (the one that manages web servers like pldt) for permission? are there any policies regarding this? can it be coded using php and others?
if you can tell me then please do. thank you in advance
Hi I am trying to connect to my database but i am having some problems where the server( WAMP) crashes and does not load this page. here is the php coding
<?php $db = new PDO("mysql:host=localhost;dbname=test;port=80", "root", ""); var_dump($db);when i run this no error comes the page doesnt load. anyone know why? when using PDO do i have to do some sort of configuration changes to wamp? i have even changed the directory of the file and still same issue. any suggestions would be wonderful. If the script is not uploaded onto the server you cant use $dbc = mysql_connect('localhost', 'username', 'pass'); so how could I connect in cli? this did not work $dbc = mysql_connect('http://123.456.789.10', 'username', 'pass'); So what can I do? Thanks when I try to connect to my database with CLI I get this error Code: [Select] Access denied for user 'bommobco_cwbtest'@'cpe-123.45.789.123.neo.res.rr.com' (using password: YES) 123.45.789.123 being my ip address, how can I fix this issue so I can connect? |