
tomhoad
Members-
Posts
52 -
Joined
-
Last visited
Never
Everything posted by tomhoad
-
silkfire - your solution worked. Many thanks!
-
I'm importing a CSV using the fgetcsv() function, which is working all good. However, when I take a look at the data in the database, I see black diamonds with question marks. This isn't too much of an issue when echoing the data back out again, as they don't appear, but when I want to use one of the CSV fields as a MySQL date, it isn't recognised as a date and is stored as 0000-00-00. e.g. I think this issue is something to do with encoding of the CSV? Can anyone offer any advice? If it helps here is my import script, and the encode type is ASCII according to mb_detect_encoding <?php include 'config.php'; include 'opendb.php'; ini_set("auto_detect_line_endings", true); $row = 0; $tmpName = $_FILES['csv']['tmp_name']; if (($handle = fopen($tmpName, "r")) !== FALSE) { $num = count($data); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $noQuotes = str_replace("\"", '', $data); $originalDate = $noQuotes[1]; //$delivery_date = date('Y-m-d', strtotime($originalDate)); $parts = explode('/', $originalDate); $delivery_date = $parts[2] . '-' . $parts[1] . '-' . $parts[0]; $row++; $import="INSERT into dispatch (delivery_note_number, delivery_date, dispatch_date, customer_delivery_date, delivery_line, produce, variety, quantity, pallets, count, depot, customer, grower, haulier, status) values ('$noQuotes[0]', '$delivery_date', '$noQuotes[2]', '$noQuotes[3]', '$noQuotes[4]', '$noQuotes[5]', '$noQuotes[6]', '$noQuotes[7]', '$noQuotes[8]', '$noQuotes[9]', '$noQuotes[10]', '$noQuotes[11]', '$noQuotes[12]', '$noQuotes[13]', '$noQuotes[14]')"; echo $import; mysql_query($import) or die(mysql_error()); } //header("location:list_dispatch.php?st=recordsadded"); fclose($handle); } ?>
-
Still the same - I have a 'title' column in both tables, perhaps that's where the problem lies?
-
What's The Best Way To Export a Database? (to store in an offline location)
tomhoad replied to joeyjj's topic in MySQL Help
I generally backup as a CSV as I consider that the most versatile format - however I'd be interested in a more authoritative answer as well! -
Thanks for that. I have made some progress but I am still struggling slightly. Believe me I've worked on this for a few hours now and can't crack it!!! Maybe I'm just too simple! My php now looks like so: $result = mysql_query("SELECT * FROM promo JOIN items ON promo.id = items.promo_id WHERE promo.id='$promo_id'") or die('Error : ' . mysql_error()); while($row = mysql_fetch_array($result)) { echo "<p>".$row['promo.title']."</p>"; echo "<p>".$row['description']."</p>"; echo "<p>".$row['filename']."</p>"; } The outcome is: I don't seem to be able to access the Promo Title at all ? Also it's repeating and I can sort of see why from the PHP - what do you recommend to just get my desired outcome (OP).
-
I am not too experienced with MySQL and I've read a few tutorials on JOIN and UNION but can't get my head around it to be honest - can someone help me out please? I'm fairly sure I need to combine these queries to get my desired result... I have 2 tables, one called promo and another called items. What I want is... This is a Promotional [title] I am the promotional description for this promo! [description] Items in this promotional are: - Item 1 - Item 2 - Item 3 Code so far: $result = mysql_query("SELECT * FROM promo WHERE id = '$promo_id'") or die('Error : ' . mysql_error()); while($row = mysql_fetch_array($result)) { echo "<p>".$row['title']."</p>"; echo "<p>".$row['description']."</p>"; } $result = mysql_query("SELECT * FROM item WHERE promo_id = '$promo_id'") or die('Error : ' . mysql_error()); while($row = mysql_fetch_array($result)) { echo "<p>".$row['filename']."</p>"; } Using MySQL 5. Thanks for your help
-
Hi I would like to do some error reporting using GET. For example I have: The URL: www.example.com/index.php?st=not_registered $st = mysql_real_escape_string($_GET['st']); if ($st = "not_registered") {echo "<p>You are not already registered!</p>";} if ($st = "already_registered") {echo "<p>That email is already registered!</p>";} if ($st = "login_fail") {echo "<p>You are not registered! Please enter your email below.</p>";} However, that seems to ignore the value of $st and just print all the options? Thank you for your help.
-
Hi there, I'm thinking of designing a site that will allow users to sign up and have their own unique 'control panel'. I just need some pointers on the logic behind this design, specifically: How can I create a 'unique' area for each user upon signup Is it possible to link that area to a subdomain e.g. username.domain.com How would the database design look? Would you recommend a database per user, or a table per user, etc. Thanks a lot for any help, I really appreciate it. I've always had excellent responses through this community so thanks for that as well. Cheers
-
Sorry I've replaced the serialized data as it's personal data!
-
Hi there. I have some data in my database that is serialized. e.g. a:2:{i:0;s:9:"Test";i:1;s:4:"Another Test";} I'm unsure how to use unserialize to convert it into a string in the format: Test, Another Test Currently I have: $radio_array = unserialize($radio); foreach ($radio_array as $i => $value) { print($radio_array[$i]); } But that throws errors. Any help appreciated, thanks.
-
Ok great, thanks a lot. I assume by security issues you mean not sanitizing the Get data? Also, the sort now works for all fields except the date of birth, and I'm pretty sure this is because this is stored as a timestamp - can you advise on how to successfully be able to sort that? Thanks!
-
Hi, I can't see where this script is failing. It doesn't appear to sort correctly (just randomly). <table width="200" border="1"> <tr> <td><b>Email <a href="view_members.php?sort=email">[sort]</a></b></td> <td><b>Name <a href="view_members.php?sort=name">[sort]</a></b></td> <td><b>Date of Birth <a href="view_members.php?sort=dob">[sort]</a></b></td> <td><b>Favourite Artist <a href="view_members.php?sort=fav_artist">[sort]</a></b></td> <td><b>Favourite Genre <a href="view_members.php?sort=fav_genre">[sort]</a></b></td> </tr> <?php if(isset($_GET['sort'])) { $query = "SELECT id, name, email, fav_artist, fav_genre, FROM_UNIXTIME(dob, '%e/%c/%Y') as dob FROM users ORDER BY '{$_GET['sort']}'"; $result = mysql_query($query) or die('Error : ' . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $row['id']; $name = $row['name']; $email = $row['email']; $dob = $row['dob']; $fav_artist = $row['fav_artist']; $fav_genre = $row['fav_genre']; ?> <tr> <td><?php echo $email;?></td> <td><?php echo $name;?></td> <td><?php echo $dob;?></td> <td><?php echo $fav_artist;?></td> <td><?php echo $fav_genre;?></td> </tr> <?php } } ?> Any help appreciated
-
[SOLVED] What's wrong with this PHP SQL Query?
tomhoad replied to tomhoad's topic in PHP Coding Help
Very obscure 'solved' link bottom left :-\ -
[SOLVED] What's wrong with this PHP SQL Query?
tomhoad replied to tomhoad's topic in PHP Coding Help
how do I mark as solved? -
[SOLVED] What's wrong with this PHP SQL Query?
tomhoad replied to tomhoad's topic in PHP Coding Help
You were almost there: $search = "SELECT * FROM users_songs WHERE users_songs_user_id = '$user_id' AND users_songs_song_id = '$song_id'"; Thanks a lot nuttycoder!! -
[SOLVED] What's wrong with this PHP SQL Query?
tomhoad replied to tomhoad's topic in PHP Coding Help
All the 'gets' are working and pulling in the correct variables. -
Hi there. My database table is as follows: users_songs_user_id | users_songs_songs_id ------------------------------------------------------- [email protected] | 1 [email protected] | 2 My code is as follows: $song_id = mysql_real_escape_string($_GET['song_id']); $user_id = mysql_real_escape_string($_GET['user_id']); $user_id = urldecode($user_id); $search = "SELECT users_songs_song_id FROM users_songs WHERE users_songs_user_id = '$user_id'"; $result = mysql_query($search) or trigger_error('Error: ' . mysql_error()); $numrows = mysql_num_rows($result); if($numrows < 1) { $query = " INSERT INTO users_songs (users_songs_user_id, users_songs_song_id) ". " VALUES ('$user_id', '$song_id')"; mysql_query($query) or die('Error : ' . mysql_error()); print "Success!"; } else { print "Fail"; } The $search SQL query appear to always return '1' as the numrows, and therefore I always get 'Fail'. I can't work out why - any help very much appreciated! Cheers
-
Ignace, do you have any ideas on this. I really appreciate your help so far
-
header("Content-Type: audio/mpeg"); ... has the same effect.
-
Cool, thanks Ignace, I will definitely bear that in mind when building this thing! Just want to get it up and running for the moment. I am having some problems actually serving the mp3 now. I have tried: ... but all I get is a load of jargon in the browser window and the browser hanging. Have looked into fread() but not sure how to use it. Any ideas on best way to force the download?
-
Chances are the download will feature artwork, lyrics, mp3 etc. so I may just bundle that all into a zip file. I know if I was the user I would rather download a single zip file than 4 or 5 seperate files. This would also keep the application as simple as possible.
-
At the moment I am focusing on one-email, one-download. However, there is the potential for more mp3s to be added - would that be a problem?
-
Ok, so I'm getting there with this, here's my code so far: submit.php <?php //open database include 'config.php'; include 'opendb.php'; //get email from form $email=$_POST['email']; //salt $salt="H67R"; //encrypt email using md5 hash $enc_email=md5($email.$salt); if ( the token doesnt already exist in the database ) { $query = " INSERT INTO records (email, used) ". " VALUES ('$enc_email', 0)"; mysql_query($query) or die('Error ,query failed'); print "Download link:<br><br>\n"; print "<a href='download.php?token=$enc_email'>here</a>\n"; } else { print "You already downloaded!" } //close database include 'closedb.php'; ?> download.php <?php //get token $token = $_GET['token']; //path to file $secretfile = "../music.mp3"; //if valid, output if( the token exists in the database and the used value is 0) { readfile($secretfile); $query = "UPDATE records SET used = '1' WHERE email = '$token'"; mysql_query($query) or die('Error : ' . mysql_error()); } else { print "Your token is bad!"; } ?> I just need to replace the 'if' statements pseudo code with actual code, but I'm not sure how to query the database to check if it already exists etc. Very simple but I'm just starting out here and appreciate your patience. The 'used' value is a boolean that updates to 1 once the url has been used, so when we check the token we can see if it's been used or not. Thank you for your help thus far!
-
Again, fantastic. What a great forum! Thanks a lot guys
-
That's awesome, thanks so much. If anyone else has any ideas, please continue to post.