Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. add and show events on a calender in php/msql problem

add and show events on a calender in php/msql problem

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phphtmlhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tryingmybest89
    wrote on last edited by
    #1

    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

    G M 2 Replies Last reply
    0
    • T tryingmybest89

      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

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      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 the if($_POST) { ... block, so if the page is loaded without POST data then they will be undefined.

      T 1 Reply Last reply
      0
      • G Graham Breach

        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 the if($_POST) { ... block, so if the page is loaded without POST data then they will be undefined.

        T Offline
        T Offline
        tryingmybest89
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • T tryingmybest89

          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

          M Offline
          M Offline
          Mutinda Boniface
          wrote on last edited by
          #4

          The 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... }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups