Hi all,
I'm having problems running the below script. For some reason it is giving me these error messages:
Warning: mysql_query(): Access denied for user: 'xxxx@localhost' (Using password: NO) in /home/xxxx/public_html/script.php on line 91
Warning: mysql_query(): A link to the server could not be established in /home/xxxx/public_html/script.php on line 91
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xxxx/public_html/script.php on line 93
Warning: mysql_close(): no MySQL-Link resource supplied in /home/xxxx/public_html/script.php on line 117
This is the script:
<?php
Session_start();
?>
<html><body>
<?
$DBhost = "localhost";
$DBuser = "xxxx";
$DBpass = "xxxx";
$DBName = "xxxx";
$table = "plane";
$table1 = "member";
$curdate = date ("d.m.y");
$sdate = $sdated."-".$sdatem."-".$sdatey;
$edate = $edated."-".$edatem."-".$edatey;
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
//Get the last id from database
$result = mysql_query ( "SELECT MAX(id) FROM $table" );
$last_id = mysql_result ( $result, 0 );
//Increase id by 1 for unique date block
$id = $last_id+1;
//utc of start and end dates
$s=mktime(0,0,0,$sdatem,$sdated,$sdatey);
$e=mktime(0,0,0,$edatem,$edated,$edatey);
while($s<=$e){
$mid_date = date('d-m-Y',$s);
//Check to make sure all days are free
$sqlquery1 = "SELECT * FROM $table where date = '$mid_date'";
$result = mysql_query($sqlquery1);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$usname = $row['name'];
$found_date = $row['date'];
$com = $row['comments'];
$i_d = $row['id'];
if ($found_date !="")
{
echo "Sorry date already taken by $usname.<br>";
//Display the dates that are taken
$sqlquery = "SELECT * FROM $table where id = '$i_d'";
$result = mysql_query($sqlquery);
$us_name = $row['name'];
$used_date = $row['date'];
$coms = $row['comments'];
//Print date block
While( $row = MySQL_fetch_array($result,MYSQL_ASSOC) ) {
$used_date = $row['date'];
$us_name = $row['name'];
$coms = $row['comments'];
//How the text looks on the screen
echo("$used_date - $us_name - $coms<br>");
}//end while
exit();
}//end of first if
else
{
print $mid_date."<br>"; //display date in mySQL format
$sqlquery2 = "INSERT INTO $table VALUES('$id','$mid_date','$uname','$comments','$curdate')";
$results = mysql_query($sqlquery2);
$s=$s+86400; //increment date by 86400 seconds(1 day)
}//end if
}//end while
mysql_close();
print "<html><body><center>";
print "<p>You have just entered this record<p>";
print "Start Date : $sdate<br>";
print "End Date : $edate<br>";
print "Name :$uname<br>";
print "Comments :$comments<br>";
print "</body></html>";
///////THIS IS THE PROBLEM AREA!!!////////////////////////////////////
$sqlquery3 = "SELECT * FROM $table1";
$result = mysql_query($sqlquery3);
While( $row = MySQL_fetch_array($result,MYSQL_ASSOC) ) {
$mailto = $row['email'];
//How the text looks on the screen
//echo("$mailto<br>");
$to = $mailto;
$subject = "Plane booking";
$message = "The plane has been booked by $uname.
Start date = $sdate
End date = $edate
Regards
The team
";
$headers = "From: webmaster <xxx@xxxxx.com>";
mail($to,$subject,$message,$headers);
}//end email while
//////////////////////////////////////////////////////////////////////////////////
mysql_close();
?>
An email has been sent to all members informing them of this booking.
</body>
</html>
I have created a new php page using the exact code (copied and pasted) that I have here but only for the problem area but rather than sending the mail out I have just echo'd the email addresses to the screen just to make sure that the select statement is getting the correct info (it does) and I have no error messages!
Can anyone help me please?
Thanks
P.s excuse the sloppy code I'm a noob :rolleyes: