dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP Not Writin to MySQL

  1. #1
    Join Date
    Jun 2014
    Posts
    1

    PHP Not Writin to MySQL

    Hello, I am having difficulty with a script that writes to a mysql database.
    It works fine when running on a linux based server with apache installed. However when I run it on a windows server using apache, php and mysql it refuses to write to the database. all the other scripts I have work fine but this one is causing me headaches.

    Please can someone take a look and point me in the right direction.

    events.php
    PHP Code:
    <?php 
    session_start
    (); 
    $page_title 'Administration'

    if (!isset(
    $_SESSION['loggedin'])) 

    header('Location: index.php');  

    include(
    'includes/headerOut.php'); 
    include(
    'includes/nav.php'); 
    ?> 

    <?php include('db/pddb.php'); ?> 
    <!--Full Content--> 
    <div> 

    </div> 
    <!--login Content--> 
    <!--Main Content--> 
        <div id="fullmContent"> 
        <?php 
        
    include ("includes/menu.php"); 
        
    ?> 
        </div> 
        <script language="JavaScript1.2" defer> 
    editor_generate('specials'); 
    </script> 
        <div id="fullmContent"> 
        <?php 


    $username 
    $_SESSION['cre_email']; 

    if (
    $_SESSION['loggedin'] == && $_SESSION['is_admin'] == 1)  
    {  

     echo (

     <table> 
    <br /> 
     <form action="submit.php" method="post" id="admin"> 
    <tr> 
    <td><label for="name" class="label">Add a new event:</label></td> 
    <td><select name="name"> 
    <option value="Shadow Lounge#London" selected="selected">Shadow Lounge</option> 
    <option value="Retro Bar#London">Retro Bar</option> 
    <option value="Amsterdam Hotel Brighton#Brighton">Amsterdam Hotel Brighton</option> 
    <option value="Sound Leicester Square#London">Sound Leicester Square</option> 
    <option value="The Green#London">The Green Islington</option> 
    <option value="FHQ#Glasgow">FHQ Glasgow</option> 
    <option value="Test Event#Test Town">Test Event</option> 
    </select></td> 
    </tr> 
    <tr> 
    <td><label for="sdating" class="label">What Kind of Event?</label></td> 
    <td><select name="sdating"> 
    <option value="Y" selected="selected">Speed Dating</option> 
    <option value="N">Coaching</option> 
    </select></td> 
    </tr> 
    <td><label for="type" class="label">Type of event:</label></td> 
    <td><select name="type"> 
    <option value="Bisexual">Bisexual</option> 
    <option value="Womens" selected="selected">Womens</option> 
    <option value="Mens">Mens</option> 
    </select></td> 
    </tr> 
    <tr> 
    <td><label for="age" class="label">Age Range:</label></td> 
    <td><select name="age"> 
    <option value="All" selected="selected">All</option> 
    <option value="22 - 36">22 - 36</option> 
    <option value="36+">36+</option> 
    </select></td> 
    </tr> 
    <tr> 
    <td><label for="date" class="label">Date of event:</label></td> 
    <td><input type="text" name="date" size="12" maxlength="10" value="dd/mm/yyyy" class="txtbx" /></td> 
    </tr> 
    <tr> 
    <td><label for="time" class="label">Time of event:</label></td> 
    <td><select name="time"> 
    <option value="7.30pm" selected="selected">7.30pm</option> 
    <option value="12.00pm" selected="selected">12.00pm</option> 
    </select></td> 
    </tr> 
    <tr> 
    <td><label for="price" class="label">Event Price:</label></td> 
    <td><select name="price"> 
    <option value="20" selected="selected">20</option> 
    <option value="18">18</option> 
    <option value="0.01">0.01</option> 
    </select></td> 
    </tr> 
    <tr> 
    <td><label for="notes" class="label">Notes</label></td> 
    <td><textarea name="notes" cols="20" rows="5"></textarea></td> 
    </tr> 
    <tr> 
    <td><label for="img_id" class="label">Select an Image to Display:</label></td> 
    <td><select name="img_id"> 
    <option value="" selected="selected">None</option> 
    <option value="<img src="images/home/star.png" width="25" height="25" />">Pink Star</option> 
    <option value="<img src="images/home/gold.png" width="25" height="25" />">Gold Star</option> 
    <option value="<img src="images/home/bbc.png" width="70" height="30" />">BBC Logo</option> 
    <option value="<img src="images/roses.jpg" width="70" height="30" />">Pink Roses</option> 
    <option value="<img src="images/roses.gif" width="70" height="30" />">Red Roses</option> 
    <option value="<img src="images/home/balloons-icon.png" width="64" height="64" />">Pink Heart Balloons</option> 
    </select></td> 
    <td> 
    <img src="images/home/balloons-icon.png" width="32" height="32" /> 
    <img src="images/home/bbc.png" width="80" height="32" /> 
    <img src="images/home/gold.png" width="32" height="32" /> 
    <img src="images/home/star.png" width="32" height="32" /> 
    <img src="images/roses.jpg" width="32" height="32" /> 
    <img src="images/roses.gif" width="32" height="32" /> 
    </td> 
    </tr> 
    <tr> 
    <td><label for="specials" class="label">Add Extras Here You Would like added above the event.</label></td> 
    <td><textarea name="specials" cols="40" rows="10"></textarea></td> 
    </tr> 
    <tr> 
    <td><label for="status" class="label">Event Status:</label></td> 
    <td><select name="status"> 
    <option value="confirmed" selected="selected">Confirmed</option> 
    <option value="sold out">Sold Out</option> 
    <option value="cancelled">Cancelled</option> 
    </select></td> 
    </tr> 
    <tr> 
    <td><input type="submit" name="submit" value="Add Event" class="btn_med" /></td>  
    <td><input type="reset" value="Reset Form" class="btn_med" /></td> 
    </tr>'
    ); 
    ?> 
    <script language="javascript1.2"> 
    editor_generate('specials'); 
    </script> 
    <?php 
    echo ("</form> 
    </table> 
    <br /> 
    <br /> 
     "
    ); 








    else   

     
    // not logged in 
     
    echo "<script language=\"JavaScript\">window.location='./index.php'</script>"
     exit(); 

     
    ?> 
         
        </div> 
         
        <div id="fullmContent"> 

          <?php 

    $username 
    $_SESSION['cre_email']; 

    if (
    $_SESSION['loggedin'] == && $_SESSION['is_admin'] == 1
    {  
     echo (
    ""); 
      
    include(
    "db/pddb.php"); 
    $query "SELECT pd_events.eve_id, sdating, eve_type_name, eve_age_range, eve_ven_name, eve_ven_location, date_format(eve_date, '%b %D') as eve_date1, eve_time, eve_date, eve_price, eve_status,  
    COUNT(booking_id) AS attendee_count, DATEDIFF(eve_date,curdate()) AS eve_date_diff, reminder_set 
    FROM pd_events  
    LEFT OUTER JOIN pd_booking ON pd_booking.eve_id = pd_events.eve_id  
    GROUP BY eve_id, eve_age_range, eve_ven_name, eve_date, eve_time  
    ORDER BY eve_date DESC 
    "


    $result mysql_query($query); 
    echo(

      <table cellpadding=\"2\" cellspacing=\"0\" width=\"100%\" border=0 style='font-size:11px;'> 
      <tr> 
        <th colspan='12' style='color:purple;'><h1>Upcoming Events</h1><br /> 
    </th> 
      </tr>   
        <tr> 
            <th>Speed Dating</th> 
          <th>Location</th> 
          <th>Type</th> 
          <th>Age Range</th> 
          <th>Date</th> 
          <th>Time</th> 
          <th>Price</th> 
          <th>Status</th> 
          <th>Attendees</th> 
          <th colspan=\"3\">&nbsp;</th> 
         </tr> 
      "
    ); 


    $inpast 0
    while (
    $row mysql_fetch_array($result))  
    {  
      
    $formatted "&pound;".$row[eve_price]; 
      
    $sendreminder ""
      
    $bg "style='background-color:white;'" 
      if(
    $row[eve_date_diff] <= && $row[eve_date_diff] >=&& $row[reminder_set]== false
      { 
        
    $sendreminder "<div style='background-color:#FF6573;text-align:left; height:30px;'><a href='events_reminder.php?id=$row[eve_id]' style='font-weight:bold; background-color:red;color:white;text-decoration:none;'>Send Reminder</a></div>"
        
    $bg "style='background-color:#FF6573;'"   
      } 
      elseif(
    $row[reminder_set]== true
      { 
        
    $sendreminder "<div style='text-align:left;'>Reminder Sent</div>";       
      } 
       
    if(
    $row[eve_date_diff] < && $inpast == 0)   

    echo(

      <tr> 
      <br /> 
        <th colspan='12' style='color:purple;'><h1>Past Events</h1><br /> 
    </th> 
      </tr> 
      <tr> 
      <th>Speed Dating</th> 
        <th>Location</th> 
        <th>Type</th> 
        <th>Age Range</th> 
        <th>Time</th> 
        <th>Date</th> 
        <th>Price</th> 
        <th>Status</th> 
        <th>Attendees</th> 
        <th colspan=\"3\">&nbsp;</th> 
      </tr>   
    "
    ); 
    $inpast 1


    echo(

      <tr 
    $bg
      <td>
    $row[sdating]</td> 
        <td>
    $row[eve_ven_location]$row[eve_ven_name]</td> 
        <td>
    $row[eve_type_name]</td> 
        <td>
    $row[eve_age_range]</td> 
        <td style=\"white-space:nowrap;\">
    $row[eve_date]</td> 
        <td>
    $row[eve_time]</td> 
        <td align=\"right\">
    $formatted</td> 
        <td align=\"center\">
    $row[eve_status]</td> 
        <td align=\"center\"><a href='events_attendees.php?id=
    $row[eve_id]$bg>$row[attendee_count]</a?</td> 
        <td><a href=\"events_update.php?id=
    $row[eve_id]\" $bg>Update Event</a></td> 
        <td><a href=\"events_delete.php?id=
    $row[eve_id]\" $bg>Delete Event</a></td> 
        <td>
    $sendreminder</td> 
      </tr>"
    ); 

    echo(
    "</table>"); 
      
     } 
      
     else   
     { 
      
    // not logged in 
      
    echo "<script language=\"JavaScript\">window.location='./index.php'</script>"
      exit(); 
     } 
      
     
    ?> 
     </p> 
          <p>&nbsp;</p> 
        </div> 

    <?php include('includes/footer.php'); ?> 
    </div> 
    </div> 
    </div> 
    </body> 
    </html>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,299
    I'd start by changing this...
    PHP Code:
    include("db/pddb.php"); 
    $query "SELECT pd_events.eve_id, sdating, eve_type_name, eve_age_range, eve_ven_name, eve_ven_location, date_format(eve_date, '%b %D') as eve_date1, eve_time, eve_date, eve_price, eve_status,  
    COUNT(booking_id) AS attendee_count, DATEDIFF(eve_date,curdate()) AS eve_date_diff, reminder_set 
    FROM pd_events  
    LEFT OUTER JOIN pd_booking ON pd_booking.eve_id = pd_events.eve_id  
    GROUP BY eve_id, eve_age_range, eve_ven_name, eve_date, eve_time  
    ORDER BY eve_date DESC 
    "


    $result mysql_query($query); 
    ...to something like this...
    PHP Code:
    // make sure we see all errors
    ini_set('display_errors'true); // change to false before going live
    error_reporting(E_ALL);

    // assuming this must be processed, require() it instead of include()-ing it, so we know for sure it loaded:
    require("db/pddb.php"); 

    $query "SELECT pd_events.eve_id, sdating, eve_type_name, eve_age_range, eve_ven_name, eve_ven_location, date_format(eve_date, '%b %D') as eve_date1, eve_time, eve_date, eve_price, eve_status,  
    COUNT(booking_id) AS attendee_count, DATEDIFF(eve_date,curdate()) AS eve_date_diff, reminder_set 
    FROM pd_events  
    LEFT OUTER JOIN pd_booking ON pd_booking.eve_id = pd_events.eve_id  
    GROUP BY eve_id, eve_age_range, eve_ven_name, eve_date, eve_time  
    ORDER BY eve_date DESC 
    "


    $result mysql_query($query);
    // if something went wrong, now's the time to find out:
    if($result == false) {
        throw new 
    Exception("Query failed:".PHP_EOL.mysql_error().PHP_EOL.$query);
    }
    // If you set up your exception handling properly, it won't need to spray potentially
    // sensitive data to the browser when in production. 
    And, of course, the obligatory caveat: the MySQL extension has been deprecated for years now, and you really should be using at least the MySQLi extension, or else PDO (my preference).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles