Jump to content

skateme

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

skateme's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi thanks for the reply. I think option B is best, however the output still appears the same. My updated code: <?php $host = "*********"; $user = "*********"; $pass = "*********"; $db = "database_name"; $table = "table"; $file = "member_information"; $link = mysql_connect($host, $user, $pass) or die("Cannot connect." . mysql_error()); mysql_select_db($db) or die("Cannot connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].","; $i++;} } $csv_output .= "\n"; $values = mysql_query("SELECT userid AS \"UserID\",temp as \"\",field1 AS \"Name\",field2 AS \"HighSchool\",field3 AS \"HSGraduation\",field4 AS \"College\",field5 AS \"CollegeGraduation\",field6 AS \"Major\", field7 AS \"InternshipSite\",field8 AS \"Email\" FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } $filename = $file."_".date("m.d.y"); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("m.d.y") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Any advice? Thanks!
  2. The table columns are called by a forum that will be too much of a hassle to update.
  3. Hi, I have a script that dumps the information from one of my MySQL tables into a CSV. The script works great, but in the result, the names of the MySQL columns are shown as-is. In other words, I have a column named "field4" that shows up as "field4" in the CSV. How can I modify the columns to more descriptive names without modifying the database itself? Here's my code: <?php $host = "*********"; $user = "*********"; $pass = "*********"; $db = "database_name"; $table = "table"; $file = "member_information"; $link = mysql_connect($host, $user, $pass) or die("Cannot connect." . mysql_error()); mysql_select_db($db) or die("Cannot connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].","; $i++;} } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } $filename = $file."_".date("m.d.y"); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("m.d.y") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> The CSV it spits out looks like this: field1 field2 field3 field 4 info info info info I want it to look like this: Name Email Location Age info info info info Thanks in advance!
  4. I'm still getting another error message on line 7. Line 7 is the $query line: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /Library/WebServer/Documents/MDR/myaccount.php on line 7 That error disappears when I remove the quotation marks around SELECT email.., but I get new error saying: Parse error: syntax error, unexpected ',' in /Library/WebServer/Documents/MDR/myaccount.php on line 7 When I remove ",location" from the query, the new error I get is: Parse error: syntax error, unexpected '=' in /Library/WebServer/Documents/MDR/myaccount.php on line 7
  5. Thanks! That worked for the most part. I get an undefined function error: Fatal error: Call to undefined function  sprintf() in /Library/WebServer/Documents/MDR/myaccount.php on line 7 My code: <?php session_start(); print "<pre>".$_SESSION."</pre>"; $con = mysql_connect("localhost", "admin", "adminpass") or die("Could not connect to database"); $database = mysql_select_db("db") or die("<br />Could not select database"); $username = $_SESSION['username']; $query = sprintf("SELECT email, location FROM accountinfo WHERE username = '.$username.'", mysql_real_escape_string($username), $con); $result = mysql_query($query); $data = mysql_fetch_array($result); $email = $data['email']; $location = $data['location']; ?> <html> <head> <title>My Account<title> </head> <body> <p>Modify account information:</p> <form action="modifyaccount.php" method="post"> Username: <input type="text" readonly="readonly" value="<?php echo $username; ?>" /><br /> Password: <input type="password" name="password" id="password" /><br /> Email: <input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br /> Location: <input type="text" name="location" id="location" value="<?php echo $location; ?>" /><br /> <input type="submit" value="Modify" /> </form> </body> </html>
  6. Do you mean something like this: $query = sprintf("select email from userinfo where username='%s' ", mysql_real_escape_string($username)); $locquery = sprintf("select location from userinfo where username='%s' ", mysql_real_escape_string($location)); $result = mysql_query($query); $locresult = mysql_query($locquery); $email = mysql_fetch_array($result); $location = mysql_fetch_array($locresult); while($result=mysql_query($query)) { $email = $row['email']; }; while($locresult=mysql_query($locresult)) { $location = $row['location']; }; I get this error when I use the code above: Parse error: syntax error, unexpected T_VARIABLE in /Library/WebServer/Documents/MDR/myaccount.php on line 25 Line 25 is the while loop again.
  7. I'm having a lot of trouble displaying a value from a database in one of my input fields. My code is: <?php session_start(); print "<pre>";print_r($_SESSION);print "</pre>"; ?> <html> <head> <title>My Account<title> </head> <body> <?php $con = mysql_connect("localhost", "admin", "adminpass") or die("Could not connect to database"); $database = mysql_select_db("db") or die("<br />Could not select database"); $username = $_SESSION['username']; $query=sprintf("select email,location from accountinfo where username='%s'",mysql_real_escape_string($username)); $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $email=$row['email']; $location=$row['location']; } ?> <p>Modify account information:</p> <form action="modifyaccount.php" method="post"> Username: <input type="text" readonly="readonly" value="<?php echo $username; ?>" /><br /> Password: <input type="password" name="password" id="password" /><br /> Email: <input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br /> Location: <input type="text" name="location" id="location" value="<?php echo $location; ?>" /><br /> <input type="submit" value="Modify" /> </form> </body> </html> and the error I get is: Parse error: syntax error, unexpected T_VARIABLE in /Library/WebServer/Documents/MDR/myaccount.php on line 27 Line 27 is basically the whole while loop.: while($row = mysql_fetch_array($result)) { $email = $row['email']; $location = $row['location']; } What am I doing wrong? Thanks in advance!
  8. If you didn't modify anything, then your host probably did something, like change their php.ini file. Ask them..
  9. Thanks for the reply but I got an error: Fatal error: Call to undefined function  mysql_query() in ........... on line 8 When I removed the single quotes from $_REQUEST['delete'] and changed the query to all lowercase, that error was gone. Instead I was left with the original error: Use of undefined constant 'delete' - assumed 'delete' in .......... on line 8 Any ideas?
  10. select * from mytable where userid='SAMEUSERIDHERE'; Is that what you were looking for?
  11. I was reading about mysql_escape_strings and how they're much more secure than just calling a variable using $_POST. I tried it out in my code but I always get an error saying: Use of undefined constant 'delete' - assumed 'delete' in .......... on line 9 How do I fix this error? This is my code $delete = mysql_query("delete from mytable where user='".mysql_escape_string($_REQUEST[delete])."'",$c); $delete; To simplify reading, the code is: where user = quote double-quote . mysql_escape_string($_REQUEST[delete]). double-quote quote double-quote I also have another question. How do I store timestamps in my database? When I'm updating/inserting a new entry I just put ' ' for the value of timestamp but it doesn't work. Thanks in advance!
  12. I want to create a script that submits information on a web site (thats not mine). I want to put some text in the textarea field and then submit the form. This is somewhat related to programs that automatically post a preset comment on MySpace pages. I want to do exactly what those programs do but not on MySpace. Does this clarify it a little bit?
×
×
  • 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.