Page 1 of 1

Look at my code please...

Posted: Thu Mar 29, 2007 4:12 pm
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]

Posted: Thu Mar 29, 2007 4:32 pm
by RobertGonzalez
You have no error checking at all. Try it with error checking and post back what is reported.

Posted: Thu Mar 29, 2007 4:40 pm
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

Posted: Thu Mar 29, 2007 4:59 pm
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);
?>

Posted: Fri Mar 30, 2007 2:44 pm
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

Posted: Fri Mar 30, 2007 2:48 pm
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..

Posted: Fri Mar 30, 2007 3:04 pm
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"

Posted: Fri Mar 30, 2007 3:10 pm
by Benjamin
The code I posted is correct, but it's not going to fix your Access denied message.

Posted: Fri Mar 30, 2007 3:21 pm
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

Posted: Sat Mar 31, 2007 12:40 am
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.