Solutions to errors » PHP


 Currently Browsing PHP Errors
Q&A: PHP / MySQL Problem…?

Question from Having Problems also: PHP / MySQL Problem…?
Hello, I have a quick MySQL and PHP Problem. I am a total n00b, reading from PHP And MySQL For Dummies Edition 3. I have a program which gives me NO errors. It is suppose to create a Database and bring you to a new page, but it seems to not do that. All it does is refresh the page. You can find my broken version here: http://www.kyleboss.com/testing/mysql_send.php .
The working version here: http://www.stevemarth.com/tests/mysql_send.php
And lastly, the code can be found Here (It is too large to put in this question) :
http://forums.mysql.com/read.php?52,152573,152573
Any help would be greatly appreciated
Thanks ben :D But I do have an action..

? Right below

or

please HELP

Popular answer:

Answer by Vidula R
any hardware firewalls you should add exceptions to?

Add your own answer to this error in the comments!

What does this php error message mean?

Question from Alex: What does this php error message mean?
What does this message mean? I want to know more about what it means than how to fix it (although if anyone knows, tell me):

Parse error: syntax error, unexpected T_VARIABLE in /home/a4732373/public_html/members/include/session.php on line 73

And also, what is if it says unexected T_STRING?

thanx

Popular answer:

Answer by Josh C
You’re probably missing a semi-colon or bracket before that line.

Give your answer to this error below!

How to create a form that allows users to send a message and attach multiple files uploads. PHP action?

Question from michaelnaeseth: How to create a form that allows users to send a message and attach multiple files uploads. PHP action?
I need to create a form that allows visitors to my website to send me a message AND upload multiple files. I also need the PHP script to rename the uploaded files to reflect the uploader’s name. Thanks in advance for any help.

Popular answer:

Answer by cam1883
Check hotscripts.com they will have exactly what you are looking for. Other best bet would be to check tutorialized.com I dont think writing an entire tutorial on how to do this will be beneficial on yahoo answers as it would be long and tedious as well there are not enough functions on wysiwyg to make a tutorial.

Add your own answer to this error in the comments!

i cant get on pengspace.com?

Question from kevin: i cant get on pengspace.com?
can someone type in pengspace and see if its working? everytime i try to go there it says Fatal error: Uncaught exception ‘XN_Exception’ with message ‘Failed query: XN_Query: subject [Content] returnIds [] begin [0] end [] alwaysReturnTotalCount [] orders [ published : asc : date ] filters [ owner.relativeUrl : = : 'pengspace' : string AND type : = : 'User' : string AND title : eic : 'WowImcool' : string ] Internal server error #0 /php/includes/XN/XN/REST.php(127): XN_REST->doRequest(’GET’, ‘http://pengspac…’, NULL, NULL, NULL) #1 /php/includes/XN/XN/Query.php(1153): XN_REST::get(’http://pengspac…’) #2 /php/includes/XN/XN/Query.php(427): XN_Query->_executeQuery() #3 [internal function]: XN_Query->execute() #4 /apps/socialnetworkmain/lib/XG_Query.php(246): call_user_func_array(Array, Array) #5 /apps/socialnetworkmain/lib/XG_Query.php(81): XG_Query->cache(’execute’, Array) #6 [internal function]: XG_Query->__call(’execute’, Array) #7 /apps/socialnetworkmain/widgets/index/models/User.php(231): XG_Query->execute() #8 /apps/socialnetworkmain/lib/XG_SecurityHelper.php(186): User: in /php/includes/XN/XN/Exception.php on line 52

Popular answer:

Answer by dino d
Ning is taking a short break!
Our experienced technicians (pictured) are currently hard at work so as to bring Ning back online shortly. Thanks for your patience.

If you have any questions, feel free to visit the Ning Blog.

Give your answer to this error below!

Why is my yahoo and msn homepage being directed to http//account box com/warning/2.php?

