Josh Connerty 20 Unverified User

0I think cpanel has the databse wizard correct? Well when you create a user you must add them to the database you are using. This is because the user can do everything they need to do but have no database assigned thus can't access your database.

If you have any issue's doing this then you should fisrt speak with your web host and ask them if they can do it :P

Or post back here for help I'm sure I can post some images with instructions etc.

Josh Connerty 20 Unverified User

Hmmm who is your web server host? Youm are right this seems very much like you either have the wrong username or password or maybe a database name etc.

There are a few ways you can debug this error on the connection variables try adding this:

$con = mysql_connect( "host" , "username" , "password" ) or die( "SERVER SELECT ERROR: " . mysql_error() );

$db = mysql_select_db( "database" , $con ) or die( "DB ERROR: " . mysql_error() );

If these return any problems then it is indeed one of the listed problems. However if it isn't then it has something to do with your query. Make sure that the table exists and that you have not givein it an upercase name (must all be lower case, some linux servers do this).

If you get any errors please post them back here.

Hope this helps you out a little.

Josh Connerty 20 Unverified User
<?php
mysql_connect("localhost", "user", "password");
mysql_select_db("MyDataBase");
$mydbstuff = mysql_query("SELECT  * FROM `MyTable`");
$ALine = mysql_fetch_array( $mydbstuff );
$theTitle = $ALine['title'];

echo $theTitle;
?>

Try that it might work better.

Did you notice you were not running a query at all?

The best way to do what you are trying to acheive is:

1) Run a query to pull the data [$query = mysql_query("SELECT * FROM `MyTable`");]
2) Put it into an array [$row = mysql_fetch_array( $query )]
3) Take the specific array [$variable = $row;]

Josh Connerty 20 Unverified User

WinSCP is a good one.

Well, I was thinking more along the lines of .htaccess. You could add a mimetype decalring JPG as an image. This as far as I know will work fine.

But it is a good idea to change them all. You could run a simple command on the upload script or can manually run a script post upload that will scan for all the .JPG files and change them to .jpg.

I think the upload version is much better and I would also advise image resizing. This will also speed up the page loading. For instance if the client was to upload a 1024x768 image that will take a very long time to load. If you resize it to at max a 90x90 then this will reduce the download time to virtually null.

Josh Connerty 20 Unverified User

Does it work if you only order by one of the terms by removing the + and the following statement?

Josh Connerty 20 Unverified User

Can anyone please help.I am trying to add values to a table from 2 dropdown lists which are dynamically poulated.
I have managed to achieve it for one drop list but have added a second and cannot create the correct syntax to add both values to the table.

// Check for a URL.
	if (eregi ('^([[:alnum:]\-\.])+(\.)([[:alnum:]]){2,4}([[:alnum:]/+=%&_\.~?\-]*)$', $_POST['url'])) {
		$u = escape_data($_POST['url']);
	} else {
		$u = FALSE;
		echo '<p><font color="red">Please enter a valid URL!</font></p>';
	}
	
	// Check for a URL title.
	if (!empty($_POST['title'])) {
		$t = escape_data($_POST['title']);
	} else {
		$t = FALSE;
		echo '<p><font color="red">Please enter a URL name/title!</font></p>';
	}
	
