php

php session_start() error

Hi, i've used a sample found on online and applied it to my code: <?php session_start(); if (isset($_REQUEST["email"])) { $_SESSION["name"] = true; $host = $_SERVER["HTTP_HOST"]; $path = dirname($_SERVER["PHP_SELF"]); $sid = session_name() . "=" . session_id(); header("Location: index.php?$sid"); exit; } ?> <!DOC...

How to order by a known id value in mysql

Hi, is it possible to order a select from mysql by using a known id first. Example: $sql = "SELECT id, name, date FROM TABLE ORDER BY "id(10)", id DESC Not sure if the above makes sense but what I would like to do is first start ordering by the known id which is 10 which I placed in quotes "id(10)". I know that cannot work as is in t...

[PHP] converting mysql data into array?

i have an ajax script that check if the user name is available or not, but it keeps taking the newest user name and the rest are out $result = mysql_query("Select username from customer"); while ($row = mysql_fetch_array($result)){ $existing_users=array(''.$row['username'].','); } i know i am doing something worng ...

How can I speed up a 1800-line PHP include? It's slowing my pageload down to 10sec/view

I designed my code to put all important functions in a single PHP file that's now 1800 lines long. I call it in other PHP files--AJAX processors, for example--with a simple "require_once("codeBank.php")". I'm discovering that it takes about 10 seconds to load up all those functions, even though I have nothing more than a few global arr...

IP Blocking on error logs PHP

Is there a way to block error logging from a specific set of IP's ? Basically macafee carry out a range of testing on the server nightly and we don't want to record these in our error logs. Is there a good way to avoid this from happening ? Hope you can advice! ...

How to UNION ALL two SELECT statements?

I have 2 tables, one looks like this: TABLE ONE id | Last Name | First Name | Username | Password | Secret Question and another that looks like this: TABLE TWO id | Hobby | Country | I want to combine a Select statement that grabs data from both tables and output the results. The following code: $select = mysql_query(" SEL...

Markdown implementation in PHP parses text within <a> tags — how does one disable this behavior?

I'm using the Markdown library for PHP by Michel Fortin. I started noticing that it formats the text in tags with markdown rules, like so: http://foo.com/My_Url_With_Underscores essentially becomes: <a href="...">http://foo.com/My&lt;em&gt;Url&lt;/em&gt;With_Underscores&lt;/a&gt; How do I disable that behavior or otherwise prevent...

How to populate html combo box with mysql data

Please help, I'm having trouble loading mysql data on the combo box. The data that I'm loading is 1 column from a table. Here is my current code, and it crashed firefox for some reason: <td colspan=”2″>Religion</TD> <td> <select name="REL" onClick="submitCboSemester();"> <?php $query_disp="SELECT * FROM Religion ORDER BY RID"; $result_d...

PDOStatement to json

How would I convert a PDOStatement to json? Is there lib out there to do this? EDIT: I need to jsonify a PDO::FETCH_OBJ. Sorry, thanks for all of the responses. json_encode does not have the ability to jsonify a PDO::FETCH_OBJ. Thanks. ...

MySQL Insert Data Question

Hi, assume I already created a table in MySQL as below CREATE TABLE IF NOT EXISTS `sales` ( `id` smallint(5) unsigned NOT NULL auto_increment, `client_id` smallint(5) unsigned NOT NULL, `order_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `sub_total` decimal(8,2) NOT NULL, `shipping_cost` deci...

How to pair users? (Like Omegle.com)

Hi, I'm trying to do an Omegle.com clone script, basically for learning purposes. I'm doing it in PHP/MySQL/AJAX. I'm having problems finding two users and connecting them. The purpose of omegle is connecting two users "randomly". What I'm doing right now is the following: When a user enters the website a session is assigned. There ...

What does a JSON-encoded request look like?

I'm building an API using PHP. What do I need to do to recognize a JSON encoded request? Does it come with a certain request type? How do I get just the request body so that I can json_decode it? ...

Beginning python for the web

I'm looking for a nice tutorial or framework for developing Python written web applications. I've done lots in PHP, but very little in Python or Ruby and figured I'd start with the first one alphabetically. ...

CodeIgniter - How to hide index.php from the URL

This is what my .htaccess looks like. The .htaccess is sitting in /www/scripts directory which is the parent of codeigniter's "system" directory and which also contains index.php. I have enabled mod_rewrite in my Apache 2.2.x. This is on Ubuntu 9.10 server. I followed this link, but it does not work. Is there anything i need to do in ap...

changing required field dynamically

Hello In my project my project manager says me to make 'state' the field required if the country is united states and make the city field optional if the country is not US. How to accomplish it? Any help? ...

compare previous ENCRYPT() call with new ENCRYPT() call mysql

I'm storing a string in mysql with the ENCRYPT() function. I want to fetch a row where that string is matched, but the new ENCRYPT() call gives me a different value, so they never match. This is expected as i'm not (and can't) give it a consistent salt: http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_encrypt ...

Trying to understand MVC Models, Advice?

I am writing my own MVC for the purpose of learning it. I have pretty much everything "down-pat" and my main stuff written besides models due to some trouble understanding them and lack of viable examples. Now, I've been told a model should reprecent a single row, someone told me, your model class should on update/insert and delete rows...

How to create a magic square in PHP?

I'd like to try my hand at creating a Magic Square in PHP (i.e. a grid of numbers that all add up to the same value), but I really don't know where to start. I know of the many methods that create magic square, such as starting "1" at a fixed position, then moving in a specific direction with each iteration. But that doesn't create a tru...

Using PHP as template language

Edit: Great points all around, dedicated templating language is obviously the way to go. Thanks! I wrote up this quick class to do templating via PHP -- I was wondering if this is easily exploitable if I were ever to open up templating to users (not the immediate plan, but thinking down the road). class Template { private $allowed_met...

PDO::fetchAll vs. PDO::fetch in a loop

Just a quick question. Is there any performance difference between using PDO::fetchAll() and PDO::fetch() in a loop (for large result sets)? I'm fetching into objects of a user-defined class, if that makes any difference. My initial uneducated assumption was that fetchAll might be faster because PDO can perform multiple operations in ...