Question from atdianekerr: Why is my yahoo and msn homepage being directed to http//account box com/warning/2.php?

Popular answer:

Answer by AmandaKerik
Congradulations… you’ve got spyware (technically a homepage hijacker)

Scan your computer with anti-spyware programs, virus scanners, etc.

If it’s a legitimate toolbar you can probably uninstall it under start > control panel > add / remove programs

Download a few anti-virus and anti-spyware programs, oh and a firewall.
( Avg antivirus – http://free.grisoft.com/ , Adaware anti-adware – http://www.lavasoftusa.com/software/adaware/ , Spywareblaster antispyware – http://www.javacoolsoftware.com/spywareblaster.html , Zonealarm firewall – http://www.zonelabs.com/store/content/company/products/znalm/freeDownload.jsp )

It’s almost guaranteed you got some nasties through either just using Internet Explorer, or downloading stuff you shouldn’t.

Internet Explorer is big, slow, insecure (you’re almost guaranteed to have some viruses and spyware right now), very out of date, and not customizable.

Drop Internet Explorer from use and get Firefox – sleek, fast, safe, easy to use, up to date, extremely customizable… and it has a cool icon.
( Firefox web browser – http://getfirefox.com/ )

Firefox has pop-up blocking built in, and with just one add-on you’ll rarely see another banner ad!
(Firefox adblocking add-on – http://adblockplus.org/ )

Install the programs and scan your computer. You might want to stay offline for this – you’re not protected until AFTER you do it.

After that – password protect your computer account. If you use a wireless connection see if you can get it secured (passwords and encryption)

Make sure to update your virus and spyware scanners once a week, and check for updates to your firewall… and operating system.

Questions? Comments? E-mail me at amandakerik at yahoo dot com.

If you have a better solution to this error, please comment below.

What is the issue with my php/mysql syntax using min() function?
php issue
by xazac

Question from victorypie.com: What is the issue with my php/mysql syntax using min() function?
This is the error I’m getting “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 ‘id #2′ at line 1″

Below is the php/mysql code

// Creates connection with database
$link = mysql_connect("webdb","db","password");
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("jokes", $link);
// the line below is where the issue is according to the error
$min_views = "SELECT min(views) FROM db.jokes";
$min = mysql_query($min_views) or die(mysql_error());
$query = "SELECT question, answer, id, views FROM db.jokes WHERE views = $min";
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result) or die(mysql_error());
$question = $row['question'];
$answer = $row['answer'];
$id = $row['id'];
$update = "UPDATE db.jokes SET views = (views + 1) WHERE id = $id";
mysql_query($update) or die ("Error. Please refresh the page or click the home button
“);
?>

The goal is to find the lowest value in the ‘views’ column and store it in variable $min

Then, find all rows where the view column = $min and pick a random one of those rows.

The code was working fine until I added in the twist involving finding the lowest view value before selecting the random row.

ALSO – what is a better site to post such a question.. something tells me there are better places to ask these type of questions as to not bore the 99% of the population to which this is all a foreign language.

Popular answer:

Answer by jimbot
I think you have to use a GROUP BY clause if you use the MIN function. Try
SELECT MIN(views) FROM jokes GROUP BY id

However, the best way would be to order the recordset by views and just take the first record. Also, you could add a random component so that if many jokes had the same views value, it would pick one at random:
SELECT id FROM jokes ORDER BY views ASC, RAND() LIMIT 0,1

Note that this has now combined your first two queries. Always better to do it with one query than two. (You can select the other fields as well if you want)

Add your own answer to this error in the comments!

in PHP – PDOException not working in try/catch?

Question from Inter B: in PHP – PDOException not working in try/catch?
Even when the query fails, it never throws an exception(not even a generic one). Does anyone know why?

try
{
$result = $this->db->query($sql);
}
catch(PDOException $e)
{
$this->exit_page(’Database Errorrr’, $e->getMessage());
}
This is a PDO data object. This is dealing with a PDOException object.
This should be sufficient information.

Popular answer:

Answer by AXN
Okay, so there is no message even when an error appears.

Why didn’t you posted the whole function?
I can only give you a working example:

error_reporting(0);
function query($sql) {
if(mysql_query($sql)) {
return true;
} else {
throw new Exception(mysql_error());
}
}
//trigger exception in a "try" block
try
{
query("SELECT * FROM `test`");
echo 'If you see this, everything is fine.';
}

//catch exception
catch(Exception $e)
{
echo 'Database Errorrr: ' .$e->getMessage();
}
?>

Testing this in an empty file should output “Database Errorrr: Access denied for user ‘ODBC’@'localhost’ (using password: NO)”

If you have a better solution to this error, please comment below.

Why is this PHP/mySQL query so slooooow?

Question from ~*Stephanie S: Why is this PHP/mySQL query so slooooow?
function add_bm($new_url)
{
// Add new bookmark to the database
echo “Attempting to add “.htmlspecialchars($new_url).’
‘;
$valid_user = $_SESSION['valid_user'];

$conn = db_connect();

// check not a repeat bookmark
$result = @mysql_query(”select * from bookmark where username=’$valid_user’
and bm_URL=’$new_url’”);
if ($result && (mysql_num_rows($result) > 0))
throw new Exception(’Bookmark already exists.’);

// insert the new bookmark
$sql = (”insert into bookmark values (’$valid_user’, ‘$new_url’)”);
if (!$sql)
throw new Exception(’Bookmark could not be inserted.’);

return true;
}

I am creating a webpage (at http://finallyfitness.net/bookmarks) that uses this code once you’ve registered, logged in, and are trying to add bookmarks to save in your account. The problem is, when you type in the bookmark that you want to save and click Submit, it takes a full minute before the page uploads it. Why???
Also, after this code is executed, the entire site runs very, very slowly for two or three full minutes. What in the world is going on?

Popular answer:

Answer by wbriii13
Well I looked at your code and I don’t see the error. Of course I am blind in one eye and can’t see out of the other.

Have you tried using a debugger? Gubed is open source and works pretty good.

http://sourceforge.net/projects/gubed/

Sure hope this helps. I know I wasn’t much help. When you find the problem I would like to know what it was.

Thanks and good luck.

P.S. Here is another site that might help,
http://www-128.ibm.com/developerworks/opensource/library/os-debug/

Add your own answer to this error in the comments!

Q&A: PHP code snippit: What does this parameter mean?

Question from ~*Stephanie S: PHP code snippit: What does this parameter mean?
if (!(@fopen($new_url, ‘r’)))
throw new Exception(’Not a valid URL.’);

This is supposed to test whether a URL that a user enters is valid or not. What does the parameter ‘r’ mean?

*** *** *** *** *** *** *** *** ***
NOTE: If it helps, the complete code for this try/catch block is as follows:

try
{
check_valid_user();
if (!filled_out($_POST))
{
throw new Exception(’Form not completely filled out.’);
}
// check URL format
if (strstr($new_url, ‘http://’)===false)
$new_url = ‘http://’.$new_url;

// check URL is valid
if (!(@fopen($new_url, ‘r’)))
throw new Exception(’Not a valid URL.’);
// try to add bm
add_bm($new_url);
echo ‘Bookmark added.’;

// get the bookmarks this user has saved
// if ($url_array = get_user_urls($_SESSION['valid_user']))
// display_user_urls($url_array);
}
catch (Exception $e)
{
echo $e->getMessage();
}

Popular answer:

Answer by Influx UK
It means ‘read’.

Try looking here if you wanted a different method of getting a web URL.
http://www.zend.com/manual/function.fopen.php

Hope it helps.

PS: I’ve seen your questions, looks like you’re trying real hard learning PHP, if there’s any references that you might want, then just email me via my profile.

Influx.

Add your own answer to this error in the comments!

Page 1 of 2512345»...Last »