Jump to content

Search the Community

Showing results for tags 'mysql'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. I have the following query used for a google line chart. The query works and does four different monthly counts for the past 12 months to current date. I need to modify it so it does the same exact thing but weekly for the past 6 month to current date. Week starts Sunday, ends Saturday. No brain food left after this one. Getting weak... * Any improvements to current query are also encouraged. Output Image attached. <?php if (isset($_REQUEST['floor']) || !isset($_REQUEST['specialty'])) { $contract_type_id = 3; $active_column = 'active'; } if (isset($_REQUEST['specialty'])) { $contract_type_id = 2; $active_column = 'active_specialty'; } $sql="SELECT C.month, sum(slab) as slab, sum(dried_in) as dried_in, sum(drywall) as drywall, sum(frame) as frame, C.year_month_number FROM ( (SELECT CASE MONTH (l.frame_date) WHEN 1 THEN CONCAT('Jan','-',Year (l.frame_date)) WHEN 2 THEN CONCAT('Feb', '-', Year (l.frame_date)) WHEN 3 THEN CONCAT('Mar','-',Year (l.frame_date)) WHEN 4 THEN CONCAT('Apr', '-', Year (l.frame_date)) WHEN 5 THEN CONCAT('May', '-', Year (l.frame_date)) WHEN 6 THEN CONCAT('Jun', '-', Year (l.frame_date)) WHEN 7 THEN CONCAT('Jul', '-', Year (l.frame_date)) WHEN 8 THEN CONCAT('Aug', '-', Year (l.frame_date)) WHEN 9 THEN CONCAT('Sep', '-', Year (l.frame_date)) WHEN 10 THEN CONCAT('Oct', '-', Year (l.frame_date)) WHEN 11 THEN CONCAT('Nov', '-', Year (l.frame_date)) WHEN 12 THEN CONCAT('Dec', '-', Year (l.frame_date)) ELSE 'Unknown' END as 'month', null as slab, null as drywall, COUNT(IF(l.frame_date is not null, 1, 0)) AS frame, null AS dried_in, CONCAT(Year (l.frame_date),LPAD(MONTH (l.frame_date),2,0)) year_month_number FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = $contract_type_id ) AND l.$active_column=1 AND l.lot_type_id <> 1 and l.frame_date is not null and (frame_date <= CURDATE() and frame_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by MONTH (l.frame_date) ORDER BY MONTH (l.frame_date) ASC) UNION ALL (SELECT CASE MONTH (l.drywall_date) WHEN 1 THEN CONCAT('Jan','-',Year (l.drywall_date)) WHEN 2 THEN CONCAT('Feb', '-', Year (l.drywall_date)) WHEN 3 THEN CONCAT('Mar','-',Year (l.drywall_date)) WHEN 4 THEN CONCAT('Apr', '-', Year (l.drywall_date)) WHEN 5 THEN CONCAT('May', '-', Year (l.drywall_date)) WHEN 6 THEN CONCAT('Jun', '-', Year (l.drywall_date)) WHEN 7 THEN CONCAT('Jul', '-', Year (l.drywall_date)) WHEN 8 THEN CONCAT('Aug', '-', Year (l.drywall_date)) WHEN 9 THEN CONCAT('Sep', '-', Year (l.drywall_date)) WHEN 10 THEN CONCAT('Oct', '-', Year (l.drywall_date)) WHEN 11 THEN CONCAT('Nov', '-', Year (l.drywall_date)) WHEN 12 THEN CONCAT('Dec', '-', Year (l.drywall_date)) ELSE 'Unknown' END as 'month', null as slab, COUNT(IF(l.drywall_date is not null, 1, 0)) AS drywall, null as frame, null AS dried_in, CONCAT(Year (l.drywall_date),LPAD(MONTH (l.drywall_date),2,0)) year_month_number FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = $contract_type_id ) AND l.$active_column=1 AND l.lot_type_id <> 1 and l.drywall_date is not null and (drywall_date <= CURDATE() and drywall_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by MONTH (l.drywall_date) ORDER BY MONTH (l.drywall_date) ASC) UNION ALL (SELECT CASE MONTH (l.slab_date) WHEN 1 THEN CONCAT('Jan','-',Year (l.slab_date)) WHEN 2 THEN CONCAT('Feb', '-', Year (l.slab_date)) WHEN 3 THEN CONCAT('Mar','-',Year (l.slab_date)) WHEN 4 THEN CONCAT('Apr', '-', Year (l.slab_date)) WHEN 5 THEN CONCAT('May', '-', Year (l.slab_date)) WHEN 6 THEN CONCAT('Jun', '-', Year (l.slab_date)) WHEN 7 THEN CONCAT('Jul', '-', Year (l.slab_date)) WHEN 8 THEN CONCAT('Aug', '-', Year (l.slab_date)) WHEN 9 THEN CONCAT('Sep', '-', Year (l.slab_date)) WHEN 10 THEN CONCAT('Oct', '-', Year (l.slab_date)) WHEN 11 THEN CONCAT('Nov', '-', Year (l.slab_date)) WHEN 12 THEN CONCAT('Dec', '-', Year (l.slab_date)) ELSE 'Unknown' END as 'month', COUNT(IF(l.slab_date is not null, 1, 0)) AS slab, null as drywall, null as frame, null AS dried_in, CONCAT(Year (l.slab_date),LPAD(MONTH (l.slab_date),2,0)) year_month_number FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = $contract_type_id ) AND l.$active_column=1 AND l.lot_type_id <> 1 and l.slab_date is not null and (slab_date <= CURDATE() and slab_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by MONTH (l.slab_date) ORDER BY MONTH (l.slab_date) ASC) UNION ALL (SELECT CASE MONTH (l.dried_in_date) WHEN 1 THEN CONCAT('Jan', '-', Year (l.dried_in_date)) WHEN 2 THEN CONCAT('Feb', '-', Year (l.dried_in_date)) WHEN 3 THEN CONCAT('Mar', '-', Year (l.dried_in_date)) WHEN 4 THEN CONCAT('Apr', '-', Year (l.dried_in_date)) WHEN 5 THEN CONCAT('May', '-', Year (l.dried_in_date)) WHEN 6 THEN CONCAT('Jun', '-', Year (l.dried_in_date)) WHEN 7 THEN CONCAT('Jul', '-', Year (l.dried_in_date)) WHEN 8 THEN CONCAT('Aug', '-', Year (l.dried_in_date)) WHEN 9 THEN CONCAT('Sep', '-', Year (l.dried_in_date)) WHEN 10 THEN CONCAT('Oct', '-', Year (l.dried_in_date)) WHEN 11 THEN CONCAT('Nov', '-', Year (l.dried_in_date)) WHEN 12 THEN CONCAT('Dec', '-', Year (l.dried_in_date)) ELSE 'Unknown' END as 'month', null AS slab, null as drywall, null as frame, Count(IF(l.dried_in_date is not null, 1 , 0)) AS dried_in, CONCAT(Year (l.dried_in_date), LPAD(MONTH (l.dried_in_date),2,0)) year_month_number FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = $contract_type_id ) AND l.$active_column=1 AND l.lot_type_id <> 1 and dried_in_date is not null and (dried_in_date <= CURDATE() and dried_in_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by MONTH (l.dried_in_date) ORDER BY MONTH (l.dried_in_date) asc) ) as C GROUP BY C.month ORDER BY C.year_month_number asc"; echo $sql; $stmt = $pdo->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(); $data[] = array( 'month', 'slab', 'dried_in', 'frame', 'drywall' ); foreach ($result as $row) { $data[] = array( $row['month'], (int) $row['slab'], (int) $row['dried_in'], (int) $row['frame'], (int) $row['drywall'] ); } $encoded_data= json_encode($data); ?> <!-- Load Google JSAPI --> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1", { packages: ["corechart"] }); google.setOnLoadCallback(drawChart); // draw chart fucntion function drawChart() { /* var jsonData = $.ajax({ url: "./includes/chart_12month_comparison_data.php", dataType: "json", async: false }).responseText; var obj = jQuery.parseJSON(jsonData); */ var data = google.visualization.arrayToDataTable(<?php echo $encoded_data;?>); var currentYear = new Date(); var options = { //title: 'Demo Google LineChart : ' + (new Date(currentYear.setDate(currentYear.getDate() - 365))).yyyymmdd() + ' - ' + (new Date()).yyyymmdd() title: '12 Month Comparison ' + (new Date(currentYear.getFullYear()-1,currentYear.getMonth()+1)).yyyymmdd() + ' - ' + (new Date()).yyyymmdd(), //legend: 'none', hAxis: { minValue: 0, maxValue: 9 }, pointSize: 10, pointShape: 'square' }; var chart = new google.visualization.LineChart( document.getElementById('chart_div')); chart.draw(data, options); } // format date function Date.prototype.yyyymmdd = function() { var yyyy = this.getFullYear().toString(); var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based var dd = this.getDate().toString(); return yyyy + "/" + (mm[1]?mm:"0"+mm[0]) + "/" + (dd[1]?dd:"0"+dd[0]); // padding }; </script> <?php $floor = isset($_GET['floor']) || !isset($_GET['specialty']) ? "style=\"color:#FF0000\"" : ''; $specialty = isset($_GET['specialty']) ? "style=\"color:#FF0000\"" : ''; ?> FILTER: <a href="<?php echo $_SERVER['SCRIPT_NAME'];?>?p=<?php echo $_GET['p'];?>&floor" title="Flooring" <?php echo $floor;?>>Flooring</a> | <a href="<?php echo $_SERVER['SCRIPT_NAME'];?>?p=<?php echo $_GET['p'];?>&specialty" title="Specialty" <?php echo $specialty;?>>Specialty</a><br><br> <div id="chart_div" style="width: 900px; height: 500px;"> </div>
  2. Here is what i need. I have a form with a bunch of text boxes and check box's that i need to submit to mysql database. I know how to submit the text boxes just fine with the insert statment. I have not used check boxes and i need some help on how to insert them into the database. I need them to be enterened in as a 0 or 1. Here is the form <form action="submit.php" method="post"> <table width="1000" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="1400" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="6%" height="168"> </td> <td width="87%"> </td> <td width="7%"> </td> </tr> <tr> <td height="37"> </td> <td><table width="100%" height="37" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="32%" valign="bottom"><input name="water-purveyor" type="text" id="water-purveyor" size="35" /></td> <td width="29%" valign="bottom"><input name="meter-num" type="text" id="meter-num" size="10" /></td> <td width="39%" valign="bottom"><input type="text" name="permit-num" id="permit-num" /></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="42"> </td> <td><table width="100%" height="37" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="32%" valign="bottom"> <input name="manufacturer" type="text" id="manufacturer" size="20" /></td> <td width="15%" valign="bottom"><input name="meter-size" type="text" id="meter-size" size="10" /></td> <td width="15%" valign="bottom"><input name="model-num" type="text" id="model-num" size="10" /></td> <td width="38%" valign="bottom"><input name="serial-num" type="text" id="serial-num" size="18" /></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="62"> </td> <td valign="bottom"><table width="100%" height="56" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="61%" valign="bottom"><textarea name="mgmt-info" cols="50" rows="1" id="mgmt-info"></textarea></td> <td width="39%" valign="bottom"><textarea name="mgmt-phone-contact" cols="30" rows="1" id="mgmt-phone-contact"></textarea></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="63"> </td> <td><table width="100%" height="57" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="61%" valign="bottom"><textarea name="owner-info" cols="50" rows="1" id="owner-info"></textarea></td> <td width="39%" valign="bottom"><textarea name="owner-phone-contact" cols="30" rows="1" id="owner-phone-contact"></textarea></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="37"> </td> <td><table width="100%" height="37" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="32%" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="3%"> </td> <td width="21%"><input type="checkbox" name="sab-owner" id="sab-owner" /></td> <td width="44%"><input type="checkbox" name="sab-management" id="sab-management" /></td> <td width="32%"><input type="checkbox" name="sab-other" id="sab-other" /></td> </tr> </table></td> <td width="29%" valign="bottom"><input name="auth-contact" type="text" id="auth-contact" size="20" /></td> <td width="39%" valign="bottom"><input name="auth-phone" type="text" id="auth-phone" size="15" /></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="65"> </td> <td><table width="100%" height="56" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="32%" valign="bottom"><textarea name="bf-assembly-address" cols="30" rows="1" id="bf-assembly-address"></textarea></td> <td width="29%" valign="bottom"><textarea name="onsite-location" cols="20" rows="1" id="onsite-location"></textarea></td> <td width="39%" valign="bottom"><textarea name="primary-business" cols="20" rows="1" id="primary-business"></textarea></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="63"> </td> <td><table width="100%" height="56" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="32%" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="62" height="8"> </td> <td width="214" height="8"><input type="checkbox" name="new-assembly-yes" id="new-assembly-yes" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="new-assembly-no" id="new-assembly-no" /></td> </tr> </table></td> <td width="29%" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="24%" height="8"> </td> <td width="76%" height="8"><input type="checkbox" name="replacement-assembly-yes" id="replacement-assembly-yes" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="replacement-assembly-no" id="replacement-assembly-no" /></td> </tr> </table></td> <td width="39%"><input type="text" name="new-serial-num" id="new-serial-num" /></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="42"> </td> <td><table width="100%" height="42" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="7%"> </td> <td width="24%"><div style="padding-top:8px; padding-left:4px;"><input type="checkbox" name="poa-secondary" id="poa-secondary" /></div></td> <td width="21%"><div style="padding-top:8px"><input type="checkbox" name="poa-primary" id="poa-primary" /></div></td> <td width="14%"><div style="padding-top:8px"><input type="checkbox" name="poa-fire-system" id="poa-fire-system" /></div></td> <td width="14%"><div style="padding-top:8px; padding-left:4px;"><input type="checkbox" name="poa-landscape" id="poa-landscape" /></div></td> <td width="20%"><div style="padding-top:8px; padding-left:4px;"><input type="checkbox" name="poa-portable" id="poa-portable" /></div></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="64"> </td> <td><table width="100%" height="58" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="33%" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="6%"> </td> <td width="3%"> </td> <td width="26%"><input type="checkbox" name="svb" id="svb" /></td> <td width="23%"><input type="checkbox" name="pvb" id="pvb" /></td> <td width="21%"><input type="checkbox" name="dc" id="dc" /></td> <td width="21%"><input type="checkbox" name="rp" id="rp" /></td> </tr> <tr> <td> </td> <td valign="bottom"> </td> <td colspan="4"><div style="padding-left:20px;"><input name="toa-other-text" type="text" id="toa-other-text" size="30" /></div></td> </tr> </table></td> <td width="35%"> <input type="text" name="line-pressure" id="line-pressure" /></td> <td width="32%"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="19%"> </td> <td width="34%"><input type="checkbox" name="bp-yes" id="bp-yes" /></td> <td width="47%"><input type="checkbox" name="bp-no" id="bp-no" /></td> </tr> </table></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="64"> </td> <td><table width="100%" height="63" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="83%"> </td> <td width="17%" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="32" colspan="5" valign="bottom" align="center"><input name="pvb-aioa-psid" type="text" id="pvb-aioa-psid" size="8" /></td> </tr> <tr> <td width="18%" height="25"> </td> <td width="28%"> </td> <td width="26%"><input type="checkbox" name="pvb-leaked-yes" id="pvb-leaked-yes" /></td> <td width="28%" colspan="2"><input type="checkbox" name="pvb-leaked-no" id="pvb-leaked-no" /></td> </tr> </table></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="56"> </td> <td><table width="100%" height="56" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="18%"> </td> <td width="22%" valign="top"><table width="100%" height="54" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="5%" height="6"> </td> <td width="49%"> </td> <td width="18%"><input type="checkbox" name="cv1-ct-yes" id="cv1-ct-yes" /></td> <td width="28%"><input type="checkbox" name="cv1-ct-no" id="cv1-ct-no" /></td> </tr> <tr> <td height="6"> </td> <td colspan="2" align="center"><input type="text" name="cv1-psid" id="cv1-psid" size="6" /></td> <td> </td> </tr> <tr> <td height="6"> </td> <td> </td> <td valign="top"><input type="checkbox" name="cv1-leaked-yes" id="cv1-leaked-yes" /></td> <td valign="top"><input type="checkbox" name="cv1-leaked-no" id="cv1-leaked-no" /></td> </tr> </table></td> <td width="22%"><table width="100%" height="54" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="5%" height="6"> </td> <td width="49%"> </td> <td width="19%"><input type="checkbox" name="cv2-ct-yes" id="cv2-ct-yes" style="background-color:transparent;" /></td> <td width="27%"><input type="checkbox" name="cv2-ct-no" id="cv2-ct-no" /></td> </tr> <tr> <td height="6"> </td> <td colspan="2" align="center"><input type="text" name="cv2-psid" id="cv2-psid" size="6" /></td> <td> </td> </tr> <tr> <td height="6"> </td> <td> </td> <td valign="top"><input type="checkbox" name="cv2-leaked-yes" id="cv2-leaked-yes" /></td> <td valign="top"><input type="checkbox" name="cv2-leaked-no" id="cv2-leaked-no" /></td> </tr> </table></td> <td width="20%" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="30" colspan="2" align="center"><input type="text" name="dprv-psid" id="dprv-psid" size="8" /></td> <td width="6%"> </td> <td width="21%"> </td> </tr> <tr> <td width="54%"> </td> <td width="19%"><input type="checkbox" name="dprv-dno-yes" id="dprv-dno-yes" /></td> <td> </td> <td><input type="checkbox" name="dprv-dno-No" id="dprv-dno-No" /></td> </tr> </table></td> <td width="18%" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="32" colspan="5" valign="bottom" align="center"><input name="pvb-cvha-psid" type="text" id="pvb-cvha-psid" size="8" /></td> </tr> <tr> <td width="20%" height="25"> </td> <td width="20%"> </td> <td width="9%"> </td> <td width="24%"><input type="checkbox" name="pvb-cvha-leaked-yes" id="pvb-cvha-leaked-yes" /></td> <td width="27%"><input type="checkbox" name="pvb-cvha-leaked-no" id="pvb-cvha-leaked-no" /></td> </tr> </table></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="145"> </td> <td><table width="100%" height="143" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="18%" height="129"> </td> <td width="22%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="54%"> </td> <td width="18%"><input type="checkbox" name="cv1-cleaned-yes" id="cv1-cleaned-yes" /></td> <td width="28%"><input type="checkbox" name="cv1-cleaned-no" id="cv1-cleaned-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="cv1-replaced-yes" id="cv1-replaced-yes" /></td> <td><input type="checkbox" name="cv1-replaced-no" id="cv1-replaced-no" /></td> </tr> <tr> <td height="40"> </td> <td valign="bottom"><input type="checkbox" name="cv1-rkd-yes" id="cv1-rkd-yes" /></td> <td valign="bottom"><input type="checkbox" name="cv1-rkd-no" id="cv1-rkd-no" /></td> </tr> <tr> <td height="22"> </td> <td><input type="checkbox" name="cv1-springs-yes" id="cv1-springs-yes" /></td> <td><input type="checkbox" name="cv1-springs-no" id="cv1-springs-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="cv1-guide-yes" id="cv1-guide-yes" /></td> <td><input type="checkbox" name="cv1-guide-no" id="cv1-guide-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="cv1-other-yes" id="cv1-other-yes" /></td> <td><input type="checkbox" name="cv1-other-no" id="cv1-other-no" /></td> </tr> </table></td> <td width="22%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="51%" height="22"> </td> <td width="21%"><input type="checkbox" name="cv2-cleaned-yes" id="cv2-cleaned-yes" /></td> <td width="28%"><input type="checkbox" name="cv2-cleaned-no" id="cv2-cleaned-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="cv2-replaced-yes" id="cv2-replaced-yes" /></td> <td><input type="checkbox" name="cv2-replaced-no" id="cv2-replaced-no" /></td> </tr> <tr> <td height="40"> </td> <td valign="bottom"><input type="checkbox" name="cv2-rkd-yes" id="cv2-rkd-yes" /></td> <td valign="bottom"><input type="checkbox" name="cv2-rkd-no" id="cv2-rkd-no" /></td> </tr> <tr> <td height="22"> </td> <td><input type="checkbox" name="cv2-springs-yes" id="cv2-springs-yes" /></td> <td><input type="checkbox" name="cv2-springs-no" id="cv2-springs-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="cv2-guide-yes" id="cv2-guide-yes" /></td> <td><input type="checkbox" name="cv2-guide-no" id="cv2-guide-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="cv2-other-yes" id="cv2-other-yes" /></td> <td><input type="checkbox" name="cv2-other-no" id="cv2-other-no" /></td> </tr> </table></td> <td width="20%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="56%" height="22"> </td> <td width="22%"><input type="checkbox" name="dprv-cleaned-yes" id="dprv-cleaned-yes" /></td> <td width="22%"><input type="checkbox" name="dprv-cleaned-no" id="dprv-cleaned-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="dprv-replaced-yes" id="dprv-replaced-yes" /></td> <td><input type="checkbox" name="dprv-replaced-no" id="dprv-replaced-no" /></td> </tr> <tr> <td height="40"> </td> <td valign="bottom"><input type="checkbox" name="dprv-rkd-yes" id="dprv-rkd-yes" /></td> <td valign="bottom"><input type="checkbox" name="dprv-rkd-no" id="dprv-rkd-no" /></td> </tr> <tr> <td height="22"> </td> <td><input type="checkbox" name="dprv-springs-yes" id="dprv-springs-yes" /></td> <td><input type="checkbox" name="dprv-springs-no" id="dprv-springs-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="dprv-guide-yes" id="dprv-guide-yes" /></td> <td><input type="checkbox" name="dprv-guide-no" id="dprv-guide-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="dprv-other-yes" id="dprv-other-yes" /></td> <td><input type="checkbox" name="dprv-other-no" id="dprv-other-no" /></td> </tr> </table></td> <td width="18%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="48%" height="22"> </td> <td width="28%"><input type="checkbox" name="pvb-cleaned-yes" id="pvb-cleaned-yes" /></td> <td width="24%"><input type="checkbox" name="pvb-cleaned-no" id="pvb-cleaned-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="pvb-replaced-yes" id="pvb-replaced-yes" /></td> <td><input type="checkbox" name="pvb-replaced-no" id="pvb-replaced-no" /></td> </tr> <tr> <td height="40"> </td> <td valign="bottom"><input type="checkbox" name="pvb-rkd-yes" id="pvb-rkd-yes" /></td> <td valign="bottom"><input type="checkbox" name="pvb-rkd-no" id="pvb-rkd-no" /></td> </tr> <tr> <td height="22"> </td> <td><input type="checkbox" name="pvb-springs-yes" id="pvb-springs-yes" /></td> <td><input type="checkbox" name="pvb-springs-no" id="pvb-springs-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="pvb-guide-yes" id="pvb-guide-yes" /></td> <td><input type="checkbox" name="pvb-guide-no" id="pvb-guide-no" /></td> </tr> <tr> <td> </td> <td><input type="checkbox" name="pvb-other-yes" id="pvb-other-yes" /></td> <td><input type="checkbox" name="pvb-other-no" id="pvb-other-no" /></td> </tr> </table></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="29"> </td> <td><table width="100%" height="29" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="18%"> </td> <td width="82%"><table width="100%" height="29" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="29%"> </td> <td width="19%" valign="top"><input name="valve-num" type="text" id="valve-num" size="12" style="height:14px;" /></td> <td width="14%"> <input type="checkbox" name="repaired" id="repaired" /> </td> <td width="15%"> <input type="checkbox" name="replaced" id="replaced" /> </td> <td width="23%"> <input type="checkbox" name="both-ok" id="both-ok" /> </td> </tr> </table></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="62"> </td> <td><table width="100%" height="60" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="18%"> </td> <td width="22%" valign="top"><table width="100%" height="41" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="25%" height="19"> </td> <td width="29%"> </td> <td width="20%"><input type="checkbox" name="ft-cv1-ct-yes" id="ft-cv1-ct-yes" /></td> <td width="26%"><input type="checkbox" name="ft-cv1-ct-no" id="ft-cv1-ct-no" /></td> </tr> <tr> <td colspan="3" align="center"><input name="ft-cv1-psid" type="text" id="ft-cv1-psid" size="8" /></td> <td> </td> </tr> </table></td> <td width="22%" valign="top"><table width="100%" height="41" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="25%" height="19"> </td> <td width="25%"> </td> <td width="24%" valign="top"><div style="padding-left:4px;"><input type="checkbox" name="ft-cv2-ct-yes" id="ft-cv2-ct-yes" /></div></td> <td width="26%"><input type="checkbox" name="ft-cv-ct-no" id="ft-cv2-ct-no" /></td> </tr> <tr> <td colspan="3" align="center"><input type="text" name="ft-cv2-psid" id="ft-cv2-psid" size="8" /></td> <td> </td> </tr> </table></td> <td width="20%" align="center"><input name="ft-dprv-psid" type="text" id="ft-dprv-psid" size="8" /></td> <td width="18%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="36%" height="22"> </td> <td colspan="2" align="center"><input name="ft-ai-psid" type="text" id="ft-ai-psid" size="4" /></td> <td width="3%"> </td> <td width="20%"> </td> </tr> <tr> <td height="25"> </td> <td width="14%"> </td> <td colspan="2" align="center"><input name="ft-cv-psid" type="text" id="ft-cv-psid" size="3" /></td> <td> </td> </tr> </table></td> </tr> </table></td> <td> </td> </tr> <tr> <td colspan="3" height="32"></td> </tr> <tr> <td height="54"> </td> <td valign="bottom"><table width="100%" height="" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="49%" rowspan="2" valign="bottom"><textarea name="tc-info" cols="45" rows="1" id="tc-info"></textarea></td> <td width="51%" rowspan="2" valign="bottom"><textarea name="tc-info2" cols="40" rows="1" id="tc-info2"></textarea></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="37"> </td> <td valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-bottom:4px;"> <tr> <td width="23%"><input name="itb" type="text" id="itb" size="20" /></td> <td width="26%"><input name="certified-tester-num2" type="text" id="certified-tester-num2" size="15" /></td> <td width="26%"><input name="date-failed" type="text" id="date-failed" size="15" /></td> <td width="25%"><input name="tk-serial-num" type="text" id="tk-serial-num" size="20" /></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="39"> </td> <td valign="bottom"><table width="100%" height="33" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="23%"> </td> <td width="52%"> </td> <td width="25%"> </td> </tr> </table></td> <td> </td> </tr> <tr> <td height="38"> </td> <td valign="bottom"><table width="100%" height="32" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="23%"><input name="ftb" type="text" id="ftb" size="20" /></td> <td width="26%"><input name="ftb-certified-tester-num" type="text" id="ftb-certified-tester-num" size="20" /></td> <td width="26%"><input name="date-passed" type="text" id="date-passed" size="15" /></td> <td width="25%"><input name="ftb-tk-serial-num" type="text" id="ftb-tk-serial-num" size="20" /></td> </tr> </table></td> <td> </td> </tr> <tr> <td height="123"> </td> <td><textarea name="comments" id="comments" cols="105" rows="3"></textarea></td> <td> </td> </tr> </table></td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> </table> </form> Here is just a sample of the insert code that i have: <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; $table = "sysform"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $water-purveyor = $_POST['water-purveyor']; $meter-num = $_POST['meter-num']; $permit-num = $_POST['permit-num']; $svb = $_POST['svb']; $pvb = $_POST['pvb']; $dc = $_POST['dc']; $rp = $_POST['rp']; $sql = "INSERT INTO $table ('water-purveyor', 'meter-num', 'permit-num','...', 'svb', 'pvb', 'dc', 'rp') VALUES ('$water-purveyor', '$meter-num', '$permit-num','$...', '$svb', '$pvb', '$dc', '$rp')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?> Can anyone help me on how to under stand how to sumbit the check box's to where i have a 1 or 0. Also i need to use the get function to pull the data back to the form. Here is the statment i have for that just as an example: <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; $table = "sysform"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $water-purveyor = $_POST['water-purveyor']; $meter-num = $_POST['meter-num']; $permit-num = $_POST['permit-num']; $svb = $_POST['svb']; $pvb = $_POST['pvb']; $dc = $_POST['dc']; $rp = $_POST['rp']; $sql="SELECT * from $table where sequence = '".$_GET["sequence"]."' "; $rs=mysql_query($sql,$conn) or die(mysql_error()); $result=mysql_fetch_array($rs); ?> <form action="" method="get"> <table width="1000" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="1400" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="6%" height="168"> </td> <td width="87%"> </td> <td width="7%"> </td> </tr> <tr> <td height="37"> </td> <td><table width="100%" height="37" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="32%" valign="bottom"><input name="water-purveyor" type="text" id="water-purveyor" size="35" value="<?php echo '$water-purveyor'?>" /></td> <td width="29%" valign="bottom"><input name="meter-num" type="text" id="meter-num" size="10" value="<?php echo '$meter-num'?>" /></td> <td width="39%" valign="bottom"><input type="text" name="permit-num" id="permit-num" value="<?php echo '$permit-num'?>" /></td> </tr> </table> </form>
  3. When I first started this project, PHP was new to me and I didn't have a clue how to use it. Here, seven months later, I still don't know what I'm doing. I have 47 pages that are MySQL intensive. Each client has their own login credentials to the database. I've been using the $_SESSION global to carry these credentials across the pages. I realize this is a huge security issue, but I don't know any other way to keep their username / password handy as they log in and out of the database. I've searched and not found anything resembling my need here. Most of the discussions relate to setting $_SESSION['foo'] = 'bar' and carying that from page to page. I cld really use some insight on this. Thanks.
  4. Hi everyone, I'm sure you have seen me around in here by learning PHP, I am getting advance now. But I don't understand why it won't insert in PHPmyadmin (MySQL) with my prompt in php. Can you find why it won't add name as insert into my database? if ($_POST['submmited']) { $first = $_POST['firstname']; $last = $_POST['lastname']; $email = $_POST['email']; if ($first && $last && $email) { $sql = "INSERT INTO Student (StudentID,Firstname,LastName,Email) VALUES (NULL,'$first','$last','$email')"; mysqli_query($Garydb, $sql); } else { echo "Failed to add register"; } } I checked around, there is no mistake but it won't add a new as insert into my database...why? What Did I do wrong? Thank you in advance Gary
  5. Hi all, I am a real newbie with PHP and mysql. I am trying to create a thumbnail carousel to present all the web applications we have in house.I am using some code from this demo because it does close to everything I need. The problem is that it displays only one image per slide and I would like to display multiple items per slide instead. Is it possible with a foreach loop for example? Code: <?php include_once('db.php'); $query = "select * from images order by id desc limit 6"; $res = mysqli_query($connection,$query); $count = mysqli_num_rows($res); $slides=''; $Indicators=''; $counter=0; while($row=mysqli_fetch_array($res)) { $title = $row['title']; $desc = $row['desc']; $image = $row['image']; if($counter == 0) { $Indicators .='<li data-target="#carousel-example-generic" data-slide-to="'.$counter.'" class="active"></li>'; $slides .= '<div class="item active"> <img src="images/'.$image.'" alt="'.$title.'" /> <div class="carousel-caption"> <h3>'.$title.'</h3> <p>'.$desc.'.</p> </div> </div>'; } else { $Indicators .='<li data-target="#carousel-example-generic" data-slide-to="'.$counter.'"></li>'; $slides .= '<div class="item"> <img src="images/'.$image.'" alt="'.$title.'" /> <div class="carousel-caption"> <h3>'.$title.'</h3> <p>'.$desc.'.</p> </div> </div>'; } $counter++; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Dynamic image slider using twitter bootstrap & PHP with MySQL | PGPGang.com</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <style type="text/css"> img {border-width: 0} * {font-family:'Lucida Grande', sans-serif;} </style> </head> <body onload="changePagination('0','first')"> <h2>Dynamic image slider using twitter bootstrap & PHP with MySQL Example. => <a href="http://www.phpgang.com/">Home</a> | <a href="http://demo.phpgang.com/">More Demos</a></h2> <link rel="stylesheet" href="css/bootstrap.min.css" /> <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script> <script src="js/bootstrap.min.js"></script> <style> .carousel-caption { background-image: url("http://www.phpgang.com/wp-content/themes/PHPGang_v2/img/bg_sidebar.png"); } .carousel-inner>.item>img, .carousel-inner>.item>a>img { height:400px; width:700px; } </style> <div class="container" style="width: 730px;"> <h2>Dynamic Image Slider</h2><span style="float: right;margin-top: -30px;"><a href="addnew.php">Add More Images</a></span> <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <?php echo $Indicators; ?> </ol> <!-- Wrapper for slides --> <div class="carousel-inner" role="listbox"> <?php echo $slides; ?> </div> <!-- Controls --> <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a class="right carousel-control" href="#carousel-example-generic" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span> </a> </div> </div> </body> </html> Thanks, Alex
  6. Hi, Just wondering if someone could point me in the right direction, I have a simple PHP MySQL login script which passes/stores data via sessions. It works fine, there is no problem with it. All I would like to do is pass some additional data from the users MySQL table. Currently it users just username and password, but I would like it to pass firstname and surname data as well. So when a user logs in with their username and password, on the next page it might say Welcome, Michael Smith. The script below is originally setup for the username to be a persons name, as it's used in the login welcome message in the login.php But I might change the username to be an email address, if I can pull in the additional data. config.php <?php /***************************** File: includes/config.php Written by: Frost of Slunked.com Tutorial: User Registration and Login System ******************************/ // start the session before any output. session_start(); // Set the folder for our includes $sFolder = '/predictor/login'; /*************** Database Connection You will need to change the user (user) and password (password) to what your database information uses. Same with the database name if you used something else. ****************/ mysql_connect('localhost', 'root', '') or trigger_error("Unable to connect to the database: " . mysql_error()); mysql_select_db('football') or trigger_error("Unable to switch to the database: " . mysql_error()); /*************** password salts are used to ensure a secure password hash and make your passwords much harder to be broken into Change these to be whatever you want, just try and limit them to 10-20 characters each to avoid collisions. ****************/ define('SALT1', '24859f@#$#@$'); define('SALT2', '^&@#_-=+Afda$#%'); // require the function file require_once($_SERVER['DOCUMENT_ROOT'] . $sFolder . '/includes/functions.php'); // default the error variable to empty. $_SESSION['error'] = ""; // declare $sOutput so we do not have to do this on each page. $sOutput=""; ?> login.php <?php /***************************** File: login.php Written by: Frost of Slunked.com Tutorial: User Registration and Login System ******************************/ require($_SERVER['DOCUMENT_ROOT'] . '/predictor/login/includes/config.php'); // If the user is logging in or out // then lets execute the proper functions if (isset($_GET['action'])) { switch (strtolower($_GET['action'])) { case 'login': if (isset($_POST['username']) && isset($_POST['password'])) { // We have both variables. Pass them to our validation function if (!validateUser($_POST['username'], $_POST['password'])) { // Well there was an error. Set the message and unset // the action so the normal form appears. $_SESSION['error'] = "Bad username or password supplied."; unset($_GET['action']); } }else { $_SESSION['error'] = "Username and Password are required to login."; unset($_GET['action']); } break; case 'logout': // If they are logged in log them out. // If they are not logged in, well nothing needs to be done. if (loggedIn()) { logoutUser(); $sOutput .= '<h1>Logged out!</h1><br />You have been logged out successfully. <br /><h4>Would you like to go to <a href="index.php">site index</a>?</h4>'; }else { // unset the action to display the login form. unset($_GET['action']); } break; } } $sOutput .= '<div id="index-body">'; // See if the user is logged in. If they are greet them // and provide them with a means to logout. if (loggedIn()) { $sOutput .= '<h1>Logged In!</h1><br /><br /> Hello, ' . $_SESSION["username"] . ' how are you today?<br /><br /> <h4>Would you like to <a href="login.php?action=logout">logout</a>?</h4> <h4>Would you like to go to <a href="index.php">site index</a>?</h4>'; }elseif (!isset($_GET['action'])) { // incase there was an error // see if we have a previous username $sUsername = ""; if (isset($_POST['username'])) { $sUsername = $_POST['username']; } $sError = ""; if (isset($_SESSION['error'])) { $sError = '<span id="error">' . $_SESSION['error'] . '</span><br />'; } $sOutput .= '<h2>Login to our site</h2><br /> <div id="login-form"> ' . $sError . ' <form name="login" method="post" action="login.php?action=login"> Username: <input type="text" name="username" value="' . $sUsername . '" /><br /> Password: <input type="password" name="password" value="" /><br /><br /> <input type="submit" name="submit" value="Login!" /> </form> </div> <h4>Would you like to <a href="login.php">login</a>?</h4> <h4>Create a new <a href="register.php">account</a>?</h4>'; } $sOutput .= '</div>'; // lets display our output string. echo $sOutput; ?> functions.php <?php /***************************** File: includes/functions.php Written by: Frost of Slunked.com Tutorial: User Registration and Login System ******************************/ /*********** bool createAccount (string $pUsername, string $pPassword) Attempt to create an account for the passed in username and password. ************/ function createAccount($pUsername, $pPassword, $pFirstname, $pSurname) { // First check we have data passed in. if (!empty($pUsername) && !empty($pPassword) && !empty($pFirstname) && !empty($pSurname)) { $uLen = strlen($pUsername); $pLen = strlen($pPassword); $fLen = strlen($pFirstname); $sLen = strlen($pSurname); // escape the $pUsername to avoid SQL Injections $eUsername = mysql_real_escape_string($pUsername); $sql = "SELECT username FROM users WHERE username = '" . $eUsername . "' LIMIT 1"; // Note the use of trigger_error instead of or die. $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // Error checks (Should be explained with the error) if ($uLen <= 4 || $uLen >= 11) { $_SESSION['error'] = "Username must be between 4 and 11 characters."; }elseif ($pLen < 6) { $_SESSION['error'] = "Password must be longer then 6 characters."; }elseif (mysql_num_rows($query) == 1) { $_SESSION['error'] = "Username already exists."; }else { // All errors passed lets // Create our insert SQL by hashing the password and using the escaped Username. $sql = "INSERT INTO users (`username`, `password`, `firstname`, `surname`) VALUES ('" . $eUsername . "', '" . hashPassword($pPassword, SALT1, SALT2) . "', '" . $pFirstname . "', '" . $pSurname . "');"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); $sql2 = "INSERT INTO predictions (userID, predictionID, week) SELECT LAST_INSERT_ID(), id, week FROM fixtures"; $query = mysql_query($sql2) or trigger_error("Query Failed: " . mysql_error()); if ($query) { return true; } } } return false; } /*********** string hashPassword (string $pPassword, string $pSalt1, string $pSalt2) This will create a SHA1 hash of the password using 2 salts that the user specifies. ************/ function hashPassword($pPassword, $pSalt1="2345#$%@3e", $pSalt2="taesa%#@2%^#") { return sha1(md5($pSalt2 . $pPassword . $pSalt1)); } /*********** bool loggedIn verifies that session data is in tack and the user is valid for this session. ************/ function loggedIn() { // check both loggedin and username to verify user. if (isset($_SESSION['loggedin']) && isset($_SESSION['userID']) && isset($_SESSION['username'])) { return true; } return false; } /*********** bool logoutUser Log out a user by unsetting the session variable. ************/ function logoutUser() { // using unset will remove the variable // and thus logging off the user. unset($_SESSION['username']); unset($_SESSION['userID']); unset($_SESSION['loggedin']); return true; } /*********** bool validateUser Attempt to verify that a username / password combination are valid. If they are it will set cookies and session data then return true. If they are not valid it simply returns false. ************/ function validateUser($pUsername, $pPassword) { // See if the username and password are valid. $sql = "SELECT * FROM users WHERE username = '" . mysql_real_escape_string($pUsername) . "' AND password = '" . hashPassword($pPassword, SALT1, SALT2) . "' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // If one row was returned, the user was logged in! if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $_SESSION['username'] = $row['username']; $_SESSION['userID'] = $row['userID']; $_SESSION['password'] = $row['password']; $_SESSION['loggedin'] = true; return true; } return false; } ?> USERS TABLE ID username password firstname surname 1 rich 12345 Richard Branson 2 alan 67898 Lord Sugar
  7. <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <div id="txtHint"></div> <script> function showUser(str) { // alert (str); if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "new.php?q=" + str, true); xmlhttp.send(); } } </script> <body> <form> <select onchange="showUser(this.value)"> <option value="1" > 1 </option> <option value="3" > 3 </option> </select> <?php $con = mysqli_connect("localhost", "root", ""); mysqli_select_db($con, "crud_tutorial"); if (isset($_REQUEST['q'])) { $q = intval($_GET['q']); //echo "$q"; $sql = "SELECT * FROM customers WHERE id = '" . $q . "'"; $result = mysqli_query($con, $sql); } else { $sql = "SELECT * FROM customers "; $result = mysqli_query($con, $sql); } echo "<table> <tr> <th>id</th> <th>name</th> </tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?> </form> </body> </html>
  8. I want to create a drop down menu that display main categories then all child categories with all of their sub child list like the one shown in below pic I am using a table named categories which uses hierarchical system like parent id, right id, left id and level looks like in below pic here is my categoriesTest.php <?php include 'common.php'; $query = "SELECT cat_id, parent_id, cat_name FROM " .$DBPrefix. "categories ORDER BY cat_name"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $items = mysql_fetch_assoc($res); $html = ''; $parent = 0; $parent_stack = array(); // $items contains the results of the SQL query $children = array(); foreach ( $items as $item ) $children[$items['parent_id']][] = $item; while ( $option = each( $children[$parent] ) ) { if ( !empty( $option ) ) { // 1) The item contains children: // store current parent in the stack, and update current parent if ( !empty( $children[$option['value']['id']] ) ) { $html .= '<li>' . $option['value']['title'] . '</li>'; $html .= '<ul>'; array_push( $parent_stack, $parent ); $parent = $option['value']['id']; } // 2) The item does not contain children else $html .= '<li>' . $option['value']['title'] . '</li>'; } // 3) Current parent has no more children: // jump back to the previous menu level else { $html .= '</ul>'; $parent = array_pop( $parent_stack ); } } // At this point, the HTML is already built echo $html; ?> the above code not working and am not sure it is the correct way. can anyone help me out?? Thanks
  9. is it possible to insert data from such a select like so: loop1: WHILE i<in_Dept_TOT DO INSERT INTO _epttbl(Project_id,Dept_id) VALUES(Result,SELECT SPLIT_STRING(in_Deptid, '||',i)); SET i=i+1; END WHILE loop1; Or is it better likeso: loop1: WHILE i<in_Dept_TOT DO SELECT SPLIT_STRING(in_Deptid, '||',i) into myvar ; INSERT INTO _epttbl(Project_id,Dept_id) VALUES(Result,myvar); SET i=i+1; END WHILE loop1;
  10. Basically what I am trying to do is have an option of choosing an "expiry time" when inserting a record. I will then use that expiry time to make a countdown clock that will expire the record when reached 0; but that's the step after. Right now I am having a bit of issue inserting that expiry time into the database. Here is my code. The error i get in the option value is something like <option value="<b>Notice</b>: Undefined variable...">. <?php $date_added = date('Y-m-d H:i:s'); $expiry_1 = date('Y-m-d H:i:s', strtotime('$date_added + 1 hour')); $expiry_6 = date('Y-m-d H:i:s', strtotime('$date_added + 6 hours')); $expiry_12 = date('Y-m-d H:i:s', strtotime('$date_added + 12 hours')); ?> <fieldset> <label>Expiry Time</label> <select name="expiry_time"> <option value="0">Select Time</option> <option value="<?php echo $expiry_1; ?>">1 hour</option> <option value="<?php echo $expiry_6; ?>">6 hours</option> <option value="<?php echo $expiry_12; ?>">12 hours</option> </select> </fieldset>
  11. Hello Forum: I smoked down the Google servers on this one and didn't come up with what I'm looking for. I have a MySQL table that stores a couple fields, one of them being a date field (set by CURDATE()) when it was written to the table. I'm trying to use the PHP date() and the sql field to find the number of days that's elapse, but I can't seem to get that to work for me. Here's what I'm working with: $stmt = $db->prepare('SELECT a.attendeeid, s.attendeeid, fname, lname, suspend, reason, sdate, a.memberid, s.memberid FROM attendees AS a JOIN suspended AS s ON a.attendeeid = s.attendeeid WHERE a.memberid = :memberid AND suspend = "Y"'); $stmt->bindValue(':memberid', $memberid, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetchAll(); ?> <div class="row"> <div class="table-repsonsive"> <table class="table table-bordered table-hover table-striped" style="margin-top:30px"> <thead> <tr> <th style="text-transform: uppercase">First</th> <th style="text-transform: uppercase">Last</th> <th style="text-transform: uppercase">Suspended</th> <th style="text-transform: uppercase">Suspension Date</th> <th style="text-transform: uppercase">Days on suspension</th> <th style="text-transform: uppercase">Reason</th> </tr> </thead> <?php foreach($result as $row ) { $i++; ?> <tbody> <?php echo '<tr style="'.getbgc($i). '">' ?> <td style="width:auto;"><?php echo $row[2] ?></td> <td style="width:auto;"><?php echo $row[3] ?></td> <td style="width:auto;"><?php echo $row[4] ?></td> <td style="width:auto;"><?php echo $row[6] ?></td> <td style="width:auto;"><?php echo strtodate(date('Y-m-d')) - $row[6] ?></td> // This is not working <td style="width:auto;"><?php echo $row[5] ?></td> $row[6] holds sdate from the query. Does anyone know how I can do this? Thanks.
  12. I'm stuck like a wheel barrow in the mud. Wondering if someone might be able to help me write this query. I have a table where status change dates are held. I'm trying to build a query that sums each of the columns by date. In the end.... I should have a column of dates in the first column. several columns as listed below. (created, offers, contracts, closed, sold) Then the total number of records with dates that match the row date. (It think that makes sense) So I can tell ... how many records were created on each day. how many offers were made on each day etc etc. Here is the query I have so far which doesn't quite work. Display is attached. select * from ( select `date`, sum(created) created, sum(offers) offers, sum(contracts) contracts, sum(closed) closed, sum(sold) sold from ( select DATE(from_unixtime(created)) `date`, count(*) created, 0 as offers, 0 as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(offer_date)) `date`, 0 as created, count(*) as offers, 0 as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(contract_date)) `date`, 0 as created, 0 as offers, count(*) as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(purchase_date)) `date`, 0 as created, 0 as offers, 0 as contracts, count(*) as closed, 0 as sold from properties union all select DATE(from_unixtime(sale_date)) `date`, 0 as created, 0 as offers, 0 as contracts, 0 as closed, count(*) as sold from properties )a group by a.`date` )b
  13. I have this table: CREATE TABLE _HRatortbl ( Hor_id INT unsigned NOT NULL auto_increment, Hicator_title longtext NOT NULL, Primary KEY(HRindicator_id), UNIQUE KEY ix_length_HRindicator_title (HRindicator_title(255)) )ENGINE=InnoDB DEFAULT CHARSET=utf8 why is it that it cannot differentiate between: Legally stipulated Age for marriage and legally stipulated age for mariage I found them both iniside the table .Is there another way to do this on text fields
  14. I am stumped. I have a database similar to this: | Class Number | Class Name | Class Date | 0001 MATH 1/1/2016 0002 SCIENCE 2/1/2016 0003 HISTORY 3/1/2016 I am calling all classes where the date is > current date. All matching classes are then put into a html dropdown box. I would now like to populate two additional fields with the class number and class date based on the selection of the dropdown. I know I'll need to use AJAX, but I am a little stumped on how to get started. My first problem is that I have the beginning of the html select tag before: while($row = $result->fetch_assoc()){ and the end select tag after the }, so I can't put the two additional form fields in the loop. Any tips on where to go from here? Here's what I have so far: <?php // Get required login info include "/secret/path/to/login.php"; $db = new mysqli('localhost', $username, $password, $database); // Connect to DB using required login info if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } unset($username);// put these variables back to null unset($password);// put these variables back to null unset($database);// put these variables back to null date_default_timezone_set('America/Los_Angeles'); // set default time zone PST $sql = "SELECT * FROM ft_form_7 WHERE class_full != 'Class Full' AND class_start_date > CURRENT_DATE()"; $result = $db->query($sql); if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']';} // show error if necessary if(mysqli_num_rows($result) < 1) { (include "/path/to/get-classes-for-registration-no-classes.php"); } echo '<select name="class_drop_down">'; // opens the dropdown box while($row = $result->fetch_assoc()){ echo '<option value="'.$row['class_name'].'">'.$row['class_name'].'</option>'; } echo '</select>'; $db->close(); $result->free(); ?>
  15. I have created a JSON file from the database, which has two table semone with attributes id, semester, cname and table courses with attributes coname and credit. Code I am writing in php is following. main.php <?php $user = "root"; $password = ""; $database = "scheduler"; $con = mysqli_connect("localhost", $user, $password, $database) or die ("Unable to connect"); $query = "SELECT semone.userid AS sbuid, semone.semester AS semester, semone.cname AS name, courses.credit AS value, courses.progskill AS skill FROM semone INNER JOIN courses ON semone.cname = courses.coname" ; $result = mysqli_query($con,$query)or die ("Unable to connect"); $info = array(); $test = array(); while ($row = $result->fetch_array(MYSQLI_ASSOC)) { $row['xyz'] = array( 'name'=> $row['name'], 'value'=> $row['value'] ); $info[$row['semester']]['children'][]= $row['xyz']; $data = json_encode(array('id' => $row['sbuid'], 'children' => $info)); } echo $data; ?> I want to get JSON file as seen in the following code, but I am getting something like this. **output.json** {"id":"12345", "children": {"first": {"children": [{"name":"CSE101","value":"100"}, {"name":"CSE102","value":"100"}]}, "second": {"children": [{"name":"CSE103","value":"50"}, {"name":"CSE104","value":"100"}, {"name":"CSE105","value":"100"}]}, "third": {"children": [{"name":"CSE106","value":"50"}]} }} But this is what I am expecting. **expected.json** { "id": 12345, "children": [{ "semester": "first", "children": [{ "name": "C101","value": 100}, { "name": "C102","value": 100}] }, { "semester": "second", "children": [{ "name": "C103", "value": 50}, {"name": "C104","value": 100}, {"name": "C105","value": 100}] }, { "semester": "third", "children": [{"name": "C106","value": 50}] } }
  16. what data type can I use to define a text field input parameter in the stored procedure below;in the data base table it is defined as: comment text, and in the stored procedure how can I define it: CREATE PROCEDURE sp_ne comm(in in_Nature_id varchar(256)/text) MODIFIES SQL DATA BEGIN insert into me(comment)values(in_Nature_id ie vvvv uygliuyiuyo......>256 characters); END
  17. I am using this for multi image upload. https://github.com/CreativeDream/jquery.filer Since it doesn't show example of how to use it with a database, I am having a bit of an issue. The following is my code. Couple things. 1. It won't insert into database with the "tokens". If I remove the token code, then it'll work. The same token works in other forms that I use. 2. Yes It inserts into the database. The issue is that it inserts only 1 file at a time and not all the selected files. <?php require_once ($_SERVER['DOCUMENT_ROOT'] . '/home/templates/header.php'); if(isset($_POST['submit'])) { if($_POST['token'] === $_SESSION['token']) { if(isset($_FILES['files'])){ $date_added = date('Y-m-d H:i:s'); // Setting up folder for images $user_dir = $_SERVER['DOCUMENT_ROOT'] .'/home/members/images/'.$db_userid.'/records/'; if(!is_dir($user_dir)){ mkdir($_SERVER['DOCUMENT_ROOT'] .'/home/members/images/'.$db_userid.'/records/', 0775, true); } else { $uploader = new Uploader(); $data = $uploader->upload($_FILES['files'], array( 'limit' => 10, //Maximum Limit of files. {null, Number} 'maxSize' => 10, //Maximum Size of files {null, Number(in MB's)} 'extensions' => null, //Whitelist for file extension. {null, Array(ex: array('jpg', 'png'))} 'required' => false, //Minimum one file is required for upload {Boolean} 'uploadDir' => '../uploads/', //Upload directory {String} 'title' => array('auto', 10), //New file name {null, String, Array} *please read documentation in README.md 'removeFiles' => true, //Enable file exclusion {Boolean(extra for jQuery.filer), String($_POST field name containing json data with file names)} 'perms' => null, //Uploaded file permisions {null, Number} 'onCheck' => null, //A callback function name to be called by checking a file for errors (must return an array) | ($file) | Callback 'onError' => null, //A callback function name to be called if an error occured (must return an array) | ($errors, $file) | Callback 'onSuccess' => null, //A callback function name to be called if all files were successfully uploaded | ($files, $metas) | Callback 'onUpload' => null, //A callback function name to be called if all files were successfully uploaded (must return an array) | ($file) | Callback 'onComplete' => null, //A callback function name to be called when upload is complete | ($file) | Callback 'onRemove' => 'onFilesRemoveCallback' //A callback function name to be called by removing files (must return an array) | ($removed_files) | Callback )); if($data['isComplete']){ $files = $data['data']; print_r($files); } if($data['hasErrors']){ $errors = $data['errors']; print_r($errors); } function onFilesRemoveCallback($removed_files){ foreach($removed_files as $key=>$value){ $file = '../uploads/' . $value; if(file_exists($file)){ unlink($file); } } return $removed_files; } for($i = 0; $i < count($_FILES['files']['name']); $i++) { $name = $_FILES['files']['name'][$i]; $temp = $_FILES['files']['tmp_name'][$i]; $ext = pathinfo($name, PATHINFO_EXTENSION); $upload = md5( rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 )); $image_thumb_path = $user_dir . 'thumb_' . $upload . $ext; try { $insert_image = $db->prepare("INSERT INTO images(user_id, image_path, date_added) VALUES(:user_id, :image_path, :date_added)"); $insert_image->bindParam(':user_id', $db_userid); $insert_image->bindParam(':image_path', $image_thumb_path); $insert_image->bindParam(':date_added', $date_added); $result_image = $insert_image->execute(); if($result_image == false) { $error = 'There was a problem inserting images!'; } else { move_uploaded_file($temp, $image_thumb_path); $success = 'Your images has been saved.'; } } catch(Exception $e) { $error = die($e->getMessage()); } } } } } } ?> <h1>Upload Images</h1> <?php include_once ($dir_path . '/home/snippets/success-errors.php'); ?> <form action="" method="post" enctype="multipart/form-data"> <fieldset> <input type="file" multiple="multiple" name="files[]" id="input2"> <fieldset> <input type="hidden" name="token" value="<?php echo $_SESSION['token'] = md5(rand(time (), true)); ?>" /> <input type="submit" name="submit" class="red-btn" value="upload" /> </fieldset> </form> <?php require_once ($_SERVER['DOCUMENT_ROOT'] . '/home/templates/footer.php');
  18. Hi I'm trying to compare two tables with each other and update the 2nd table with the new updated name from table 1 via their unique identical ID $resultus = mysql_query("SELECT * FROM Users2"); $rowus = mysql_fetch_array($resultus); $naamus = urldecode($rowus['Username']); $mxitus = $rowus['mxitid']; $resultnup = mysql_query("SELECT * FROM pm"); $rownup = mysql_fetch_array($resultnup); $naamup = $rownup['username']; $ipup = $rownup['ip']; while($ipup == $mxitus){ $updatename = "UPDATE pm SET username= \"$naamus\" WHERE ip = \"$mxitus\""; mysql_query($updatename) or die("Error: ".mysql_error()); } The $mxitus and $ipup is the 2 fields that would be identical in both tables now Im trying to update the pm table username field with the naamus field from Users 2 any assistance please?
  19. $read1 = "unread"; $query = "INSERT INTO pm (username,mxitid,message,time,read,ip) VALUES (\"$naam\",\"$ip1\",\"$message\",\"$date\",\"$read1\",\"$banby2\")"; I'm getting the error This only happened when I added the read and value $read I got the field named read in my database.... any suggestion where im going wrong? If I remove the read field the rest of the query works 100%
  20. I'm looking for an application or a social wall plugin to be added to a project. After looking at Wordpress and finally sifting through all the plugins (maybe all), I have come to a conclusion the plugins are not giving me enough customization options. For example, customizing the registration form. I need to add javascript for a combo box in order to display different options depending on what was selected. What I need - Your Opinion on a good social wall that's easy to make changes. I need a secure login and password --- PDO based A control panel would be nice to activate users or deactivate. A customized registration form Ability to add more pages, add php to customize it to work like I need it to. Responsive. If anyone has an opinion with experience on this matter it would be great to hear from you.
  21. Hi all, I currently have a web app (php my first once actually) that accesses a MySql database. How I was handling the login was like this: This user enters the username and pw which gets sent to a stored procedure. If they successfully are validated I output a record (contains userid, first name and if they are logged in or not) and I set two session variables, 1 that stores a boolean if they are logged in (1 if they are, 0 if they are not) and the other stores the user id of that user (so I can use later to make sure they only get their data). I then check these session variables to 1.Make sure they are logged in and 2. Make sure they are only requesting their data (userid) I'm now going to be working on an Android app and make all the data access stuff a rest api that both the app and the website can consume. I modified the login stored procedure so it now will return a token as well. The token is generated on the DB(a hashed value of a couple of fields concatenated). When they log in successfully the token generated is stored in a user token table.(one user, one token) The table also stores a token_expire timestamp. Every time they log in a new token is created(and token_expire is updated). If they try to do something after the token expired (based on the token_expire field) then it should redirect them to login so a new token can be created. When I do the Android app, dealing with this and storing this token on the client is easy and there are many ways to store it (I was thinking storing it in a local sqlite table, shared_prefs (prob not the best way) etc..) and I would just parse through the json result. So keeping track of the token is easy with the app but my problem comes in with the PHP web site. So I'm faced with two issues: Issue 1. Right now I have a php form (with login and password fields) and it posts to a login process page which calls the stored procedure and if all is good redirects them to a dashboard page. Now if I use rest the post action would be something like: api/users/login instead of loginprocess.php correct? But then the api just spits out json and I'm not sure how to hand the result from the api to the php code. As when I change the post action I just get a white page with the json result string. So I need help knowing what to do once the api returns the result. Does this have to be called differently than a normal form submit? Do I just have the form submit call a js funcation that makes the call to the page and parses the result? Similar to something like this but instead of passing the cookie passing the login information? $opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."\r\n")); $context = stream_context_create($opts); session_write_close(); // unlock the file $contents = file_get_contents(url, false, $context); Issue 2. Once this token is generated in MySQL and sent back to the api, I need to pass it back to the PHP(related to #1) but How do I store it so that other pages of the site can send it when it requests the data? I know it has to be sent in the header in future requests and that's not my issue. My issue is where do I store the token on the web client so that other pages can use it? Should I store it in a client cookie? (but then doesn't this go against rest?) Store it in local storage? I'm pretty new to PHP and REST (was a classic ASP guy and just getting back into this stuff. This project is the first personal project for myself to learn this stuff and get the rust out) so I'm just trying to figure out the best way. I do not want to use sessions as that violates REST. I also do not want to use oauth or any 3rd party solution. I have been reading a lot about this but I'm still unclear as to how to go about these changes to the web version of the app and have it function properly. This is what my rest login api looks like so far (I know this will have to change but I'm stuck here with it): function loginUser() { global $app; $req = $app->request(); $paramUsername = $req->params('username'); $paramPassword = $req->params('password'); $sql = "CALL checkPassword(:username,:password)"; try { $dbCon = getConnection(); $stmt = $dbCon->prepare($sql); $stmt->bindParam("username", $paramUsername); $stmt->bindParam("password", $paramPassword); $stmt->execute(); $result = $stmt->fetchAll(); $loggedin=$result[0]["loggedin"]; $uid= $result[0]["uid"]; $fname=$result[0]["firstname"]; $token=$result[0]["token"]; $response["uid"]=$uid; $response["loggedin"]=$loggedin; $response["firstname"]=$fname; $response["token"]=$token; echo json_encode($response); $dbCon = null; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } } Which returns: {"uid":"100","loggedin":"1","firstname":"John","token":"f0165d67221563bef150018276f4f77b7bd1e1763223e"} Here is what the form looks like calling the api currently: <form id="login" method="post" action="webservices/api/users/login"> <input class="my-class" style="width:20em" type="email" name="username" required> <input class="my-class" style="width:20em" type="password" name="password" required> <button type="submit" id="SubmitButton" name="submit" "></button> </form> Can anyone recommend the best way to deal with these two issues? Any help would be appreciated. Oh I should mention I'm using slim to help with the rest api's. TIA
  22. Me again.. I've struggled for the past 2 hours to insert article comments and link them to an existent article on the page. Now, the function that is displaying both comments and articles looks like this: function list_articles() { include('core/db/db_connection.php'); $sql = "SELECT blog.content_id, blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by FROM blog LEFT OUTER JOIN article_comments ON blog.content_id = article_comments.blog_id WHERE blog.content != '' ORDER BY blog.content_id DESC"; $result = mysqli_query($dbCon, $sql); $previous_blog_id = 0; while ($row = mysqli_fetch_array($result)) { if ($previous_blog_id != $row['content_id']) { echo "<h5 class='posted_by'>Posted by {$row['posted_by']} on {$row['date']}</h5> <h1 class='content_headers'>{$row['title']}</h1> <article>{$row['content']}</article> <hr class='artline'>"; $previous_blog_id = $row['content_id']; } if (!empty($row['comment_by']) && !empty($row['comments'])) { echo "<div class='commented_by'>Posted by: {$row['comment_by']} </div> <div class='comments'>Comments: {$row['comments']}</div> <hr class='artline2'>"; } } } The function I'm running to insert comments into article_comments table function insert_comments($comments, $comment_by, $blog_id) { include('core/db/db_connection.php'); $comment_by = sanitize($comment_by); $comments = sanitize($comments); $sql = "INSERT INTO article_comments (comments, comment_by, blog_id) VALUES ('$comments', '$comment_by', '$blog_id')"; mysqli_query($dbCon, $sql); } This works - it does the insertion, however I have no clue on how I could target the $blog_id variable when the user submits the post... The below is the form I use <?php echo list_articles(); if (!empty($_POST)) { insert_comments($_POST['comments'], $_POST['username'], 11); } ?> <form method='post' action='' class='comments_form'> <input type='text' name='username' placeholder='your name... *' id='name'> <textarea name='comments' id='textarea' placeholder='your comment... *' cols='30' rows='6'></textarea> <input type='submit' name='submit' id='post' value='post'> </form> I bet you noticed that I've manually inserted 11 as a param for the last variable. This links to blog_id 11 (the foreign key) in my article_comments table. It is displaying the comment just fine. Is there any way to target $blog_id without having to insert a number manually? Something like how I am targeting the $comments variable using $_POST['comments'] ? Also, even if I can target that, how do I know which post is the user commenting to? Should I give them the option to choose in a drop-down list ? That seems awkward.. but it's the only solution I can think of.
  23. Hello I have a php script I actually got from Stackoverflow, on one of the questions asked. I'm not really sure where to apply it, I put it in some code that I had already that submits the data to be put in the text file. It downloads the file, but inside it has php errors. The errors are: Undefined variable: month in xxx.xxx.xxx on line 12 Undefined variable: res xxx.xxx.xxx on line 14 mysql_fetch_array() expects parameter 1 to be resource, null given in xxx.xxx.xxx on line 14 The script I have is: //Below is where you create particular month's text file $file = $month . '.txt'; $handle = fopen($file, "w"); while ($row=mysql_fetch_array($res)){ $writestring = $row['data_I_want'] . "\r\n"; fwrite($handle, $writestring); } fclose($handle); $data = file_get_contents($file); echo $data; //Now the file is ready with data from database //Add below to download the text file created $filename = $file; //name of the file $filepath = $file; //location of the file. I have put $file since your file is create on the same folder where this script is header("Cache-control: private"); header("Content-type: application/force-download"); header("Content-transfer-encoding: binary\n"); header("Content-disposition: attachment; filename=\"$filename\""); header("Content-Length: ".filesize($filepath)); readfile($filepath); exit;
  24. Good day, I have a task at hand, I was given an project where I need to combine 3 blogs into on site. I understand the simplistic answer to this but the doing is a bit confusing at this point and would like to get some input from a community. Is there software I can use for this, except for wordpress? Or is it best to design and develop each cms for each blog into a main CMS page. MAIN CMS PAGE -> Blog 1, blog 2, blog 3 and then settings for each blogs and add/edit and delete pages etc. The second problem is that I have briefly dealt with themes before and have found them to be a pain when it comes to trying to select a theme from a list of 3. I got fairly tilted results as some elements confused each other.. Is this fairly normal? Does php have a weakness towards themes? Any software suggestions and guidance would be so appreciated. Thanks in advance
  25. I've written a script to store images in my database. The images have a caption that is also uploaded and stored. This was fairly easy to get working. I have a jquery function setup to add a new file input and caption input every time I click a button. This also works. What is not working is my PHP is not uploading multiple files for some reason. Could someone tell me what I have done wrong? Thanks HTML: <form id="uploadMultiple" method="post" action="/scripts/php/imageUploadTest" enctype="multipart/form-data"> <table class="fileUploadTable" id="uploadArea" cellspacing="0"> <tr> <td> <label for="imageFile">Image:</label> <input type="file" name="imageFile" accept=".jpg,.jpeg,.png,.gif"> </td> <td> <label for="imageCaption">Image Caption:</label> <input type="text" name="imageCaption"> </td> <td width="150px"> </td> </tr> <tr id="uploadSubmission"> <td> <input type="submit" value="Upload More" id="uploadMore"> </td> <td> <input type="submit" value="Submit" name="addImage"> </td> <td width="150px"> </td> </tr> </table> </form> JQuery for adding new elements: $(function() { var scntDiv = $('#uploadArea'); var i = $('#p_scents tr td').size() + 1; $('#uploadMore').live('click', function() { $('<tr><td><label for="imageFile">Image:</label> <input type="file" name="imageFile" accept=".jpg,.jpeg,.png,.gif"></td><td><label for="imageCaption">Image Caption:</label> <input type="text" name="imageCaption"></td><td><a href="#" class="removeUpload" width="150px" style="text-align: center">Remove</a></td></tr>').insertBefore( $('#uploadSubmission') ); i++; return false; }); $('.removeUpload').live('click', function() { if( i > 1 ) { $(this).parents('tr').remove(); i--; } return false; }); }); And finally the PHP: require($_SERVER['DOCUMENT_ROOT'].'/settings/globalVariables.php'); require($_SERVER['DOCUMENT_ROOT'].'/settings/mysqli_connect.php'); $db_name = 'imageUploads'; $tbl_name = 'gallery'; if(!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_select_db($conn, "$db_name")or die("cannot select DB"); foreach($_FILES['imageFile'] as $file){ $caption = $_POST['imageCaption']; $uploadDir = 'http://www.example.com/images/'.'gallery/'; $fileName = $_FILES['imageFile']['name']; $filePath = $uploadDir . $fileName; if(move_uploaded_file($_FILES["imageFile"]["tmp_name"],$_SERVER['DOCUMENT_ROOT']."/images/gallery/".$_FILES["imageFile"]["name"])) { $query_image = "INSERT INTO $tbl_name(filename,path,caption) VALUES ('$fileName','$uploadDir','$caption')"; if(mysqli_query($conn, $query_image)) { echo "Stored in: " . "gallery/" . $_FILES["imageFile"]["name"]; } else { echo 'File name not stored in database'; } } } I was hoping I had it working properly for multiple images with my `foreach` loop but it only uploads one image even if I have 4 selected. EDIT: I've tried modifying my code to this and it's not working either but looking at tutorials this seems to be more on the right track than my previous code: r equire($_SERVER['DOCUMENT_ROOT'].'/settings/globalVariables.php'); require($_SERVER['DOCUMENT_ROOT'].'/settings/mysqli_connect.php'); $db_name = 'imageUploads'; $tbl_name = 'gallery'; if(!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_select_db($conn, "$db_name")or die("cannot select DB"); foreach($_FILES['imageFile'] as $key => $name){ $caption = $_POST['imageCaption']; $uploadDir = 'http://www.example.com/images/'.'gallery/'; $fileName = $key.$_FILES['imageFile']['name'][$key]; $file_size = $_FILES['files']['size'][$key]; $file_tmp = $_FILES['files']['tmp_name'][$key]; $file_type= $_FILES['files']['type'][$key]; $filePath = $uploadDir . $fileName; if(move_uploaded_file($file_tmp,$_SERVER['DOCUMENT_ROOT']."/images/gallery/".$fileName)) { $query_image = "INSERT INTO $tbl_name(filename,path,caption) VALUES ('$fileName','$uploadDir','$caption')"; if(mysqli_query($conn, $query_image)) { echo "Stored in: " . "gallery/" . $_FILES["imageFile"]["name"]; } else { echo 'File name not stored in database'; } } } I've also added `[]` in the names of the HTML input elements that needed them.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.