Look at my code please...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
morpia
Forum Newbie
Posts: 11
Joined: Tue Mar 27, 2007 2:12 pm

Look at my code please...

Post by morpia »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a code on that is a form to upload videos to my site in a database and something im doing is not allowing it to load, so can you look at this for me please.

The table is located under _videos --> upload --> and the "field" "title" is "upload" and the other field is "code", which is the code that I am trying to upload.  Here is a screenshot...

http://morpia.com/php_problem.JPG

Page I am trying to put this on can be found here:  http://morpia.com/site.php?page=upload

Code: Select all

<?php
$dbhost = 'localhost';
$dbuser = 'morpiaco_videos';
$dbpass = '*****';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = 'morpiaco_videos';
mysql_select_db($dbname);

$query  = "SELECT title, code FROM upload WHERE code='$code'";
$result = mysql_query($query);

mysql_query("SELECT DATE_FORMAT(date, '%m/%d/%Y') as formatteddate");

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>

<? echo $row['code']; ?>



<?
}
mysql_close($conn);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You have no error checking at all. Try it with error checking and post back what is reported.
morpia
Forum Newbie
Posts: 11
Joined: Tue Mar 27, 2007 2:12 pm

Post by morpia »

i never quite learned how to do that, i thought myself php sort of. Can you tell me what the code is in order to check them.

I know it has
"

if (blah blah blah)

else (blah blah blah)

"

thats about all i know for that
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try this and see what it does...

Code: Select all

<?php
$conn = mysql_connect('localhost', 'morpiaco_videos', '*****') or die ('Error connecting to mysql:' . mysql_error());
mysql_select_db('morpiaco_videos') or die(mysql_error());

$query  = "SELECT title, code FROM upload WHERE code='$code'";
$result = mysql_query($query) or die(mysql_error());

// This is going to do nothing at all for you
//mysql_query("SELECT DATE_FORMAT(date, '%m/%d/%Y') as formatteddate");

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo $row['code'] . '<br />';
}
mysql_close($conn);
?>
morpia
Forum Newbie
Posts: 11
Joined: Tue Mar 27, 2007 2:12 pm

Post by morpia »

Warning: mysql_connect(): Access denied for user: 'morpiaco_videos@localhost' (Using password: YES) in /home/morpiaco/public_html/upload.php on line 2
Error connecting to mysql:Access denied for user: 'morpiaco_videos@localhost' (Using password: YES)



and that date format was from my old site, i simply took the old code and tried putting it on my new site and changed a little of it, and apparently it didnt work
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

$query  = "SELECT title, code FROM upload WHERE code='$code'";
Should be ...

Code: Select all

$query  = "SELECT `title`, `code` FROM `upload` WHERE `code`='" . mysql_real_escape_string($_POST['code']) . "' LIMIT 1";
Well you can remove the LIMIT 1 part if you expect multiple rows..
morpia
Forum Newbie
Posts: 11
Joined: Tue Mar 27, 2007 2:12 pm

Post by morpia »

That doesnt seem right and if it is, it didnt work, and i tried various alterations of the code u just posted along with the exact thing


Well i used this

Code: Select all

$query  = "SELECT `title`, `code` FROM `upload` WHERE `code`='" mysql_real_escape_string($_POST['code']);
and then the error changed to "Parse error: parse error, unexpected T_STRING in /home/morpiaco/public_html/upload.php on line 5"
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

The code I posted is correct, but it's not going to fix your Access denied message.
morpia
Forum Newbie
Posts: 11
Joined: Tue Mar 27, 2007 2:12 pm

Post by morpia »

Never mind, i got it by myself, it had absolutely nothing to do with anything any of you said. I took off the code u suggested and took off the "WHERE 'code'=" thing and it worked fine...




http://morpia.com/page.php?page=upload
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

If You are Hosted in some shared Server Go to your control panel to get the correct User Name. Or Create A New Use From Php My Admin. And Then Use That User name.
Post Reply