add and show events on a calender in php/msql problem
-
Hi im trying to get my calender to display on the website but it is showing errors such as this: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'joeuser'@'localhost' (using password: YES) in C:\wamp\www\prog\addeventcal.php on line 8 Notice: Undefined variable: m in C:\wamp\www\prog\addeventcal.php on line 26 & 27 & 28 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\wamp\www\prog\addeventcal.php on line 29 here is my code. Can you please explain as to why it is not working. thank you
<html>
<head>
<title>Show/Add Events</title>
<head>
<body>
<h1>Show/Add Events</h1>
<?php
$mysqli = mysqli_connect("localhost", "joeuser", "YES", "testDB");//Add any new event
if($_POST){
$m = $_POST["m"];
$d = $_POST["d"];
$y = $_POST["y"];$event\_date = $y."-".$m."-".$d." ".$\_POST\["event\_time\_hh"\]."; ".$\_POST\["event\_time\_mm"\].":00"; $insEVENT\_sql = "INSERT INTO calender\_events(event\_title, event\_shortdesc, event\_start) VALUES('".$\_POST\["event\_title"\]."'; '".$\_POST\["event\_shortdesc"\]."', '$event\_date')"; $insEvent\_res = mysqli\_query($mysqli, $insEvent\_sql) or die(mysqli\_error($mysqli));
}
//Show events for this day
$getEvent_sql = "SELECT event_title, event_shortdesc,
date_format(event_start, '%l:%i %p') as fmt_date FROM
calender_events WHERE month(event_start) = '".$m."'
AND dayofmonth(event_start) = '".$d."' AND
year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysqli_query($mysqli, $getEvent_sql)
or die(mysqli_error($mysqli));if(mysqli_num_rows($getEvent_res) > 0){
$event_txt = "<ul>";
while($ev = @mysqli_fetch_array($getEvent_res)){
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = stripslashes($ev["event_desc"]);
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."<br/>".$event_shortdesc."</li>";
}
$event_txt .= "</ul>";
mysqli_free_result($getEvent_res);
}else{
$event_txt = "";
}mysqli_close($mysqli);
if($event_txt != ""){
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}//Show form for the adding event
echo "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Would you like to add an event?</strong><br/>
Complete the form below and press the -
Hi im trying to get my calender to display on the website but it is showing errors such as this: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'joeuser'@'localhost' (using password: YES) in C:\wamp\www\prog\addeventcal.php on line 8 Notice: Undefined variable: m in C:\wamp\www\prog\addeventcal.php on line 26 & 27 & 28 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\wamp\www\prog\addeventcal.php on line 29 here is my code. Can you please explain as to why it is not working. thank you
<html>
<head>
<title>Show/Add Events</title>
<head>
<body>
<h1>Show/Add Events</h1>
<?php
$mysqli = mysqli_connect("localhost", "joeuser", "YES", "testDB");//Add any new event
if($_POST){
$m = $_POST["m"];
$d = $_POST["d"];
$y = $_POST["y"];$event\_date = $y."-".$m."-".$d." ".$\_POST\["event\_time\_hh"\]."; ".$\_POST\["event\_time\_mm"\].":00"; $insEVENT\_sql = "INSERT INTO calender\_events(event\_title, event\_shortdesc, event\_start) VALUES('".$\_POST\["event\_title"\]."'; '".$\_POST\["event\_shortdesc"\]."', '$event\_date')"; $insEvent\_res = mysqli\_query($mysqli, $insEvent\_sql) or die(mysqli\_error($mysqli));
}
//Show events for this day
$getEvent_sql = "SELECT event_title, event_shortdesc,
date_format(event_start, '%l:%i %p') as fmt_date FROM
calender_events WHERE month(event_start) = '".$m."'
AND dayofmonth(event_start) = '".$d."' AND
year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysqli_query($mysqli, $getEvent_sql)
or die(mysqli_error($mysqli));if(mysqli_num_rows($getEvent_res) > 0){
$event_txt = "<ul>";
while($ev = @mysqli_fetch_array($getEvent_res)){
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = stripslashes($ev["event_desc"]);
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."<br/>".$event_shortdesc."</li>";
}
$event_txt .= "</ul>";
mysqli_free_result($getEvent_res);
}else{
$event_txt = "";
}mysqli_close($mysqli);
if($event_txt != ""){
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}//Show form for the adding event
echo "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Would you like to add an event?</strong><br/>
Complete the form below and press theYour database connection is failing, which is causing some of your problems. Are you sure the password is "YES"? Does "joeuser"@"localhost" have permission to use the "testDB" database? The "undefined variable" message is probably because you are using
$m
(and$d
,$y
) to construct a query using them when they have not been defined. You are only defining them inside theif($_POST) { ...
block, so if the page is loaded without POST data then they will be undefined. -
Your database connection is failing, which is causing some of your problems. Are you sure the password is "YES"? Does "joeuser"@"localhost" have permission to use the "testDB" database? The "undefined variable" message is probably because you are using
$m
(and$d
,$y
) to construct a query using them when they have not been defined. You are only defining them inside theif($_POST) { ...
block, so if the page is loaded without POST data then they will be undefined.o ok. that makes sense! i went back through my code and added in a $_GET to get the $m, $y, and $d. I also changed it from joeuser to root and password to "" since there wasnt a password set up. I found that I wasnt calling my database by the right in the connection call. Thank you for your help!
-
Hi im trying to get my calender to display on the website but it is showing errors such as this: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'joeuser'@'localhost' (using password: YES) in C:\wamp\www\prog\addeventcal.php on line 8 Notice: Undefined variable: m in C:\wamp\www\prog\addeventcal.php on line 26 & 27 & 28 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\wamp\www\prog\addeventcal.php on line 29 here is my code. Can you please explain as to why it is not working. thank you
<html>
<head>
<title>Show/Add Events</title>
<head>
<body>
<h1>Show/Add Events</h1>
<?php
$mysqli = mysqli_connect("localhost", "joeuser", "YES", "testDB");//Add any new event
if($_POST){
$m = $_POST["m"];
$d = $_POST["d"];
$y = $_POST["y"];$event\_date = $y."-".$m."-".$d." ".$\_POST\["event\_time\_hh"\]."; ".$\_POST\["event\_time\_mm"\].":00"; $insEVENT\_sql = "INSERT INTO calender\_events(event\_title, event\_shortdesc, event\_start) VALUES('".$\_POST\["event\_title"\]."'; '".$\_POST\["event\_shortdesc"\]."', '$event\_date')"; $insEvent\_res = mysqli\_query($mysqli, $insEvent\_sql) or die(mysqli\_error($mysqli));
}
//Show events for this day
$getEvent_sql = "SELECT event_title, event_shortdesc,
date_format(event_start, '%l:%i %p') as fmt_date FROM
calender_events WHERE month(event_start) = '".$m."'
AND dayofmonth(event_start) = '".$d."' AND
year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysqli_query($mysqli, $getEvent_sql)
or die(mysqli_error($mysqli));if(mysqli_num_rows($getEvent_res) > 0){
$event_txt = "<ul>";
while($ev = @mysqli_fetch_array($getEvent_res)){
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = stripslashes($ev["event_desc"]);
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."<br/>".$event_shortdesc."</li>";
}
$event_txt .= "</ul>";
mysqli_free_result($getEvent_res);
}else{
$event_txt = "";
}mysqli_close($mysqli);
if($event_txt != ""){
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}//Show form for the adding event
echo "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Would you like to add an event?</strong><br/>
Complete the form below and press theThe problem is that your app[web page] doesn't create a successful database connection before passing you query statements to fetch data from the db:: //make sure you are using the correct user and password: //if you are using any Apache servers like xampp,wampp.. and you never supplied your password later on ,then the default credentials to connect to your db is:====> $host="localhost"; $user="root"; $password=""; $con = mysql_connect($host,$user,$password); if(!$con){ echo "SERVER CONNECTION FAILED : source =".mysql_error(); exit; //remember this avoid any further page processing... }