PHP - Code Help , View Tables Form A Database Via Php. (code Included.
Advance thank you.
Can you help please. The error..... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\test_dabase.php on line 24 code. Code: [Select] <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES"; //select show and show. $mysql_select2="mysql_query(".$mysql_show.") or die(mysql_error())"; } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_assoc($mysql_select2)){ //show it. echo $data; } } ?> Similar TutorialsThis topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347131.0 I have a snippet of code like this below. If I have it directly on my page, it works fine. But if I move this snippet of code into an include file and use "require_once('thefile.php');", the code no longer works properly. How is that possible? FYI, this snippet is in the middle of a for loop on the regular page. Maybe you can't use includes when in a loop? I don't know. Makes no sense that it works when on the page, but not when included using require once. Any thoughts how this could be possible? I imagine there is some rule with include files that I'm missing??? This is the code and I don't think it matters exactly what its doing so I won't bother you with that. This is how it looks on the page itself... Code: [Select] if ($type=="one") { $_SESSION['cluenum']=1; //so clue #1 begins as the selected clue echo "<script type='text/javascript'>document.getElementById('clue1').style.border = '1px solid red';</script>"; //sets the styling on clue #1 $allcode = "onclick='setnumber($i);'"; } else { // type must be equal to all, so don't do anything special $allcode=""; } This is how it looks in the include file... Code: [Select] <?php if ($type=="one") { $_SESSION['cluenum']=1; //so clue #1 begins as the selected clue echo "<script type='text/javascript'>document.getElementById('clue1').style.border = '1px solid red';</script>"; //sets the styling on clue #1 $allcode = "onclick='setnumber($i);'"; } else { // type must be equal to all, so don't do anything special $allcode=""; } ?> I have this code <?php session_start(); $error = 0; $valError = ""; // Form Page Submit Security $domain_list = explode(',',""); $ip_limit = 0; $active = 1; $active_message = <<<EOT Sorry, this form is currently disabled. EOT; include_once 'security/secure_submit.php'; include_once 'lib/utility.php'; $_SESSION["entry_key"] = isset($_SESSION["entry_key"]) ? $_SESSION["entry_key"] : md5(time() + rand(10000, 1000000)); // cname - text if(isset($_POST['cname']) && $_POST['cname'] != '') { $cname = isset($_POST['cname']) ? $_POST['cname'] : ''; $_SESSION['cname'] = $cname; } else { $error = '1'; $valError .= 'Company Name : is required.<br/>'; } if(isset($_SESSION['cname_is'])) { $_SESSION['cname_is'] = 0; } $cname = isset($_SESSION['cname']) ? $_SESSION['cname'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['cname'] = $cname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Company Name :'] = $cname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['cname'] = "Company Name :"; // dname - text if(isset($_POST['dname']) && $_POST['dname'] != '') { $dname = isset($_POST['dname']) ? $_POST['dname'] : ''; $_SESSION['dname'] = $dname; } else { $error = '1'; $valError .= 'Domain Name : is required.<br/>'; } if(isset($_SESSION['dname_is'])) { $_SESSION['dname_is'] = 0; } $dname = isset($_SESSION['dname']) ? $_SESSION['dname'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['dname'] = $dname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Domain Name :'] = $dname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['dname'] = "Domain Name :"; // ipaddress - text if(isset($_POST['ipaddress']) && $_POST['ipaddress'] != '') { $ipaddress = isset($_POST['ipaddress']) ? $_POST['ipaddress'] : ''; $_SESSION['ipaddress'] = $ipaddress; } else { $error = '1'; $valError .= 'IP Address : is required.<br/>'; } if(isset($_SESSION['ipaddress_is'])) { $_SESSION['ipaddress_is'] = 0; } $ipaddress = isset($_SESSION['ipaddress']) ? $_SESSION['ipaddress'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ipaddress'] = $ipaddress; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['IP Address :'] = $ipaddress; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ipaddress'] = "IP Address :"; // ns1 - text if(isset($_POST['ns1']) && $_POST['ns1'] != '') { $ns1 = isset($_POST['ns1']) ? $_POST['ns1'] : ''; $_SESSION['ns1'] = $ns1; } else { $error = '1'; $valError .= 'Name Server 1 : is required.<br/>'; } if(isset($_SESSION['ns1_is'])) { $_SESSION['ns1_is'] = 0; } $ns1 = isset($_SESSION['ns1']) ? $_SESSION['ns1'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ns1'] = $ns1; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Name Server 1 :'] = $ns1; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ns1'] = "Name Server 1 :"; // ns2 - text if(isset($_POST['ns2']) && $_POST['ns2'] != '') { $ns2 = isset($_POST['ns2']) ? $_POST['ns2'] : ''; $_SESSION['ns2'] = $ns2; } else { $error = '1'; $valError .= 'Name Server 2 : is required.<br/>'; } if(isset($_SESSION['ns2_is'])) { $_SESSION['ns2_is'] = 0; } $ns2 = isset($_SESSION['ns2']) ? $_SESSION['ns2'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ns2'] = $ns2; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Name Server 2 :'] = $ns2; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ns2'] = "Name Server 2 :"; // ftpserver - text if(isset($_POST['ftpserver']) && $_POST['ftpserver'] != '') { $ftpserver = isset($_POST['ftpserver']) ? $_POST['ftpserver'] : ''; $_SESSION['ftpserver'] = $ftpserver; } else { $error = '1'; $valError .= 'FTP Server Address : is required.<br/>'; } if(isset($_SESSION['ftpserver_is'])) { $_SESSION['ftpserver_is'] = 0; } $ftpserver = isset($_SESSION['ftpserver']) ? $_SESSION['ftpserver'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ftpserver'] = $ftpserver; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['FTP Server Address :'] = $ftpserver; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ftpserver'] = "FTP Server Address :"; // ftpuname - text if(isset($_POST['ftpuname']) && $_POST['ftpuname'] != '') { $ftpuname = isset($_POST['ftpuname']) ? $_POST['ftpuname'] : ''; $_SESSION['ftpuname'] = $ftpuname; } else { $error = '1'; $valError .= 'FTP Username : is required.<br/>'; } if(isset($_SESSION['ftpuname_is'])) { $_SESSION['ftpuname_is'] = 0; } $ftpuname = isset($_SESSION['ftpuname']) ? $_SESSION['ftpuname'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ftpuname'] = $ftpuname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['FTP Username :'] = $ftpuname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ftpuname'] = "FTP Username :"; // ftppword - text if(isset($_POST['ftppword']) && $_POST['ftppword'] != '') { $ftppword = isset($_POST['ftppword']) ? $_POST['ftppword'] : ''; $_SESSION['ftppword'] = $ftppword; } else { $error = '1'; $valError .= 'FTP Password : is required.<br/>'; } if(isset($_SESSION['ftppword_is'])) { $_SESSION['ftppword_is'] = 0; } $ftppword = isset($_SESSION['ftppword']) ? $_SESSION['ftppword'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ftppword'] = $ftppword; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['FTP Password :'] = $ftppword; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ftppword'] = "FTP Password :"; // pop - text if(isset($_POST['pop']) && $_POST['pop'] != '') { $pop = isset($_POST['pop']) ? $_POST['pop'] : ''; $_SESSION['pop'] = $pop; } else { $error = '1'; $valError .= 'POP : is required.<br/>'; } if(isset($_SESSION['pop_is'])) { $_SESSION['pop_is'] = 0; } $pop = isset($_SESSION['pop']) ? $_SESSION['pop'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['pop'] = $pop; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['POP :'] = $pop; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['pop'] = "POP :"; // smtp - text if(isset($_POST['smtp']) && $_POST['smtp'] != '') { $smtp = isset($_POST['smtp']) ? $_POST['smtp'] : ''; $_SESSION['smtp'] = $smtp; } else { $error = '1'; $valError .= 'SMTP : is required.<br/>'; } if(isset($_SESSION['smtp_is'])) { $_SESSION['smtp_is'] = 0; } $smtp = isset($_SESSION['smtp']) ? $_SESSION['smtp'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['smtp'] = $smtp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['SMTP :'] = $smtp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['smtp'] = "SMTP :"; // webmailaddy - text if(isset($_POST['webmailaddy']) && $_POST['webmailaddy'] != '') { $webmailaddy = isset($_POST['webmailaddy']) ? $_POST['webmailaddy'] : ''; $_SESSION['webmailaddy'] = $webmailaddy; } else { $error = '1'; $valError .= 'Webmail Address : is required.<br/>'; } if(isset($_SESSION['webmailaddy_is'])) { $_SESSION['webmailaddy_is'] = 0; } $webmailaddy = isset($_SESSION['webmailaddy']) ? $_SESSION['webmailaddy'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['webmailaddy'] = $webmailaddy; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Webmail Address :'] = $webmailaddy; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['webmailaddy'] = "Webmail Address :"; // adiskspace - text if(isset($_POST['adiskspace']) && $_POST['adiskspace'] != '') { $adiskspace = isset($_POST['adiskspace']) ? $_POST['adiskspace'] : ''; $_SESSION['adiskspace'] = $adiskspace; } else { $error = '1'; $valError .= 'Allocated Disk Space : is required.<br/>'; } if(isset($_SESSION['adiskspace_is'])) { $_SESSION['adiskspace_is'] = 0; } $adiskspace = isset($_SESSION['adiskspace']) ? $_SESSION['adiskspace'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['adiskspace'] = $adiskspace; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated Disk Space :'] = $adiskspace; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['adiskspace'] = "Allocated Disk Space :"; // ambw - text if(isset($_POST['ambw']) && $_POST['ambw'] != '') { $ambw = isset($_POST['ambw']) ? $_POST['ambw'] : ''; $_SESSION['ambw'] = $ambw; } else { $error = '1'; $valError .= 'Allocated Monthly Bandwidth : is required.<br/>'; } if(isset($_SESSION['ambw_is'])) { $_SESSION['ambw_is'] = 0; } $ambw = isset($_SESSION['ambw']) ? $_SESSION['ambw'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ambw'] = $ambw; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated Monthly Bandwidth :'] = $ambw; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ambw'] = "Allocated Monthly Bandwidth :"; // amboxes - text if(isset($_POST['amboxes']) && $_POST['amboxes'] != '') { $amboxes = isset($_POST['amboxes']) ? $_POST['amboxes'] : ''; $_SESSION['amboxes'] = $amboxes; } else { $error = '1'; $valError .= 'Allocated MailBoxes : is required.<br/>'; } if(isset($_SESSION['amboxes_is'])) { $_SESSION['amboxes_is'] = 0; } $amboxes = isset($_SESSION['amboxes']) ? $_SESSION['amboxes'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['amboxes'] = $amboxes; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated MailBoxes :'] = $amboxes; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['amboxes'] = "Allocated MailBoxes :"; // amboxquota - text if(isset($_POST['amboxquota']) && $_POST['amboxquota'] != '') { $amboxquota = isset($_POST['amboxquota']) ? $_POST['amboxquota'] : ''; $_SESSION['amboxquota'] = $amboxquota; } else { $error = '1'; $valError .= 'Allocated MailBox Quoted : is required.<br/>'; } if(isset($_SESSION['amboxquota_is'])) { $_SESSION['amboxquota_is'] = 0; } $amboxquota = isset($_SESSION['amboxquota']) ? $_SESSION['amboxquota'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['amboxquota'] = $amboxquota; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated MailBox Quoted :'] = $amboxquota; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['amboxquota'] = "Allocated MailBox Quoted :"; // adbase - text if(isset($_POST['adbase']) && $_POST['adbase'] != '') { $adbase = isset($_POST['adbase']) ? $_POST['adbase'] : ''; $_SESSION['adbase'] = $adbase; } else { $error = '1'; $valError .= 'Allocated Databases : is required.<br/>'; } if(isset($_SESSION['adbase_is'])) { $_SESSION['adbase_is'] = 0; } $adbase = isset($_SESSION['adbase']) ? $_SESSION['adbase'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['adbase'] = $adbase; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated Databases :'] = $adbase; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['adbase'] = "Allocated Databases :"; // exp - text if(isset($_POST['exp']) && $_POST['exp'] != '') { $exp = isset($_POST['exp']) ? $_POST['exp'] : ''; $_SESSION['exp'] = $exp; } else { $error = '1'; $valError .= 'Expires On : is required.<br/>'; } if(isset($_SESSION['exp_is'])) { $_SESSION['exp_is'] = 0; } $exp = isset($_SESSION['exp']) ? $_SESSION['exp'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['exp'] = $exp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Expires On :'] = $exp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['exp'] = "Expires On :"; if($error){ if(isset($_SESSION['pages']['page5.php'])) { unset($_SESSION['pages']['page5.php']); } $_SESSION["e_message"] = $valError; header("Location: index.php?section-hostingedit"); } else { $_SESSION['pages']['page5.php'] = 'pass'; // custom route code //DATABASE INTERACTION //Setup database connection $dbserver = "localhost"; $dbuname = "vri_dev"; $dbpword = "emit098nice054" //Connect to DB Server $con = mysql_connect($dbserver, $dbuname, $dbpword); if(!$con){ die('Could not connect to the database server :' . mysql_error()); echo"1"; }else{ echo"1.2"; //Select Database mysql_select_db("vri_inkcontrol", $con); //Get idcname $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']' AND dname='$_POST['dname']'"; $r = mysql_query($q); //Put idcname query into an array $r_array = mysql_fetch_assoc($r); //Store idcname result from previouse query $idcname = $r_array['idcname']; //trap duplicate records //If the number of rows returned by above query is not greater then we if(mysql_num_rows($r) == 0){ echo"2"; //Insert idcname in `tbl_hosting_cname` since id doesn't exist $q = "INSERT INTO `tbl_hosting_cname` SET cname='$_POST['cname']"; mysql_query($q); //grab the cname id in `tbl_hosting_cname` $q = "SELECT idcname FROM `tbl_hosting_cname WHERE cname='$_POST['cname']'"; $r = mysql_query($q); //now we must grab the id cname from array $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $r = mysql_query("SELECT * FROM `tbl_hosting_domain` WHERE cname='$idcname' AND dname='$_POST['dname']'"); if(mysql_num_rows($r) !== 1){ echo"3"; $q = "INSERT INTO `tbl_hosting_domain` (idcname, dname, ip, ns1, ns2, ftpaddress, ftpuname, ftppword, pop, smtp, webmailaddress, diskspace, bandwidth, nummailboxes, mailboxquota, numdatabases, exp) VALUES ('$idcname', '$_POST['dname']', '$_POST['ip']', '$_POST['ns1']', '$_POST['ns2']', '$_POST['ftpserver']', '$_POST['ftpuname']', '$_POST['ftppword']', '$_POST['pop']', '$_POST['smtp']', '$_POST['webmailaddy']', '$_POST['adiskspace']', '$_POST['ambw']', '$_POST['amboxes']', '$_POST['amboxesquota']', '$_POST['adbases']', '$_POST['exp']')"; mysql_query($q); $route = "Location: index.php?section=newaddyes"; }elseif(mysql_num_rows($r) == 1){ echo"3.2"; $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $q = "UPDATE `tbl_hosting_domain` SET ( ip = '$_POST['ip']', ns1 = '$_POST['ns1']', ns2 = '$_POST['ns2']', ftpaddress = '$_POST['ftpserver']', ftpuname = '$_POST['ftpuname']', ftppword = '$_POST['ftppword']', pop = '$_POST['pop']', smtp = '$_POST['smtp']', webmailaddress = '$_POST['webmailaddy']', diskspace = '$_POST['adiskspace']', bandwidth = '$_POST['ambw']', nummailboxes = '$_POST['amboxes']', mailboxquota = '$_POST['amboxesquota']', numdatabases = '$_POST['adbases']', exp = '$_POST['exp']' WHERE cname='$idcname'"; $route = "Location: index.php?section=newaddyes"; }else{ echo"lsr1" $route = "Location: index.php?section=newaddno"; } // conditional route code // default action header($route); } ?> the code that will not run is // custom route code //DATABASE INTERACTION //Setup database connection $dbserver = "localhost"; $dbuname = "vri_dev"; $dbpword = "emit098nice054" //Connect to DB Server $con = mysql_connect($dbserver, $dbuname, $dbpword); if(!$con){ die('Could not connect to the database server :' . mysql_error()); echo"1"; }else{ echo"1.2"; //Select Database mysql_select_db("vri_inkcontrol", $con); //Get idcname $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']' AND dname='$_POST['dname']'"; $r = mysql_query($q); //Put idcname query into an array $r_array = mysql_fetch_assoc($r); //Store idcname result from previouse query $idcname = $r_array['idcname']; //trap duplicate records //If the number of rows returned by above query is not greater then we if(mysql_num_rows($r) == 0){ echo"2"; //Insert idcname in `tbl_hosting_cname` since id doesn't exist $q = "INSERT INTO `tbl_hosting_cname` SET cname='$_POST['cname']"; mysql_query($q); //grab the cname id in `tbl_hosting_cname` $q = "SELECT idcname FROM `tbl_hosting_cname WHERE cname='$_POST['cname']'"; $r = mysql_query($q); //now we must grab the id cname from array $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $r = mysql_query("SELECT * FROM `tbl_hosting_domain` WHERE cname='$idcname' AND dname='$_POST['dname']'"); if(mysql_num_rows($r) !== 1){ echo"3"; $q = "INSERT INTO `tbl_hosting_domain` (idcname, dname, ip, ns1, ns2, ftpaddress, ftpuname, ftppword, pop, smtp, webmailaddress, diskspace, bandwidth, nummailboxes, mailboxquota, numdatabases, exp) VALUES ('$idcname', '$_POST['dname']', '$_POST['ip']', '$_POST['ns1']', '$_POST['ns2']', '$_POST['ftpserver']', '$_POST['ftpuname']', '$_POST['ftppword']', '$_POST['pop']', '$_POST['smtp']', '$_POST['webmailaddy']', '$_POST['adiskspace']', '$_POST['ambw']', '$_POST['amboxes']', '$_POST['amboxesquota']', '$_POST['adbases']', '$_POST['exp']')"; mysql_query($q); $route = "Location: index.php?section=newaddyes"; }elseif(mysql_num_rows($r) == 1){ echo"3.2"; $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $q = "UPDATE `tbl_hosting_domain` SET ( ip = '$_POST['ip']', ns1 = '$_POST['ns1']', ns2 = '$_POST['ns2']', ftpaddress = '$_POST['ftpserver']', ftpuname = '$_POST['ftpuname']', ftppword = '$_POST['ftppword']', pop = '$_POST['pop']', smtp = '$_POST['smtp']', webmailaddress = '$_POST['webmailaddy']', diskspace = '$_POST['adiskspace']', bandwidth = '$_POST['ambw']', nummailboxes = '$_POST['amboxes']', mailboxquota = '$_POST['amboxesquota']', numdatabases = '$_POST['adbases']', exp = '$_POST['exp']' WHERE cname='$idcname'"; $route = "Location: index.php?section=newaddyes"; }else{ echo"lsr1" $route = "Location: index.php?section=newaddno"; } If everything on the form passes it should process the data into the database. However it is not. I placed echo statements to see where it was getting to in the database interaction portion of the code but no dice. Any help is apreciated, thanks in advance. Hey All, I will be marketing a simple php script shortly and would like to Obfuscate my code and have it check to see if the person is running the script on the proper domain, much like other Purchased Scripts, you have to buy licenses and some are limited to a Per Domain basis. Could I use cURL to run a script on another server (mine) that takes the URL it came from, and a variable "the auth key" and check if the person is using the script on the proper domain? If the domain and auth key don't match in the DB i would return a message saying invalid key or something, else continue to execute the script. <?php //authkey would be defined in config file $authkey = "769870afhljkzxf90436"; $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,"http://example.com/page.php?authkey=$authkey"); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); if (empty($buffer)) { print "Sorry, AuthServ is performing maintenance.....<p>"; } else { print $buffer; } ?> Is there a smarter way to do this? I don't have an extra 300 bucks to use something like ioncube, just looking for a general proper direction on going about this as I am totally clueless. thanks looking for a way to view the PHP source code of any PHP page on the web. Looking for a way to obtain PHP source code in order to help me with a certain issue. Advise. Hello all, i have a feeling im doing something wrong, but i have no idea what. being server-side code, php should not show when you 'view page source' in your browser (or rather it should display as html), correct ? why, then am i seeing php code when i view page source? see attached image Hey everyone, So here is my problem. I have some code to display the amount of views that page has got. In this case it is the thread in my forums section. I have used the same code to show how many people have views a certain persons profile page and that works fine but when I use it on my forum thread page I get this error. Quote You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='20' LIMIT 1' at line 1 Here is the section of code: Code: [Select] <?php $thread_id = preg_replace('#[^0-9]#i', '', $_GET['id']); $getThreadViews = mysql_query("SELECT view_count FROM forum_posts WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); $row = mysql_fetch_assoc($getThreadViews); $counter = $row['view_count']; if($counter == 0){ $counter = 1; $startCounter = mysql_query("INSERT INTO forum_posts (view_count) VALUES ('$counter') WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); } $threadViews = $counter+1; $appendCounter = mysql_query("UPDATE forum_posts SET view_count='$view_count' WHERE id='$thread_id'") or die (mysql_error()); ?> I have checked that there are no spelling errors so just wanted to show it to a fresh pair of eyes because its really starting to annoy me. Thanks in advance for any help. Hi, I'm looking for a code to view the date of the past weekdays. Forexample, if it's thursday, I want it to view the dates for wednesday, tuesday, monday, Friday before. Thank you in advance. Hi, I need to insert some code into my current form code which will check to see if a username exist and if so will display an echo message. If it does not exist will post the form (assuming everything else is filled in correctly). I have tried some code in a few places but it doesn't work correctly as I get the username message exist no matter what. I think I am inserting the code into the wrong area, so need assistance as to how to incorporate the username check code. $sql="select * from Profile where username = '$username'; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(mysql_num_rows($result)!=0) { process form } else { echo "That username already exist!"; } the current code of the form <?PHP //session_start(); require_once "formvalidator.php"; $show_form=true; if (!isset($_POST['Submit'])) { $human_number1 = rand(1, 12); $human_number2 = rand(1, 38); $human_answer = $human_number1 + $human_number2; $_SESSION['check_answer'] = $human_answer; } if(isset($_POST['Submit'])) { if (!isset($_SESSION['check_answer'])) { echo "<p>Error: Answer session not set</p>"; } if($_POST['math'] != $_SESSION['check_answer']) { echo "<p>You did not pass the human check.</p>"; exit(); } $validator = new FormValidator(); $validator->addValidation("FirstName","req","Please fill in FirstName"); $validator->addValidation("LastName","req","Please fill in LastName"); $validator->addValidation("UserName","req","Please fill in UserName"); $validator->addValidation("Password","req","Please fill in a Password"); $validator->addValidation("Password2","req","Please re-enter your password"); $validator->addValidation("Password2","eqelmnt=Password","Your passwords do not match!"); $validator->addValidation("email","email","The input for Email should be a valid email value"); $validator->addValidation("email","req","Please fill in Email"); $validator->addValidation("Zip","req","Please fill in your Zip Code"); $validator->addValidation("Security","req","Please fill in your Security Question"); $validator->addValidation("Security2","req","Please fill in your Security Answer"); if($validator->ValidateForm()) { $con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error()); mysql_select_db("beatthis_beatthis") or die(mysql_error()); $FirstName=mysql_real_escape_string($_POST['FirstName']); //This value has to be the same as in the HTML form file $LastName=mysql_real_escape_string($_POST['LastName']); //This value has to be the same as in the HTML form file $UserName=mysql_real_escape_string($_POST['UserName']); //This value has to be the same as in the HTML form file $Password= md5($_POST['Password']); //This value has to be the same as in the HTML form file $Password2= md5($_POST['Password2']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $Zip=mysql_real_escape_string($_POST['Zip']); //This value has to be the same as in the HTML form file $Birthday=mysql_real_escape_string($_POST['Birthday']); //This value has to be the same as in the HTML form file $Security=mysql_real_escape_string($_POST['Security']); //This value has to be the same as in the HTML form file $Security2=mysql_real_escape_string($_POST['Security2']); //This value has to be the same as in the HTML form file $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } mysql_close($con); $show_form=false; } else { echo "<h3 class='ErrorTitle'>Validation Errors:</h3>"; $error_hash = $validator->GetErrors(); foreach($error_hash as $inpname => $inp_err) { echo "<p class='errors'>$inpname : $inp_err</p>\n"; } } } if(true == $show_form) { ?> I have a strange problem. When a guest visits my contact-user.php page, they get a message telling them the must login before viewing the page. After the guest logs in, they view the same page and it tells them they have to login again (keeps on looping). But if they manually refresh that page with the "you must be logged in" message, it recognizes the login and lets them in. How can I get this page to immediately recognize that the user is logged in and not require them to refresh the page manually? Here is my code for contact-user.php <?php session_start(); header("Cache-Control: private, max-age=10800, pre-check=10800"); header("Pragma: private"); header("Expires: " . date(DATE_RFC822,strtotime("+2 day"))); include("connection.php"); mysql_select_db("database"); if (isset($_SESSION['username'])) { ******** MY HTML PAGE CONTENT ******** } else { echo "<meta http-equiv='REFRESH' content='2;url=http://www.mysite.com/login.php'> <center><font color='#EE0000'><p>You must be logged in before negotiating. You will now be redirect to the login page.</p></font></center>"; } ?> Here is my code for login.php script: <?php include("connection.php"); mysql_select_db("database"); session_start(); if(isset($_POST['login'])){ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $tUnixTime = time(); $sGMTMySqlString = gmdate("Y-m-d H:i:s", $tUnixTime); if (!$username || !$password) { print "Please fill out all fields."; exit; } $logres = mysql_num_rows(mysql_query("SELECT * FROM members WHERE username = '$username' and password = '$password'")); if ($logres <= 0) { print "Login failed. If you have not already, please signup. Otherwise, check your spelling and login again."; exit; } else { $_SESSION['username'] = $username; if (isset($_SESSION)) { echo'You are now logging in'; mysql_query("UPDATE members SET activity = '$sGMTMySqlString' WHERE username = '$username'"); } else { echo "You are not logged in!"; } echo'<html><head><meta http-equiv="REFRESH" content="1;url=http://www.mysite.com/members/' . $_SESSION['username'] . '/"></head><body></body></html>'; exit; } } ?> Can you help me integrate this code :
<form method="post" action="submit.php"> <input type="checkbox" class="required" /> Click to check <br /> <input disabled="disabled" type='submit' id="submitBtn" value="Submit"> </form>In to this Contact Form code, please? <form action="../page.php?page=1" method="post" name="contact_us" onSubmit="return capCheck(this);"> <table cellpadding="5" width="100%"> <tr> <td width="10" class="required_field">*</td> <td width="80">Your Name</td> <td><input type="text" name="name" maxlength="40" style="width:400px;/></td> </tr> <tr> <td class="required_field">*</td> <td>Email Address</td> <td><input type="text" name="email" maxlength="40" style="width:400px;/></td> </tr> <tr> <td></td> <td>Comments:</td> <td><textarea name="comments" style="width: 400px; height: 250px;"></textarea></td> </tr> </table> </form Hello Everyone I am new to php and indeed Web Development. After testing and Playing a bit, I can get the following code to work as two files, the form calling the *.php file to insert into the database, however, I am trying to create one html/php file that displays the form and then executes the php code to insert into the database once user clickes the button. Please can you assist me with the code? I have something horribly wrong and I cannot find it. Code: [Select] <?php> <html> <head> <title>Personal Details</title> </head> <body> <form method="post" action="contactdetails.html"><font face="Arial"> Call Sign:<br> <input name="callsign" size="5" type="text"><br> Surame:<br> <input name="surname" size="30" type="text"><br> First Name:<br> <input name="firstnames" size="30" type="text"><br> Known as:<br> <input name="knownas" size="30" type="text"><br> RSA ID No.:<br> <input name="rsaid" size="13" type="text"><br> Birth Date:<br> <input name="birthdate" size="12" type="text"><br> <input name="Insert" value="Next" type="submit"></form> </font><br> </body> </html> //php to insert data into table $callsign = $_POST['callsign']; $surname = $_POST['surname']; $firstnames = $_POST['firstnames']; $knownas = $_POST['knownas']; $rsaid = $_POST['rsaid']; $birthdate = $_POST['birthdate']; mysql_connect ("localhost", "jredpixm_testuse", "PHPDevelopment") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("jredpixm_test"); $query="INSERT INTO personal_details (callsign, surname, firstnames, knownas, rsaid, birthdate)Values ('$callsign', '$surname', '$firstnames', '$knownas', '$rsaid', '$birthdate')"; mysql_query($query) or die ('Error updating Database'); echo "<p>Thanks, your information has been added to the database.</p>"; ?> Regards Allen To access MySql tables from PHP, I use the PHP code and the function below. If I make these changes, would this code work for SQL Server 2008? mysql_fetch_array to mssql_fetch_array mysql_connect to mssql_connect mysql_select_db to mssql_select_db mysql_query to mssql_query PHP code -------------------------------------------------------------------------------- $sql = "SELECT mast_id FROM district_mast WHERE mast_district = '".$dist_num."'"; $result = func_table_access($sql); $rows = mysql_fetch_array($result); Function -------------------------------------------------------------------------------- FUNCTION func_table_access($sql) { $db = "aplustutoru"; $host = "localhost"; $user = "root"; $pass = ""; IF (!($conn=mysql_connect($host, $user, $pass))) { PRINTF("error connecting to DB by user = $user and pwd=$pass"); EXIT; } $db3 = MYSQL_SELECT_DB($db,$conn) or die("Unable to connect to local database"); IF ($sql <> "justopendb") { $result = MYSQL_QUERY($sql) OR DIE ("Can not run query because ". MYSQL_ERROR()); RETURN $result; } } Hi, So i have HTML table which i'm attempting to turn into executable SQL code which i can then insert into a SQL database table. I'm wondering if anyone has any good ideas for the best way to get this done? I need to extract the data from each of the <tr bgcolor="#EEEEEE">, scrape the text within each <td></td> and then format it in sql. so far i have removed the html not required and created an array by exploding "<tr bgcolor="#EEEEEE">", however, its creating an empty element in the first array index [0], to fix this i have tried $players = array_shift($players); however it removed everything from the array. next i was thinking i would need to remove all html within each array element and add a comma to the end, then i would need to compress it all back together again? would this be the best way to do this? source html <html> <head> <title><br/></title> <style type ="text/css"> body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } th { padding: 5px; text-align: left; } td { padding: 2px; border-style: solid; border-width: 1px } </style> </head> <body> <center><B><br/> </center></B> <p> <table bordercolor="#000000" width="90%" align="center"> <tr bgcolor="#EEEEEE"> <th>UID</th> <th>Name</th> <th>Nat</th> <th>Position</th> <th>Best Pos</th> <th>Age</th> <th>DoB</th> <th>Height</th> <th>Weight</th> <th>Expires</th> <th>Wage</th> <th>Value</th> <th>Aer</th> <th>Cmd</th> <th>Com</th> <th>Ecc</th> <th>Han</th> <th>Kic</th> <th>1v1</th> <th>Pun</th> <th>Ref</th> <th>TRO</th> <th>Thr</th> <th>Cor</th> <th>Cro</th> <th>Dri</th> <th>Fin</th> <th>Fir</th> <th>Fre</th> <th>Hea</th> <th>Lon</th> <th>L Th</th> <th>Mar</th> <th>Pas</th> <th>Pen</th> <th>Tck</th> <th>Tec</th> <th>Agg</th> <th>Ant</th> <th>Bra</th> <th>Cmp</th> <th>Cnt</th> <th>Dec</th> <th>Det</th> <th>Fla</th> <th>Ldr</th> <th>OtB</th> <th>Pos</th> <th>Tea</th> <th>Vis</th> <th>Wor</th> <th>Acc</th> <th>Agi</th> <th>Bal</th> <th>Jum</th> <th>Nat</th> <th>Pac</th> <th>Sta</th> <th>Str</th> </tr> <tr bgcolor="#EEEEEE"> <td>859596</td> <td>Tim Krul</td> <td>NED</td> <td>GK</td> <td>GK</td> <td>31</td> <td>3/4/1988 (31 years old)</td> <td>194 cm</td> <td>83 kg</td> <td>30/6/2022</td> <td>£25,000 p/w</td> <td>£12.75M</td> <td>15</td> <td>13</td> <td>14</td> <td>8</td> <td>13</td> <td>13</td> <td>15</td> <td>12</td> <td>16</td> <td>15</td> <td>12</td> <td>1</td> <td>2</td> <td>1</td> <td>3</td> <td>8</td> <td>4</td> <td>5</td> <td>3</td> <td>2</td> <td>2</td> <td>9</td> <td>4</td> <td>3</td> <td>8</td> <td>11</td> <td>12</td> <td>14</td> <td>13</td> <td>13</td> <td>12</td> <td>14</td> <td>2</td> <td>14</td> <td>2</td> <td>15</td> <td>10</td> <td>5</td> <td>13</td> <td>11</td> <td>13</td> <td>14</td> <td>17</td> <td>13</td> <td>8</td> <td>14</td> <td>10</td> </tr> <tr bgcolor="#EEEEEE"> <td>5204730</td> <td>Michael McGovern</td> <td>NIR</td> <td>GK</td> <td>GK</td> <td>34</td> <td>12/7/1984 (34 years old)</td> <td>188 cm</td> <td>86 kg</td> <td>30/6/2021</td> <td>£8,000 p/w</td> <td>£875K</td> <td>12</td> <td>11</td> <td>10</td> <td>2</td> <td>12</td> <td>12</td> <td>12</td> <td>11</td> <td>13</td> <td>8</td> <td>10</td> <td>5</td> <td>2</td> <td>1</td> <td>3</td> <td>9</td> <td>7</td> <td>6</td> <td>3</td> <td>3</td> <td>2</td> <td>7</td> <td>1</td> <td>2</td> <td>5</td> <td>7</td> <td>12</td> <td>14</td> <td>13</td> <td>13</td> <td>11</td> <td>17</td> <td>1</td> <td>12</td> <td>7</td> <td>12</td> <td>15</td> <td>10</td> <td>15</td> <td>10</td> <td>13</td> <td>12</td> <td>12</td> <td>12</td> <td>8</td> <td>15</td> <td>14</td> </tr> </table> <p> <p align="center"> </body> </html>
code i've created so far: <?php // Defining the basic scraping function function scrape_between($data, $start, $end) { $data = stristr($data, $start); // Stripping all data from before $start $data = substr($data, strlen($start)); // Stripping $start $stop = stripos($data, $end); // Getting the position of the $end of the data to scrape $data = substr($data, 0, $stop); // Stripping all data from after and including the $end of the data to scrape return $data; // Returning the scraped data from the function } $myfile = fopen("source.html", "r") or die("Unable to open file!"); $page = fread($myfile,filesize("source.html")); $page = scrape_between($page, '</tr>', '</table>'); $players = explode('<tr bgcolor="#EEEEEE">', $page); echo '<pre>'; print_r($players); echo '</pre>'; fclose($myfile); ?> Edited December 14, 2019 by seany1234 Hello, I am trying to get this website working but i get an error saying invalid data source name. I am fairly certain the error is from one of these 2 files. db_connection.php <?php function OpenCon() { $dbhost = "localhost"; $dbuser = "root"; $dbpass = "123"; $db = "db"; $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error); return $conn; } function CloseCon($conn) { $conn -> close(); } ?> and the other file index.php /* // <? /* php require('includes/db_connection.php'); */ ?> */ <? php include 'db_connection.php'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Blog</title> <link rel="stylesheet" href="style/normalize.css"> <link rel="stylesheet" href="style/main.css"> </head> <body> <div id="wrapper"> <h1>Blog</h1> <hr /> <?php $db = null; global $stmt; try { // $stmt = db->query('SELECT postID, postTitle, postDesc, postDate FROM blog_posts ORDER BY postID DESC'); $conn = new PDO('SELECT postID, postTitle, postDesc, postDate FROM blog_posts ORDER BY postID DESC'); while($row = $stmt->fetch()){ echo '<div>'; echo '<h1><a href="viewpost.php?id='.$row['postID'].'">'.$row['postTitle'].'</a></h1>'; echo '<p>Posted on '.date('jS M Y H:i:s', strtotime($row['postDate'])).'</p>'; echo '<p>'.$row['postDesc'].'</p>'; echo '<p><a href="viewpost.php?id='.$row['postID'].'">Read More</a></p>'; echo '</div>'; } } catch(PDOException $e) { echo $e->getMessage(); } ?> </div> </body> </html> Please help me with this error, I would really like this to work. Thank you very much. How can I run php code that is stored in a database? I have my pages created by grabbing the contents of a pageBody mySQL table cell, but some pages require further php to be able to display correctly. For example, I have a players page, which will list all players, and some information about them. The players and information is all saved in a players table in my database (separate to the pages table where pageBody is stored). I use simple php to grab all the players and format all of their information so it can be displayed on the page. This is the flow of information that I would like: User clicks on players page browser loads content page (this is a template page), and grabs the pageid from $_GET browser then reads pages table in database to get the pageBody associated with the pageid The pageBody will contain more php, which will run the players script to retrieve the list, and display Doing it the above way will make it much easier to extend the website to include more types of pages that has to run additional php scripts. The only way I can think of this working is by doing this: user clicks on players page browser loads content page, grabs pageid from $_GET browser checks the pageid for the one associated with players (hard coded into the php script) browser then loads the players.php script instead of going to the database This above way means that I will need to edit the index.php page everytime I add a new list type (example, coaches, volunteers etc). Anyone have any suggestions? I know my question is long, but I was finding it hard to explain it in an easy to understand way, but I'm still not sure if I have :S. Cheers Denno i have this code... and i want to make it more dynamic.... Code: [Select] <?php $content = $content[1].$content[2].$content[3].$content[4].$content[5].$content[6].$content[7].$content[8].$content[9].$content[10].$content[11].$content[12] .$content[13].$content[14].$content[15].$content[16] .$content[17].$content[18].$content[19].$content[20].$content[21].$content[22].$content[23].$content[24]; $sql = mysql_query ("insert into database (content) values ('$content')") or die(mysql_error()); ?> for example... instead content[1]. content[2]. content[3] ...etc... i want something like this....... $content = $content[from 1 to 24]; or $content = $content[from 1 to 777]; any solutions? Hello, I am trying to get a news script to work, but I can't get it to insert anything into the database. I cannot figure it out for the life of me. Code: (newsupdate.php) [Select] <form name="shout" action="post.php" method="post"> <p><b>Name:</b><br/><input type="text" name="name" size="15"/></p> <p><b>Message</b>:<br/> <textarea wrap="physical" name="message" rows="3" cols="25">News goes here! </textarea></p> <p><input type="submit" value="Shout now!"/> <input type="reset" value="Clear"/></p> </form> Code: (post.php) [Select] <? $name = $_POST["name"]; $message = $_POST["message"]; include("dbconnect.php"); $date = date("M j y"); $menu = MYSQL_QUERY("INSERT INTO adminnews (id,name,date,message)". "VALUES ('NULL', '$name', '$date', '$message')"); echo("Shout-out added! You will be redirected to the main page shortly. If you are not, click <a href='index.php'>here</a>."); ?> dbconnect.php is just the configuration for connecting to the database, and I have checked that all ready. A log-in script uses it just fine. 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/ I'm trying to use php code that is stored in the sql database, but It doesn't seem to be executing the code. when I see the page source, its there but the server is not executing the command how do I accomplish this. Here is a simple code snippet to show what I am trying to do. $result = mysql_query("select * from data"); $row = mysql_fetch_array($result); echo $row['code']; In the code field in data table this is whats there. <?php echo "testing."; ?> |