PHP - Two Different Mysql (using Pdo) Problems. D:
It seems the code below doesn't work properly. Even if there isn't a record that has the same username or name, it will say there is on in the database, which prevents them from making an account. Why so?
Code: [Select] $check1 = $db->prepare("SELECT username,name FROM servers WHERE username = ? OR name = ? LIMIT 1"); $check1->execute(array($username, $password)); if($check1->rowCount() > 0) { echo "Sorry, there is already an account with this username and/or server name!"; } And here is my other problem, the harder one. It seems my execute wont work properly. The data will NEVER insert in the database, and it just says: "You've successfully created your account!" Here is my code: Code: [Select] $insertQuery = $db->prepare("INSERT INTO servers (id, username, password, name, type, description, ip, votes, beta) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); $insertQuery->execute(array(null, $username, $password, $name, $server_type, $description, $ip, 0, 1)); if($insertQuery->errorInfo() > 0) { echo "Sorry, there was the following error:"; print_r($insertQuery->errorInfo()); } else { echo "Server has been succesfully created!"; } [MAY LOOK SLOPPY. CODED IN NOTEPAD++, BEST VIEWED WITH IT.] Full, whole page code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = $_POST['username']; $password = $_POST['password']; $name = $_POST['name']; $server_type = $_POST['type']; $description = $_POST['description']; //This check isn't 100% secure. It allows for registration with no server details if(!$username || !$password) { //Ideally HTML and PHP should be as separate as possible. Perhaps consider having a different PHP script that runs the registration echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = $db->prepare("SELECT username,name FROM servers WHERE username = ? OR name = ? LIMIT 1"); $check1->execute(array($username, $name)); if($check1->rowCount() > 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; $insertQuery = $db->prepare("INSERT INTO servers (id, username, password, name, type, description, ip, votes, beta) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); $insertQuery->execute(array(null, $username, $password, $name, $server_type, $description, $ip, 0, 1)); if($insertQuery->errorInfo() > 0) { echo "Sorry, there was the following error:"; print_r($insertQuery->errorInfo()); } else { echo "Server has been succesfully created!"; } } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> Similar TutorialsHello Im just new to coding into php and im getting this error? i cant seems to see database into my php ? what wrong need help CREATE TABLE IF NOT EXISTS `payment_details` ( `id` int(11) NOT NULL AUTO_INCREMENT, `idnumber` varchar(30) NOT NULL, `date` varchar(30) NOT NULL, `amount` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;Here my php code i cant seems to understand what wrong i dont get any error from mysql or from my php please i dont know what wrong <label for="filter">Filter</label> <input type="text" name="filter" value="" id="filter" /> <table cellpadding="1" cellspacing="1" id="resultTable"> <thead> <tr> <th style="border-left: 1px solid #C1DAD7"> Date </th> <th>Amount</th> </tr> </thead> <tbody> <?php include('../connect.php'); $id=$_SESSION['SESS_MEMBER_ID']; $result = mysql_query("SELECT * FROM student WHERE id='$id'"); while($row = mysql_fetch_array($result)) { echo '<tr class="record">'; echo '<td style="border-left: 1px solid #C1DAD7"><div align="left">'.$row['date'].'</div></td>'; echo '<td><div align="left">'.$row['amount'].'</div></td>'; echo '</tr>'; } ?> </tbody> </table> Hi, I'm not sure if this should be posted in the PHP forum or the mySQL forum as it's a bit of both to be honest. Basically I am generating what I think is a fairly complex SQL statement (although I'm by no means a mySQL master so it might not be that complex) through the use of PHP. The PHP that is generating the statement looks like so: Code: [Select] // Availability $availability = 'SELECT * FROM indivdual_teachers WHERE 1=1'; foreach($_GET as $key=>$value){ if(strpos($key, 'availability_') == 0 and $value=='Available'){ $day = (int)str_replace('availability_', '', $key); $availability .= ' AND teacher_id IN (SELECT candidate_id FROM availability_calendar WHERE (DAY = '.$day.' AND MONTH = '.$month.' AND YEAR = '.$year.' AND availability = "Available")) '; } } // Staff Yype if($_GET['staff_required'] == 'Non Teaching Staff') { $search_str[] = "role !=\"\""; } elseif($_GET['staff_required'] == 'Teaching Staff') { $search_str[] = "role=\"\""; } else { } // Lives in... if(!empty($_GET['location'])) { $location = mysql_real_escape_string($_GET['location']); $search_str[] = "address2 LIKE '%$location%' OR city LIKE '%$location%'"; } elseif(!empty($_GET['region'])) { $region = mysql_real_escape_string($_GET['region']); $search_str[] = "region = '$region'"; } else { // They don't want to search on lives in... so do nothing } // Registered with... if(!empty($_GET['LA'])) { $local_authority = mysql_real_escape_string($_GET['LA']); $search_str[] = "id IN (SELECT teacher_id FROM teacher_LEAs WHERE LEA = '$local_authority')"; } elseif (!empty($_GET['Agency'])) { $agency = mysql_real_escape_string($_GET['Agency']); $search_str[] = "id IN (SELECT teacher_id FROM teacher_agencies WHERE agency = '$agency')"; } else { // They don't want to search on registered with... so do nothing } $total = $_GET["keywords"]; $keyarr = explode(',',$total); // In order to process this array values here is the code foreach($keyarr as $key=>$value) { // becareful to check the value for empty line $value = trim($value); if (!empty($value)) { $search_str[] = "id IN (SELECT teacher_id FROM test_cv_tags WHERE skills = '$value')"; } } // Subject/Specalism if(!empty($_GET['subject'])) { $subject = mysql_real_escape_string($_GET['subject']); $search_str[] = "id IN (SELECT teacher_id FROM teacher_specialisms WHERE specalism = '$subject')"; } if(!empty($_GET['additional_subject'])) { $additional_subject = mysql_real_escape_string($_GET['additional_subject']); $search_str[] = "id IN (SELECT teacher_id FROM teacher_additional_subjects WHERE subject = '$additional_subject')"; } // Ranking if(!empty($_GET['overall'])) { $overall = mysql_real_escape_string($_GET['overall']); $search_str[] = "avg_overall >= $overall "; } else { if(!empty($_GET['behaviour'])) { $behaviour = mysql_real_escape_string($_GET['behaviour']); $search_str[] = "avg_behaviour_management >= $behaviour "; } if(!empty($_GET['ability'])) { $ability = mysql_real_escape_string($_GET['ability']); $search_str[] = "avg_teaching_ability >= $ability "; } if(!empty($_GET['planning'])) { $planning = mysql_real_escape_string($_GET['planning']); $search_str[] = "avg_preperation_planning >= $planning "; } if(!empty($_GET['professional'])) { $professionalism = mysql_real_escape_string($_GET['professional']); $search_str[] = "avg_professionalism >= $professionalism "; } } This is all brought together like so; Code: [Select] if(!empty($search_str)){ $sql = "$availability AND ".join(" AND ", $search_str)." AND public_profile = 'Yes' ORDER BY avg_overall DESC"; echo $sql; } else { $sql = "$availability AND public_profile = 'Yes' ORDER BY avg_overall DESC"; echo $sql; } When I complete my form and echo the completed query it looks something like this; Code: [Select] SELECT * FROM indivdual_teachers WHERE 1=1 AND teacher_id IN (SELECT candidate_id FROM availability_calendar WHERE (DAY = 19 AND MONTH = 04 AND YEAR = 2012 AND availability = "Available")) AND role="" AND region = 'North East' AND id IN (SELECT teacher_id FROM teacher_agencies WHERE agency = 'Education World') AND id IN (SELECT teacher_id FROM test_cv_tags WHERE skills = 'french') [color=red]AND[/color] id IN (SELECT teacher_id FROM test_cv_tags WHERE skills = 'golf') [color=red]AND[/color] id IN (SELECT teacher_id FROM test_cv_tags WHERE skills = 'spanish') AND id IN (SELECT teacher_id FROM teacher_specialisms WHERE specalism = 'Accounting') AND id IN (SELECT teacher_id FROM teacher_additional_subjects WHERE subject = 'Art') AND avg_behaviour_management >= 5 AND avg_teaching_ability >= 5 AND avg_preperation_planning >= 5 AND avg_professionalism >= 5 AND public_profile = 'Yes' ORDER BY avg_overall DESC The problem I have is that the part I have highlighted in red should actually be an OR statement in order for the query to work as intended. I realise why it is an AND statement, simply because it is using this (highlighted in green). I can't simply change the green AND to an OR because that would cause the rest of my query to misfunction; Code: [Select] $sql = "$availability AND ".join(" [color=green]AND[/color] ", $search_str)." AND public_profile = 'Yes' ORDER BY avg_overall DESC"; However I have been unable to resolve the issue. Would someone be kind enough to offer me some advice/guidance here? Many thanks. Hi all, I have a query that runs just fine from the command line in MySQL, but when I try to run the exact same query using PHP to query the same database I get an error. The query is: SELECT Street, City, ZipCode, providers.bWebpage, OpHours.Open, OpHours.Close, lat, lng, ( 3959 * acos( cos( radians('41.757787') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('-88.321416') ) + sin( radians('41.757787') ) * sin( radians( lat ) ) ) ) AS distance FROM Providers, OpHours WHERE providers.bName = OpHours.bName AND OpHours.Close > '17:00:00' HAVING distance < '10' ORDER BY distance LIMIT 0 , 30 Like I stated above, when I run this query from the MySQL command line it returns 12 rows, which is what it should. But when I try executing the same query via PHP I get this error message: Invalid query: 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 ''17:00:00' HAVING distance < '10' ORDER BY distance LIMIT 0 , 30' at line 1 The PHP code is thus: $connection=mysql_connect ($server, $username, $password); if (!$connection) { echo 'Connection error'; die("Not connected : " . mysql_error()); } $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { echo 'Database selection error' . '\n'; die ("Can\'t use db : " . mysql_error()); } $query = sprintf("SELECT Street, City, ZipCode, providers.bWebpage, OpHours.Open, OpHours.Close, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM Providers, OpHours WHERE providers.bName = OpHours.bName %s HAVING distance < '%s' ORDER BY distance LIMIT 0 , 30", mysql_real_escape_string($center_lat), mysql_real_escape_string($center_lng), mysql_real_escape_string($center_lat), mysql_real_escape_string($hours), mysql_real_escape_string($radius)); $result = mysql_query($query); if (!$result) { die("Invalid query: " . mysql_error()); } I've also checked the MySQL logs and they don't report any errors. I'm running this on a Mac using Snow Leopard. MySQL version is 5.1.37 and the PHP version is 5.2.11. If it makes any difference both of these are from MAMP version 1.8.4. I have a db.php and inside it I filled out all the info needed:
<?php define('DB_HOST', 'example.com'); define('DB_NAME', 'database_name'); define('DB_USERNAME', 'user_name'); define('DB_PASSWORD', '*******'); $odb = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD); ?>My problem is with the DB_HOST, is that my direct URL to the site? for example, google.com or is it like an IP? Hi, I only just worked out (a little slow) that mysql is not redundant and crap =\ Apparently I should be using mysqli.
However I need help I tried following a tutorial online but it failed. This is my login script and it doesn't work
<?php require_once '../inc/conn.php'; session_start(); if ($_POST['username']) { $username = $_POST['username']; $password = $_POST['password']; $requestLogin = mysqli_query( $retreat, "SELECT * FROM login WHERE username='$username' AND password='$password'"); while($row = mysqli_fetch_array($requestLogin)){ $userID = $row['userID']; $_SESSION['userID'] = $userID; $username = $row['username']; $_SESSION['username'] = $username; header('location: /administrator/'); } } ?>And this is the conn.php ( something hidden for safety, however it does connect correctly. <?php $hostname = 'localhost'; $username = ''; $password = ''; $database = ''; $retreat = mysqli_connect($hostname, $username, $password, $database) or die('Connecting to MySQL failed'); ?>The actual <form> is also correct as it's just normal html and worked before I tried converting to mysqli. After this login I have a script which is this that goes in the header of all admin pages. <?php require_once '../inc/conn.php'; session_start(); if (isset($_SESSION['userID'])) { $username = $_SESSION['username']; $getUser = mysqli_query( $retreat, "SELECT user_rights FROM login WHERE username='$username'"); while($row = mysqli_fetch_array($getUser)){ $user_rights = $row['user_rights']; } } else { include_once 'login.php'; exit(); } ?>I am no coding professional by any means but I get the job done. However this mysqli is sort of new ground. Hello PHPFreaks. I have one problem, that I've tried to fix for a day or two now. I need a function, that picks out a random row in a table, and returns one thing. I tried with, getting the max rows in the table, make a random number in the interval 0 to max rows, then select the random number, but it failed. I hope someone can help me out with this one? -Niixie This is my code, and I know it's pretty messy, because i fooled around with it for a day or two, so it's hard to find head or tail in it. Code: [Select] $query0 = sprintf("SELECT * FROM registertest"); $result = mysql_query($query0); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $nums = mysql_num_rows($result); $rand_nums = rand(0,$nums); $query1 = sprintf("SELECT question FROM registertest WHERE id='%i'", $rand_nums); $result1 = mysql_query($query1) or die(mysql_error()); if (!$result1) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $row = mysql_fetch_row($result1); mysql_free_result($result); mysql_free_result($result1); $_SESSION['registerquestion'] = $row; if(strlen($_SESSION['registerquestion'])!=0){return 1;}else{return 0;} Hi all, I use a MySQL insert query of the following form: Code: [Select] <?php $insert1= mysql_query ("INSERT INTO tablename (H1, H2, H3) VALUES '$V1','$V2','$V3')"); ?> However, I encounter problems when $V1, $V2 or $V3 contain certain symbols, such as quotes ("'). What is the best way to avoid this? Thanks! I wasn't too sure if this should be in the MySQL help section so please (admin/mods) feel free to move this if you feel it's necessary. I'm attempting to connect to a URL through cURL that is being grabbed from a mysql table. The url within the table is: http://es-us.noticias.yahoo.com/ue-podr%C3%ADa-revisar-veda-crudo-ir%C3%A1n-en-pr%C3%B3ximos-124018543.html" When I plug this into firefox it works. When using it through cURL directly (see below) it works. Code: [Select] $url = "http://es-us.noticias.yahoo.com/ue-podr%C3%ADa-revisar-veda-crudo-ir%C3%A1n-en-pr%C3%B3ximos-124018543.html"; // create a new curl resource $ch = curl_init(); // set URL to download curl_setopt($ch, CURLOPT_URL, $url); // user agent: curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); // remove header? 0 = yes, 1 = no curl_setopt($ch, CURLOPT_HEADER, 0); // should curl return or print the data? true = return, false = print curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 60); // download the given URL, and return output $page = curl_exec($ch); However, when I grab the url from a table within mysql it does not work and no curl error (or any error for that matter) is returned. Code: [Select] $get_url_links = "SELECT * FROM tabe"; $url_link = mysql_query($get_url_links); $row = mysql_fetch_array($url_link); $url = $row['link']."<br />"; I'm suspecting this is some kind of encoding issue. I've tried $url = mysql_real_escape_string($url); --- before entering it into the table $url = mysql_real_escape_string($url); --- before calling cURL mysql_query("set names 'utf8'"); --- before inserting the url into the table I've also set the column table type to 'text'. Suggestions appreciated. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=323935.0 I have a post.php that is suposted to run a mysql query, and it used to, but it won't anymore and I don't have the old file. Can someone just look see if there is something i'm missing? <?php //header("Location: ./?p=UCP"); setcookie("Errors", 0, time()-3600); // Connects to your Database mysql_connect("SERVER", "USER", "PASS") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); if (isset($_POST['remove'])) { $id=$_POST['ID']; if($_POST['initals'] == "NLW") { if (is_numeric ($id)) { mysql_query("DELETE FROM `users` WHERE `users`.`ID` = $id LIMIT 1"); $error="<span style="; $error .="color:green"; $error .=">"; $error .= "User Removed."; $error .="</span>"; setcookie(Errors, $error, time()+20); } else { $error="<span style="; $error .="color:red"; $error .=">"; $error .= "Please enter a valid ID"; $error .="</span>"; setcookie(Errors, $error, time()+20); header('Location ./?p=UPC'); } } else { $error="<span style="; $error .="color:red"; $error .=">"; $error .="Initials are not correct"; $error .="<span/>"; setcookie(Errors, $error, time()+20); header('Location ./?p=UPC'); } } elseif (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { $error="<span style="; $error .="color:red"; $error .=">"; $error .= "You did not complete all of the required fields"; $error .="</span>"; setcookie(Errors, $error, time()+20); header('Location ./?p=UPC'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { $error="<span style="; $error .="color:red"; $error .=">"; $error .= "Sorry, the username is already in use."; $error .="</span>"; setcookie(Errors, $error, time()+20); header('Location ./?p=UPC'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { $error="<span style="; $error .="color:red"; $error .=">"; $error .= 'Your passwords did not match.'; $error .="</span>"; setcookie(Errors, $error, time()+20); echo $error; } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); $_POST['pass2'] = $_POST['pass2']; } // now we insert it into the database $insert = "INSERT INTO users (username, password, Human-Readable) VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['pass2']."')"; mysql_query("INSERT INTO users (username, password, Human-Readable) VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['pass2']."')"); $error="<span style="; $error .="color:green"; $error .=">"; $error .= "<h1>User Registered</h1> <p><h2>Thank you, the user has been registered - he/she may now login</a>.</h2></p>"; $error .="</span>"; setcookie(Errors, $error, time()+20); header('Location: ./?p=UCP'); } else { header('Location: ./?p=UCP'); echo $error; } ?> The remove function works but its the submit. Thanks in advanced Hi guys I am working on adding a third party php members register and login into a clients web site but every time I try the regidter page is shows me this error message. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'username'@'localhost' (using password: YES) in /home/cpassoc2/public_html/register-exec.php on line 15 Failed to connect to server: Access denied for user 'username'@'localhost' (using password: YES) This is what i have in the config.php page. <?php define('DB_HOST', 'localhost'); define('DB_USER', 'cpassoc2-memark'); define('DB_PASSWORD', '?????????'); password replaced define('DB_DATABASE', 'cpassoc2-me'); ?> I have set up the my SQL within the control panel of the site, So do i need to do any thing else???, what am i missing???. Mark..... Hello, First post here! I am using a script to store small files into a database. I know it is not highly recommended but this is the only solution I can find in this case. All seems fine when inserting but when retrieving all documents are corrupt. I am working with PHP 5 on Windows server. Part script after upload: (the document is uploaded to the server first and this is working fine) Code: [Select] if (!empty($_FILES)) { $folder = "kenya/docs_temp/";//including last / $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = dirname(__FILE__); $targetPath = substr($targetPath,0,strrpos($targetPath, "uploadify")). $folder; $targetFile = str_replace('\\','/',$targetPath) . $_FILES['Filedata']['name']; $fileName = $_FILES['Filedata']['name']; $tmpName = $_FILES['Filedata']['tmp_name']; $fileSize = $_FILES['Filedata']['size']; $fileType = $_FILES['Filedata']['type']; $conn=odbc_connect('xxx','xxx','xxxx'); $content = file_get_contents($tmpName,true); $content = addslashes($content); if(!get_magic_quotes_gpc()){ $fileName = mysql_real_escape_string($fileName); } $file_info = pathinfo($_FILES['Filedata']['name']); $addDoc = "INSERT INTO tblfiles (file_name,file_type,file_size,file_content,file_extension) VALUES ('".addslashes($fileName)."','".$fileType."','".$fileSize."','".$content."','".$file_info['extension']."')"; odbc_exec($conn,$addDoc); } The the script to retrieve and output to the browser: Code: [Select] $conn=odbc_connect('xxxx','xxx','xxxx'); //get the document $getF = "SELECT * FROM tblfiles WHERE userId = '".$_GET['userId']."' AND fileId = '".$_GET['fileId']."'"; $rsF = odbc_exec($conn,$getF); $size = floor(odbc_result($rsF,'file_size')); $type = odbc_result($rsF,'file_type'); $name = odbc_result($rsF,'file_name'); $content = odbc_result($rsF,'file_content'); ob_end_clean(); header("Content-length: ".$size.""); header("Content-type: ".$type.""); header('Content-Disposition: attachment; filename="'.$name.'"'); echo $content; And finally here is the structure for the table: Code: [Select] CREATE TABLE `tblfiles` ( `fileId` int(11) NOT NULL auto_increment, `userId` int(11) NOT NULL, `file_name` varchar(100) NOT NULL, `file_type` varchar(100) default NULL, `file_size` int(11) default NULL, `file_content` mediumblob, `file_extension` varchar(50) NOT NULL, PRIMARY KEY (`fileId`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; many thanks for any assistance. class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); It display a blank page like attachment result1.jpg, but if I move the $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); from function debug() and join it with function execute() like this: public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } it return me Linuxformat content ( expected result ) like result2.jpg below is the working code : class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); Why I couldn't split "CURLOPT_STDERR, CURLOPT_RETURNTRANSFER" with "curl_exec" create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! Hi, I hope someone can help me. I am trying to generate a script for our Intranet that tells me which birthdays = today. My field in my table = d/m/y, eg 09/05/2011 (9 May 2011). How do I get the script to just look at the day & month, not the year? My script looks like this: Code: [Select] <?php echo date("d/m/Y") . "<br />"; $myDate = date('d/m/Y'); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); $sql = "SELECT * FROM detail WHERE dob='$mydate'"; $result=mysql_query($sql); echo mysql_num_rows($result); ?> |