I want to check for the username in the users table. If it's found, then I want to get the id. Otherwise, I want to insert the username as a new record, then get the id.
Here's my code:
<?PHP
$sql = "SELECT id FROM users where username = '$username'";
$query = mysql_query($sql) or die(mysql_error());
$result = mysql_num_rows($query);
if...
Here's a small example (download, rename to .php and execute it in your shell):
test.txt
Why does preg_replace return NULL instead of the original string?
\x{2192} is the same as HTML "→" ("→").
...
So ereg won't be present in PHP6. And I don't really care, because I'm using PCRE functions. But for multibyte strings, I'm using mb_ereg_* functions. The question is: they'll be present in PHP6 in the mbstring extension, or I will have to switch to some kind of multibyte PCRE functions?
...
Trying to create a simple text-translator in PHP.
It shoult match something like:
Bla bla {translator id="TEST" language="de"/}
The language can be optional
Blabla <translator id="TEST"/>
Here is the code:
$result = preg_replace_callback(
'#{translator(\s+(?\'attribute\'\w+)="(?\'value\'\w+)")+/}#i',
array($this, 'translateTe...
I'm using PHP's new(ish) Date classes for a calendar/scheduler I'm developing. I am trying to extend DateInterval so that I limit the interval to particular sizes like 1 year, 1 month, 1 week or 1 day. The extended class would be used to help generate the calendar view.
I'm getting the PHP error: Unknown property (days) when I run the f...
Today, I removed and reinstalled the latest version of lampp in order to move to php 5.30, and suddenly a very simple app is failing to connect to the mysql database. I'm using PDO to connect, and receiving the following error:
Warning: PDO::__construct() [pdo.--construct]: [2002] Invalid argument (trying to connect
via unix://) in /h...
$dml = "insert into ... ";
mysql_query($dml,$con);
$Id = isset($row) ? $row['id'] : mysql_insert_id($con);
I saw the record is created,but just can't retrieve the Id.
What's wrong?
EDIT
fixed,it's caused by $row.
...
I want to generate all combination of length r from a set [0...(n-1)]
So the output should be like this (n = 6 r = 2)
$res = array(array(0,1),array(0,2),array(0,3),array(0,4),array(0,5),array(1,2),array(1,3),array(1,4),array(1,5),array(2,3),array(2,4),array(2,5),array(3,4),array(3,5),array(4,5));
with a function like
function permut...
Is there a PHP framework that doesn't force me to use a single index.php as the entry point, or an MVC architecture? Because I need to develop something in my own way, with features like Authentication, Security, Crypto, Database CRUD and the like, and so a framework of some sort could help. Is this RAD?
...
I want to validate a string only if it contains '0-9' chars with length between 7 and 9.
What I have is [0-9]{7,9} but this matches a string of ten chars too, which I don't want.
Thanks.
...
How do I create message queue in PHP, such that it can be modified and read by 2 different scripts running at the same time? Or is it better to use a database for this?
...
Does PHP have global variables that can be modified by one running script and read by another?
...
I'm presently building (at this point, prototyping is a better term) a paid subscription site using Drupal. After searching through the Drupal modules - I haven't been able to find anything that will allow me to create a new Drupal account once the user has visited my landing page, decided they want to subscribe, and provided their valid...
Hello
I have changed the php.ini file in the location (C:\xampp\apache\bin\php.ini) for Xampp and restart the server
I am sure it is the real php.ini file because I have checked with phpinfo()
however my changes does not take effect!
why?
update:
I have PHP Version 5.2.8
I have changed the file C:\xampp\php\php5.ini
but the pr...
I've spent the last couple days trying to get ODBC installed and I am about to lose my mind, I'm way out of my element here. Please can some one help me before I fall to pieces. Here's what I'm trying:
1) Download 1.7.2 source code package found here (I'm using 1.7.2): http://www.mamp.info/en/downloads/index.html
2) CD into the php dir...
I have a PHP object coming from an outside source (using PEAR's XML_Serializer). Some variables have dashes in the name like:
<?php
$company->{'address-one'};
I just want to know what the best way to go through this object and rename the object properties with underscores replacing the dashes so I don't have to deal with the sill...
Hi all,
For IIS (5.0 or higher), are there alternatives to apache's .htaccess directives php_flag and php_value to set PHP_INI_PERDIR config values?
Thanks.
...
How can something like the following be done in a PHP script?
code{
$result1 = task1() or break;
$result2 = task2() or break;
}
common_code();
exit();
...
Hi everyone. I'm trying to use the following code to create a zip file from a directory and serve it to the user via an http download:
// write the file
file_put_contents($path . "/index.html", $output);
// zip up the contents
chdir($path);
exec("zip -r {$course->name} ./");
$filename = "{$course->name}.zip";
header('Content-Type: ...
I am using a Front Controller to send the user through a series of pages with questions. Pretty much everything must be dynamic as the pages, the questions, and everything else is set in the admin interface and stored in the database.
I am tracking the user's progress through the database by storing a unique identifier in the session a...