Jump to content

candice

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

candice's Achievements

Member

Member (2/5)

0

Reputation

  1. Sorry im not very sure what you mean. How should i code it?
  2. Thanks for the reply. I tried replacing the code, but im still getting the same error. XML Parsing Error: junk after document element Location: http://localhost/equipdb/genUserSearch.php Line Number 2, Column 1:<b>Notice</b>: Undefined index: search in <b>C:\wamp\www\equipdb\genUserSearch.php</b> on line <b>41</b><br /> ^ could be something to search variable?
  3. Hi all, I am about to do a live search, and in the midst of testing out my script that generates the xml, i found this error: XML Parsing Error: junk after document element Location: http://localhost/equipdb/genUserSearch.php Line Number 2, Column 1:<b>Notice</b>: Undefined index: search in <b>C:\wamp\www\equipdb\genUserSearch.php</b> on line <b>41</b><br /> ^ Does any of you know where the error lies? Thanks. Attached is my code: <?php header ('Content-type:text/xml') ?> <?php echo ('<?xml version="1.0" encoding="iso-8859-1"?>') ?> <?php require_once('connection.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } function highlightkeyword($text) { $keyword = $_GET['search']; $highlighttext = str_ireplace($keyword, "<span class='highlight'>".$keyword."</span>", $text); return $highlighttext; } mysql_select_db($db_name); $search = $_GET['search']; $query_rsAccount = "SELECT * FROM student WHERE studentID LIKE '%".$search."%' OR studentname LIKE '%".$search."%'"; $rsAccount = mysql_query($query_rsAccount, $db_name) or die(mysql_error()); $row_rsAccount = mysql_fetch_assoc($rsAccount); $totalRows_rsAccount = mysql_num_rows($rsAccount); ?> <Account> <?php do { ?> <result total ="<?php echo $totalRows_rsAccount ?>"> <id><![CDATA[<?php echo $row_rsAccount['id']; ?>]]></id> <studentID><![CDATA[<?php echo highlightkeyword($row_rsAccount['studentID']); ?>]]></studentID> <studentname><![CDATA[<?php echo highlightkeyword($row_rsAccount['studentname']); ?>]]></studentname> <?php } while ($row_rsAccount = mysql_fetch_assoc($rsAccount)); ?> </Account> <?php mysql_free_result($rsAccount); ?>
  4. Hi, Thanks for the help!! I'll go and give it a try.
  5. Thanks.. we will also try it.. but could u help us to code that part to make sure that we are on the right track?? Thanks a milion.
  6. Thanks for replying. The button is actually split up,meaning its two different pictures. What i want is something like, when the user clicks on one button, the value of the button would then be captured and then the form would then be submitted, updating the status in the database. it works something like creating a radio button, selecting one of the radio buttons and then pressing the update button to change the status, just that in this case, i do not want the update button, just clicking the image itself and then updating the status
  7. I have 2 image button which allow users to change the status in or out: Meaning that when user click on the red icon, the status would automatically change to in and when click on the green icon, it will change to out. I did some codings, but the value doesn't seem to be passing in. <input type="image" src="images/icons/in.jpg" value="In" alt="submit"/> can anyone help?
  8. Hi all, I have a radio button and image for the user to toggle between his/her in and out status. however, i want to make the image clickable such that once the image above the radio button is clicked, the radio button would be auto selected? is there any way i can do this with php and html? Thanks!!!!!
  9. Hi all, I have a radio button and image for the user to toggle between his/her in and out status. however, i want to make the image clickable such that once the image above the radio button is clicked, the radio button would be auto selected? is there any way i can do this with php and html? Thanks!!!!!
  10. Hi, I tried your method, but i getting this error. Warning: fopen('Subject Schedule2 - Excel (extracted 31 July).csv') [function.fopen]: failed to open stream: No such file or directory in C:\wamp\www\web portal (staff)v1\import2.php on line 121 Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\wamp\www\web portal (staff)v1\import2.php on line 123 SQL ERROR:Query was empty do you know what is the problem? attached below is my current codes <?php session_start(); echo $name; ob_start(); ?> <?php require_once('staffSql.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Staff Signage: Web Portal</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="4"><?php include("./include/headerAdmin.php"); ?></td> </tr> <tr> <td colspan="4" bgcolor="#FFFFFF" height="6"></td> </tr> <tr> <td width="5" valign="top" bgcolor="#FFFFFF"> </td> <td width="175" align="center" valign="top" bgcolor="#FFFFFF"><?php include("./include/leftBar.php");?></td> <td width="7" bgcolor="#FFFFFF"> </td> <td width="614" valign="top" bgcolor="#FFFFFF"><table width="605" border="0" align="center" cellspacing="0"> <tr> <td height="20" valign="middle" bgcolor="#437AB6"><span class="contentHeader"> Import Staff Timetable</span></td> </tr> <tr> </tr> <tr> <td valign="top" bgcolor = "#FAFAF5"><form action="import2.php" method="post" enctype="multipart/form-data"> <div align="center"> <p align="left" class="contentText">Here, you can upload a new staff timetable into the database with each new semester. The old timetable would be replaced once the new one has been uploaded into the database. Please note that <strong>ONLY CSV </strong>files are allowed to be uploaded to the database. There is however, no file size limit.</p> <p align="center" class="contentText">File Path <input type="file" name="fileupload" id="fileupload" /> </p> <p align="center"> <input type="submit" name="upload" id="upload" value="Submit" /> </p> <p align="center"><strong>NOTE: You do not have to remove the header at the csv file</strong></p> <p align="center"> <?php //FUNCTION TO GET THE EXTENSION OF THE FILE THAT IS BEING UPLOADED function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } function GetFilename($file) { $filename = substr($file, strrpos($file,'/')+1,strlen($file)-strrpos($file,'/')); return $filename; } //UPLOADING FILE if(isset($_POST['upload'])) { $filetype = $_FILES['fileupload']['type']; if(empty($filetype)){ echo'<font color="red"><span class = "contentText"><b>Please click on the browse button to locate your file</b></span></font>'; //echo "<script language=\"JavaScript\">"; //echo "alert('Please click on the browse button to locate your file');"; } if($filetype){ $csvfile = stripslashes($_FILES['fileupload']['name']); $extension = getExtension($csvfile); $extension = strtolower($extension); //echo $extension; if (($extension != "csv") && ($extension != "CSV")){ echo'<font color="red"><span class = "contentText"><b>Invalid file type. Please upload only .csv files</b></span></font>'; /*echo "<script language=\"JavaScript\">"; echo "alert('Invalid file type. Please upload only .csv files');"; echo "</script>"; */ } else { $uploaddir = 'C:/wamp/www/web portal (staff)v1/uploads/'; $uploadfile = $uploaddir . basename($_FILES['fileupload']['name']); echo $csvname; echo $uploaddir; echo $uploadfile; $csvname = GetFilename($uploadfile); $fp = fopen("'$csvname'", "r"); while ($data = fgetcsv($fp, 1000)){ if (!is_numeric($data[0])){ // skip header // process data $query = 'LOAD DATA INFILE "'.$uploadfile.'" REPLACE INTO TABLE timetable FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n" IGNORE 1 LINES'; } else{ $query = 'LOAD DATA INFILE "'.$uploadfile.'" REPLACE INTO TABLE timetable FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n"'; } } } //TRUNCATE THE FILE BEFORE INSERTING IT INTO THE DATABASE mysql_select_db($dbname, $root); mysql_select_db($dbname, $root); mysql_query("TRUNCATE TABLE timetable") or die("MySQL Error: " . mysql_error()); //Delete the existing rows //LOAD DATA FILE INTO DATABASE mysql_query($query, $root) or die('SQL ERROR:'.mysql_error()); //Insert in the new values into the database fclose($fp); } } ?></p> </div> </form></td> </tr> </table> <p><br /> </p> <p> </p> <p> </p> <p> </p> <p> </p></td> </tr> <tr> <td colspan="4"><?php include("include/footer.php") ?></td> </tr> </table> </body> </html> <?php ob_flush(); ?>
  11. Hi all, i'm trying to get my csv import app to check for the csv file header. if here is a header, it would execute this particular query, it not, it would execute another query. Attached below is my codes. any idea what is wrong? <?php session_start(); echo $name; ob_start(); ?> <?php require_once('staffSql.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Staff Signage: Web Portal</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="4"><?php include("./include/headerAdmin.php"); ?></td> </tr> <tr> <td colspan="4" bgcolor="#FFFFFF" height="6"></td> </tr> <tr> <td width="5" valign="top" bgcolor="#FFFFFF"> </td> <td width="175" align="center" valign="top" bgcolor="#FFFFFF"><?php include("./include/leftBar.php");?></td> <td width="7" bgcolor="#FFFFFF"> </td> <td width="614" valign="top" bgcolor="#FFFFFF"><table width="605" border="0" align="center" cellspacing="0"> <tr> <td height="20" valign="middle" bgcolor="#437AB6"><span class="contentHeader"> Import Staff Timetable</span></td> </tr> <tr> </tr> <tr> <td valign="top" bgcolor = "#FAFAF5"><form action="import2.php" method="post" enctype="multipart/form-data"> <div align="center"> <p align="left" class="contentText">Here, you can upload a new staff timetable into the database with each new semester. The old timetable would be replaced once the new one has been uploaded into the database. Please note that <strong>ONLY CSV </strong>files are allowed to be uploaded to the database. There is however, no file size limit.</p> <p align="center" class="contentText">File Path <input type="file" name="fileupload" id="fileupload" /> </p> <p align="center"> <input type="submit" name="upload" id="upload" value="Submit" /> </p> <p align="center"><strong>NOTE: You do not have to remove the header at the csv file</strong></p> <p align="center"> <?php //FUNCTION TO GET THE EXTENSION OF THE FILE THAT IS BEING UPLOADED function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //UPLOADING FILE if(isset($_POST['upload'])) { $filetype = $_FILES['fileupload']['type']; if(empty($filetype)){ echo'<font color="red"><span class = "contentText"><b>Please click on the browse button to locate your file</b></span></font>'; //echo "<script language=\"JavaScript\">"; //echo "alert('Please click on the browse button to locate your file');"; } if($filetype){ $csvfile = stripslashes($_FILES['fileupload']['name']); $extension = getExtension($csvfile); $extension = strtolower($extension); //echo $extension; if (($extension != "csv") && ($extension != "CSV")){ echo'<font color="red"><span class = "contentText"><b>Invalid file type. Please upload only .csv files</b></span></font>'; /*echo "<script language=\"JavaScript\">"; echo "alert('Invalid file type. Please upload only .csv files');"; echo "</script>"; */ } else { $uploaddir = 'C:/wamp/www/web portal (staff)v1/images/uploaded/'; $uploadfile = $uploaddir . basename($_FILES['fileupload']['name']); if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile)) { echo "<span class='contentText'>File is valid, and was successfully uploaded.\n</span>"; echo "<span class = 'contentText'>Cick <a href ='admin_timetable.php'><b>here</b></a> to view the timetable that you have just uploaded"; } $fp = fopen('$uploaddir', 'r'); while ($data = fgetcsv($fp, 1024)){ if (!is_numeric($data[0])){ // skip header // process data $query = 'LOAD DATA INFILE "'.$uploadfile.'" REPLACE INTO TABLE timetable FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n" IGNORE 1 LINES'; } else{ $query = 'LOAD DATA INFILE "'.$uploadfile.'" REPLACE INTO TABLE timetable FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n"'; } } fclose($fp); //TRUNCATE THE FILE BEFORE INSERTING IT INTO THE DATABASE mysql_select_db($dbname, $root); //mysql_select_db($dbname, $root); mysql_query("TRUNCATE TABLE timetable") or die("MySQL Error: " . mysql_error()); //Delete the existing rows //LOAD DATA FILE INTO DATABASE mysql_query($query, $root) or die('SQL ERROR:'.mysql_error()); //Insert in the new values into the database } } } ?></p> </div> </form></td> </tr> </table> <p><br /> </p> <p> </p> <p> </p> <p> </p> <p> </p></td> </tr> <tr> <td colspan="4"><?php include("include/footer.php") ?></td> </tr> </table> </body> </html> <?php ob_flush(); ?>
  12. Thanks a million! I'll give me a try
  13. Hi all, i have a csv fiile that has to be imported to a ftp server database. The code works when i am trying out the application on localhost, and the data in the file is successfully uploaded and sent in the database. however, this becomes an issue on when my files are launched on the ftp server. I get this following error: SQL ERROR:Access denied for user 'istaff'@'%' (using password: YES) does anyone know what this means? I'm attaching my code here, perhaps it might help. Thanks!! <?php session_start(); echo $name; ob_start(); ?> <?php require_once('staffSql.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Staff Signage: Web Portal</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="4"><?php include("./include/headerAdmin.php"); ?></td> </tr> <tr> <td colspan="4" bgcolor="#FFFFFF" height="6"></td> </tr> <tr> <td width="5" valign="top" bgcolor="#FFFFFF"> </td> <td width="175" align="center" valign="top" bgcolor="#FFFFFF"><?php include("./include/leftBar.php");?></td> <td width="7" bgcolor="#FFFFFF"> </td> <td width="614" valign="top" bgcolor="#FFFFFF"><table width="605" border="0" align="center" cellspacing="0"> <tr> <td height="20" valign="middle" bgcolor="#437AB6"><span class="contentHeader"> Import Staff Timetable</span></td> </tr> <tr> </tr> <tr> <td valign="top" bgcolor = "#FAFAF5"><form action="import2.php" method="post" enctype="multipart/form-data"> <div align="center"> <p align="left" class="contentText">Here, you can upload a new staff timetable into the database with each new semester. The old timetable would be replaced once the new one has been uploaded into the database. Please note that <strong>ONLY CSV </strong>files are allowed to be uploaded to the database. There is however, no file size limit.</p> <p align="center" class="contentText">File Path <input type="file" name="fileupload" id="fileupload" /> </p> <p align="center"> <input type="submit" name="upload" id="upload" value="Submit" /> </p> <p align="center"> <?php //FUNCTION TO GET THE EXTENSION OF THE FILE THAT IS BEING UPLOADED function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //UPLOADING FILE if(isset($_POST['upload'])) { $filetype = $_FILES['fileupload']['type']; if(empty($filetype)){ echo'<font color="red"><span class = "contentText"><b>Please click on the browse button to locate your file</b></span></font>'; //echo "<script language=\"JavaScript\">"; //echo "alert('Please click on the browse button to locate your file');"; } if($filetype){ $csvfile = stripslashes($_FILES['fileupload']['name']); $extension = getExtension($csvfile); $extension = strtolower($extension); //echo $extension; if (($extension != "csv") && ($extension != "CSV")){ echo'<font color="red"><span class = "contentText"><b>Invalid file type. Please upload only .csv files</b></span></font>'; /*echo "<script language=\"JavaScript\">"; echo "alert('Invalid file type. Please upload only .csv files');"; echo "</script>"; */ } else { $uploaddir = 'images/uploaded/'; $uploadfile = $uploaddir . basename($_FILES['fileupload']['name']); if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile)) { echo "<span class='contentText'>File is valid, and was successfully uploaded.\n</span>"; echo "<span class = 'contentText'>Cick <a href ='admin_timetable.php'><b>here</b></a> to view the timetable that you have just uploaded"; } //TRUNCATE THE FILE BEFORE INSERTING IT INTO THE DATABASE mysql_select_db($dbname, $root); //mysql_select_db($dbname, $root); mysql_query("TRUNCATE TABLE timetable") or die("MySQL Error: " . mysql_error()); //Delete the existing rows //LOAD DATA FILE INTO DATABASE $query = 'LOAD DATA INFILE "'.$uploadfile.'" REPLACE INTO TABLE timetable FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n"'; mysql_query($query, $root) or die('SQL ERROR:'.mysql_error()); //Insert in the new values into the database } } } ?></p> </div> </form></td> </tr> </table> <p><br /> </p> <p> </p> <p> </p> <p> </p> <p> </p></td> </tr> <tr> <td colspan="4"><?php include("include/footer.php") ?></td> </tr> </table> </body> </html> <?php ob_flush(); ?>
  14. Hi all, I have a csv file that i wish to upload to the database, and i was wondering what is the code snippet that can help me check whether csv file has a header. Thanks!!
  15. ok thanks!! I'll give it a try!!
×
×
  • 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.