// Check for a URL date.
	if (!empty($_POST['pub_date'])) {
		$p = escape_data($_POST['pub_date']);
	} else {
		$p = FALSE;
		echo '<p><font color="red">Please enter a date!</font></p>';
	}

		
	// Check for a description.
	if (!empty($_POST['description'])) {
		$d = escape_data($_POST['description']);
	} else {
		$d = FALSE;
		echo '<p><font color="red">Please enter a description!</font></p>';
	}
	
		// Check for a publisher.
	if (isset($_POST['posters']) && (is_array($_POST['posters']))) {
		$poster = TRUE;
	} else {
		$poster = FALSE;
		echo '<p><font color="red">Please choose a Publisher!</font></p>';
	}
	
	// Check for a category.
	if (isset($_POST['types']) && (is_array($_POST['types']))) {
		$type = TRUE;
	} else {
		$type = FALSE;
		echo '<p><font color="red">Please choose a Client!</font></p>';
	}
		
	if ($u && $t && $d && $p && $type && $poster) { // If everything's OK.
	

		// Add the URL to the urls table.
		$query = "INSERT INTO urls (url, title, description, pub_date) VALUES ('$u', '$t', '$d', '$p')";		
		$result = @mysql_query ($query); // Run the query.
		$uid …
Josh Connerty 20 Unverified User

Can you give me the exact result resource error please. This will help me diagnose the issue.

Aslo you will need to post your script in [ code ] tags.

Josh Connerty 20 Unverified User

I see your logic but it is somewhat floored.

If you just create a table that will hold your users details WITH AN ID!

Then you can create another table that will hold files. For instance:

file_id | owner_id | name | source | downloads

This is of course if you want to count the downloads done the source will hold the http:// source of the file, the name will be the name of the file and the file_id will be the identinfying primary key. The most important one is the owner_id, this should be the same as the users id.

Then you can run a simple query using the users id:

// The cookie holding the users username
$username = $_COOKIE['username'];
// The id from the table using thr users username to pull the row
$user_id = fetch("SELECT `owner_id` FROM `users` WHERE `username` = '$username'");
// Run the query to select all of the downloads for the specified user
$query = mysql_query("SELECT * FROM `users` WHERE `owner_id` = '$user_id'");
// Run a loops to echo out the downloads
while( $row = mysql_fetch_array( $query ) ) {
     echo '<p>Name: '.$row['name'].'</p>';
     echo '<p>Downloads: '.$row['downloads'].'</p>';
     echo '<p><a href="download.php?dl_id='.$row['id'].'">Download the file here.</a></p>';
}

This is ofcourse only if you wish to count the downloads and try (a little bit) to hide the actual url of the file. The download.php would run similar querys to make sure the user has permition to download this file then return maybe an …

Josh Connerty 20 Unverified User

Well they are extremely easy to make. Do you have much PHP/MySql knowledge?

I could probably whack one out in a few hours. Of course for me to give you any ideas of how this might be done I would need to know what you have so far so as we could build around this.

Josh Connerty 20 Unverified User

I presume you mean it doesn't send to the database?

The only thing I have noticed is that the way in wich you are connecting is not the way in wich I would.

I have seen others connect this way but they were all having problems, my advice would be to stick to the w3schools method.

$con = mysql_connect( "localhost" , "root" , "" ) or die( "MySQL ERROR: " . mysql_error() );
$db = mysql_select_db( "kawempe_hc" , $con ) or die( "MySQL ERROR: " . mysql_error() );

Also as apose to addslashes I would use mysql_real_escape_string this will make sure that the database puts the data in a way that it will be able to accept it.

If the problem persist after these corrections please can you send an SQL export of your table (passwords don't need to be included) not the data just the structure.

Josh Connerty 20 Unverified User

Try typing your query into phpMyAdmin and see if that returns any rows for the query.

It seems that the query will not return the rows due to the fact MySql will not use that format of time. It could also be that you don't have a start date that is exactly the time in wich you are unputting but I kinda thought that was obvious so you wouldn't make that mistake.

Josh Connerty 20 Unverified User

It would seem that you will need to run a mysql_num_rows check on your query, it seems that the query is returning no matches or start dates.

echo mysql_num_rows( $q );
// $q being whatever variable you ran the mysql_query under.

Also I'm a bit un-nerved with your method. I would imagine using timestamps would make things much easier.

That way you convert the date put in to a timestamp then it would select any timestamps that are closer to the curent time because the timestamp would be a bigger number. If you catch my drift.

You should look into it, also there are functions that convert Y/M/D to a timestamp.

Josh Connerty 20 Unverified User

Ok can you use a client like phpMyAdmin to view the tables themselves?

If so do the dates indeed look like that?

What is the field name in wich the dates come under?

Have you changed the echo $row to echo $row ?

This should echo out the start dates.

Give these a try and so what you come up with.

Josh Connerty 20 Unverified User

Ok so where the loop is (while( $row = mysql_ ) you need to change the array's to the names of each field on the rows of your table.

HTML FILE:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bookings Details </title>
</head>
<body>
<p>Enter the client and Booking date below to chek bookings information </p>
<form action="../actions/bookings_details.php" method="post">

<p><label for="D M Y">Booking Date:</label><br />
<input id="D M Y" name="D M Y" type="text" /></p>

<p><input type="submit" value="Check Booking" /></p>
</form>

</body>
</html>

PHP FILE:

<html>
<head>
<title>Bookings  Details</title>
</head>
<body>
<?php
$con = mysql_connect("xxxxxx","xxxxxxx","xxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xxxxxxxx", $con);
$date = $_POST['D M Y'];
$q = mysql_query( "SELECT * FROM bookings WHERE startdate='$date'" );
while( $row = mysql_fetch_array( $q ) ) {
    echo $row['date']."<br />";
    echo $row['availbale']."<br />";   
}
mysql_close($con);
?>

</body>
</html>

Try this out and see what you get.

The main problem was you wasn't executing the query correctly and you weren't asking PHP to echo out the results set.

Josh Connerty 20 Unverified User

Hi
I will explain what I am trying to do:
I have used MYPHP admin to create a database where user booking details will be stored in a table called bookings.
Now I need to retrieve all the bookings for a specific date. For achieving this I have created two pages one is html page for user to type the date and click on get bookings and the second page is a php page where it will have the database connection and the MySQL query.
But it only returns a blank page. Below are my html and php pages code.
Any help will be highly appreciated
Kind Regards
HB25
Html page

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bookings Details </title>
</head>
<body>
<p>Enter the client and Booking date below to chek bookings information </p>
<form action="../actions/bookings_details.php" method="post">

<p><label for="date">Booking Date:</label><br />
<input id="%D  %M  %Y" name="%D  %M  %Y" type="text" /></p>

<p><input type="submit" value="check Booking" /></p>
</form>

</body>
</html>

PHP page

<html>
<head>
<title>Bookings  Details</title>
</head>
<body>
<?php
$con = mysql_connect("xxxxxx","xxxxxxx","xxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xxxxxxxx", $con);

 SELECT * FROM bookings WHERE startdate=$_POST[%D  %M  %Y];
mysql_close($con);
?>

</body>
</html

You didn't seem to actually make the query in the PHP document.

Where you wrote

mysql_select_db("xxxxxxxx", $con);

SELECT * FROM bookings WHERE startdate=$_POST[%D %M %Y];
mysql_close($con);

you need to actually send the query. For example what you would do is

$date = $_POST[%D  %M  %Y];
$query …
Josh Connerty 20 Unverified User

Hello all
i have (after much googleing) written a php script which when activated appends to a main text file with the text seen below in this exact format

type=
name=----------------------------------------------------------------------------------------------
#
type=
name=(USER INPUT HERE)
#
type=
name=----------------------------------------------------------------------------------------------
#

what i need is a simple webform with one input field where the user can enter thier name.
When they hit submit the main text file would be written (appended) to with the text shown above yet with the users name in place of (USER INPUT HERE).From what i understand this is a 3 part job and i am missing the first two parts the input and processing of the data
i have found many simple input forms but have no clue how these should be made to work with my present script which works the way it should.

Can some one point me in the right direction?
im going through all the tutorials i can at the moment and might find a solution before anyone here can help.
But there is no harm in asking .

ciao folk

thanks for any feedback

solocky

You need to first open the file: $handle = fopen( "FILEPATH" , "a" ); // a meaning amend Then you need to fwrite the file with the users input:

fwrite( "#\ntype=\nname=".$_POST['input'] , $handle );

Then close the file: fclose( $handle ); This should work.