
thaidomizil
Members-
Posts
63 -
Joined
-
Last visited
Never
Everything posted by thaidomizil
-
Hello, i'm trying to query mysql to show table contents, my code so far is this: mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM codes"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); to show content: <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"id"); $f2=mysql_result($result,$i,"code"); $f3=mysql_result($result,$i,"secret"); $f4=mysql_result($result,$i,"date"); $f5=mysql_result($result,$i,"ip"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> </tr> Now this shows all the content from the table, what i want to have is 2 scripts which should work like this: Script1 to show table contents: ID1, ID2, ID4, ID5, ID7, ID8 and so on. Script2 to show table contents: ID3, ID6, ID9 and so on. Basically one that shows only every 3rd and skips 1 and 2, and another one that skips every 3rd. Is this possible ? Thanks !
-
Check for duplicate entries - mysql insert
thaidomizil replied to thaidomizil's topic in PHP Coding Help
I mean there needs to be one more if statement, to print the message 'duplicate entry', now there's one for code inserted and one for code invalid (if the code is not 19 digits and does not start with 5541258), so i would need another one that says duplicate entry instead of code inserted (since it is a valid code). Or not ? -
Check for duplicate entries - mysql insert
thaidomizil replied to thaidomizil's topic in PHP Coding Help
Oh okay, now it makes sense. Could you answer me one more question? How can i insert another if statement in the case that a duplicate was found, like: if duplicatefound print 'your code is being checked already, please wait' Thanks ! -
Check for duplicate entries - mysql insert
thaidomizil replied to thaidomizil's topic in PHP Coding Help
Hello, Thanks for the Code, this looks like it checks for all values is this correct ? how would i modify it to only check for the value 'code', this is the only one that has to be unique in the DB. For 'secret' for example, it's ok if there's a duplicate. -
Hello, i am inserting some form data into my mysql db, i happen to get some duplicates so i want to check first if the entry exists already before i insert. my current code: <?php if(isset($_POST['submit'])) { ?> <?php if (strlen($_POST['code']) == 19 && substr($_POST['code'],0,7) == '5541258') { mysql_query("INSERT INTO table(code,secret,ip,date) VALUES('$_POST[code]','$_POST[secret]','$_SERVER[REMOTE_ADDR]',CURDATE())"); Print "<font color='green'>The code will be checked now</font>"; } else { Print "<font color='red'>The code is invalid</font>"; } ?><?php } ?> I would like to use the value 'code' to check if the entry exists, that one is unique for each entry. How would i do that ? Thanks !
-
I changed the query line, the result is the same, no more specific error is given.
-
Hello i want to fetch the content from my MySQL db for one table and show it on a page, i'm using this code: <?php include("inc/connect.php"); ?> <?php $result = $_REQUEST['result']; ?> <?php $query = mysql_query("select * from listtest order by id asc"); while($result = mysql_fetch_array($query)) { ?> <tr> <td><?php echo $result['id']; ?></td> <td><?php echo $result['code']; ?></td> <td align="center"><a href="edit.php?id=<?php echo $result['id']; ?>">View</a></td> <td align="center"> </td> </tr> <?php } ?> it's throwing me this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in 32qgtf.php on line 30 What am i doing wrong ? /Edit: line 29/30 is the mysql query / fetch.
-
Validate numbers before inserting into MySQL
thaidomizil replied to thaidomizil's topic in PHP Coding Help
Thanks xyph, i just noticed my button name wasn't set to submit only the id. Also, i just saw that this isn't working: if (strlen($_POST['test']) != 19 This is working fine though && substr($_POST['test'],0,7) != '1234567') any idea? -
Validate numbers before inserting into MySQL
thaidomizil replied to thaidomizil's topic in PHP Coding Help
I don't want to open a new thread for this, your code works fine, i'm trying to put if(isset($_POST['submit'])) infront, my final code looks like this: if(isset($_POST['submit'])) { if (strlen($_POST['test']) != 19 && substr($_POST['test'],0,7) != '1234567') { echo "wrong code"; } else { mysql_query("INSERT INTO table(code) VALUES('$_POST[test]')"); Print "Your table has been populated"; }} now the script doesn't do anything, i guess i set the curly braces wrong or can i not put 2x if behind each other ? can you enlighten me on this please -
Validate numbers before inserting into MySQL
thaidomizil replied to thaidomizil's topic in PHP Coding Help
Works, thanks ! -
Hello, i'm trying to server-side validate input from POST to insert it into mysql if the requirements for the insert are met. i was using jquery before but this isn't reliable at all, i want the data to get inserted into mysql only if the length is 19 chars and only if it starts with 3227580 the next 12 digits can be any number. So basically: IF chars=19 and data=3227580* insert into mysql -- else show error Thank you for help.
-
Sorry that i have to bother you again, i tried using the last piece of code you provided, i'm getting this error: Parse error: syntax error, unexpected ';', expecting ')' in /Applications/XAMPP/xamppfiles/htdocs/test.php on line 15 Edit: Hey, it works just the way i really needed it too ! Thanks to you guys !
-
mjdamato, i'm building up the page with the divs currently, so to make them show with your piece of code i would have to hide them first and afterwards bring them back to a visible state with your code , i guess? Thanks for your help, to both of you, it's very much appreciated.
-
Hello, i have a form with a dropdown selection with the values 1 to 8, on the submit page i have another form which has 8 divs, now i want to show only a number of those divs based on the selection of the dropdown from the previous page. example: 1st page dropdown value is 4, form gets submitted, on the next page show div 1 & 2 & 3 & 4, and so on. Is this possible? /Edit: i just thought about it again and i think i could use <?php $dropdown=$_POST['dropdown']; if($dropdown=="1") { ?> around the div tags, but then i would have to make 8 forms and take out 1 div one by one based on the dropdown selection, or is my thinking wrong?
-
That error means you are trying to create a function that already exists. It looks like in ver 5.3 of PHP there is an actual function called date_diff(). Doh! If you have version 5.3 you can just use that function. If not, rename the function I provided to something else. EDIT: The fact that you got that error would mean that you are using a version of PHP that has that built in function, or possibly you put the code in a loop on your page. Even if you do have a version of PHP with that built-in function you need to make sure the server(s) you will be deploying to will support it as well. How about your 2nd example, would that work out of the box, like so: <?php function date_diff($firstDate, $lastDate) { return (int) ((strtotime($lastDate)-strtotime($firstDate))/86400)+1; } $dates = array( array('February 5, 2011', 'April 15, 2011'), array('March 15, 2011', 'May 19, 2011'), array('January 5, 2011', 'June 12, 2011'), array('August 20, 2011', 'August 25, 2011'), array('July 14, 2011', 'December 23, 2011'), array('December 15, 2011', 'January 20, 2012') ); foreach($dates as $datePair) { $startDate = $datePair[0]; $endDate = $datePair[1]; echo "There are " . date_diff($startDate, $endDate) . " day(s) between {$startDate} and {$endDate}<br>\n"; } ?> or not? I'm getting the same error there, can't i just put a break at the end of your first code to show me the result without looping endlessly ? There isn't any script on my side at all, all i want to do is get the result from date 1 to date 2 really :-) /Edit Sorry i didn't see your edit on your post, will phpinfo show me that somewhere ? /Edit 2 i renamed the function, it is working fine now ! Thank you !
-
mjdamato, thank you for the code, which i would want to use as it can use the month names for the dates. However i'm getting some errors here. Fatal error: Cannot redeclare date_diff() in /Applications/XAMPP/xamppfiles/htdocs/test/flug-und-hotel.php on line 92 i just copy pasted the code "as is" without changing anything about the dates yet. Would you please enlighten me how to implement it properly ? Thank you
-
Works like a charm, where's your donate button ? Thanks a bunch !
-
Hello, i appreciate that, i am quite the beginner with php though so i wouldn't know where to start, i take it i would just have to add another "$check" kind as in the script to specify the second date ? If you could point me in the right direction i would be grateful. Thanks for your effort.
-
That looks more like a countdown ? Premiso, i guess your code does work, could you hint me in the right direction how i could convert my current date format to the format needed for that script ? the jquery code for that datepicker is all hieroglyphs to me, i can't find out how to change the date format. Thank you
-
Hi there, i am using a form with 2 inputs which are equipped with a datepicker: Date 1 & Date 2, is it possible to calculate how many days are there from Date 1 to Date 2 (including the selected ones) ? On my form the dates are in this format: September 08, 2011 (i guess i can change that to numeric only, if that helps) Tamper data shows them getting posted like this: September+14%2C+2011 Any help / hints will be appreciated !
-
Need help to make a small adjustment on script
thaidomizil replied to thaidomizil's topic in Javascript Help
I got it working now, removed style="display:none;" from my <li> where the select is sitting inside. Thank you so much! -
Need help to make a small adjustment on script
thaidomizil replied to thaidomizil's topic in Javascript Help
Liam, thank you for your quick reply, i've tried the code quick on a blank page to make sure it works, which it does, thank you for that ! Now i've tried to implement it into my site, i don't know what exactly is the problem but it won't work there, the select is populated through js aswell, does that make any difference ? I also submitted my form with tamper data running to make sure the values and the select name is correct, which they are, but still it won't work. What am i missing ? -
Hello, i found this script that changes the action of a form based on a dropdown selection, i tried to make it work with my form but it won't work. Can someone help me out here please? This is the code: $("#bookingType").change(function() { var action = $(this).val() == "people" ? "user" : "content"; $("#book-travel-form").attr("action", "/search/" + action); }); Changing the form and select id's isn't the problem, i've done that already, my dropdown has the Values F and FH, what i need is, if F is selected change form action to flug.php if FH is selected change it to flugandh.php, there is also this: ("action", "/search/" + action); which adds a subfolder infront of the url, i tried to remove it but that didn't work too well thank you !
-
Hello, is it possible to define the next page after a form submission based on a value from the form ? Example: My form has a dropdown Value 1: Flight Value 2: Flight + Hotel now i'm trying to achieve that if value 1 is chosen after submission it goes to flight.php, if value 2 it should go to flighthotel.php or am i heading into the completely wrong direction here and over complicating things ? Thanks in advance !
-
Hello, i'm trying to show a picture based on the value that was selected from a previous pages dropdownbox, i'm receiving the text value just fine using <?php echo $_POST["dropdown"]; ?> on the next page. So lets say i have A B C in the dropdown box, for selection A i want to show A.jpg on the next page, B - B.jpg and so on. How can i accomplish this ? Thanks for your help, as i'm quite a beginner