mattichu
-
Posts
38 -
Joined
-
Last visited
Posts posted by mattichu
-
-
Hi Probably a simple solution to this:
I need to check if a randomly generated string is already in the database, if it is I need to generate another one until a unique one is found.
How do I go about implementing this?
I have the following code:
<?php $name=$_POST['name']; $mobile=$_POST['mobile']; $email=$_POST['email']; $name=ucwords($name); $email=strtolower ($email); function randStrGen($len){ $result = ""; $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; $charArray = str_split($chars); for($i = 0; $i < $len; $i++){ $randItem = array_rand($charArray); $result .= "".$charArray[$randItem]; } return $result; } $randstr = randStrGen(5); $code=$randstr; $servername = "********"; $username = "******"; $password = "******"; $dbname = "******"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM freedrink WHERE code='$code'"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Need a loop somehow }
Thanks!
-
Hi!
Im using the following code to change an image from a tick to a cross:
<script type="text/javascript"> imgs=Array("/new4/images/allow.png","/new4/images/deny.png"); var x=0; function change() { document.getElementById("bob").src=imgs[++x]; if (x==1) { x=-1; } } </script> <img id="bob" height="20" width="20"src="/new4/images/allow.png" onmousedown="change()">
How would I go about storing the option the user has left it on in an SQL database?
any help much appreciated!
-
I'm a total noob with java script and have found some code to open an upload dialogue when a link is clicked.
How/where do I insert the code which will actually upload the file to the server?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <script type="text/javascript"> $(function() { $('#uploadFile').click(function(e) { $('#fileUploadField').click(); e.preventDefault(); }); }); </script> <input type="file" name="something" style="display: none" id="fileUploadField" /> <a href="" id="uploadFile">Upload File</a>
Any Help much appreciated
-
nice one, and how would I go about doing this?
-
after much googling I still can find a solution
Is it possible to update an sql database with the textbox value when its changed or no longer in focus?
cheers!
-
Thanks jcbones!
-
hello!
I have a page which uses some code from dot mailer.co.uk to add a users data into their address book, once that has been done I would like the page to redirect to a thank you page.
Problem is nothing after that code seems to process.
for example:
$addressbookid=****; $email = $email; $AudienceType="B2B"; $OptInType="Single"; $EmailType="Html"; $FirstName = $firstname; $LastName=$lastname; $Mobile = $mobile; $notes = "This person made a table booking" ; $keys = array("FIRSTNAME","LASTNAME","MOBILE"); $var1 = new SoapVar($FirstName,XSD_STRING,"string","http://www.w3.org/2001/XMLSchema"); //Create an instance of SoapVar for each one of the values $var2 = new SoapVar($LastName,XSD_STRING,"string","http://www.w3.org/2001/XMLSchema"); $var3 = new SoapVar($Mobile,XSD_STRING,"string","http://www.w3.org/2001/XMLSchema"); $values = array($var1,$var2,$var3); $Datafields = array ('Keys'=>$keys,'Values'=>$values); $contact = array ("Email"=>$email,"AudienceType"=>$AudienceType,"OptInType"=>$OptInType,"EmailType"=>$EmailType,"ID"=>-1,"DataFields"=>$Datafields,"Notes"=>$notes); $params = array ("username"=>$username,"password"=>$password,"contact"=>$contact,"addressbookId"=>$addressbookid); return $client->AddContactToAddressbook($params); echo "test";
the echo at the end doesn't do anything, any ideas why?
-
Hi I have a table:
------------------------------------------------------------------------------------------
ID | DATE | Staff1 | Staff2 | Staff3 | venue |
------------------------------------------------------------------------------------------
1 1st Jan 10-cl 11-cl OFF xx
2 2nd Jan 11-cl 10-cl 10-cl xx
3 3rd Jan 10-cl 11-cl OFF xx
4 4th Jan 11-cl 10-cl 10-cl xx
5 5th Jan 10-cl 11-cl OFF xx
6 6thJan 11-cl 10-cl 10-cl xy
How would I swap the contents in staff 1 and 2 AFTER the 2nd jan?
any help much appreciated!
^^
-
Thanks Psycho, exactly what I was after.
much appreciated!
-
heyy
I have a form which validates by posting the form to itself so that when the page reloads the values the user input are posted back into the text boxes.
How do I make it so that the posted drop down selection is the selected item on the reload??
-
I've changed the code to:
$dayoff=$_POST['dayoff']; $date=date("dS M Y",$dayoff);
But this gives: 31st Dec 1969
$dayoff outputs correctly
-
Hi,
Im posting a date in the format : dd/mm/yyyy
and am wanting to store it in a database as a string.
I'm using the following code:
$dayoff=$_POST['dayoff']; $dayoffst=strtotime('$dayoff'); $date=date('dS M Y',$dayoffst);
However when I echo the $dayoffst it doesn't return anything
any ideas?
-
Hi,
I have written a PHP clocking in system for staff to use. The user inputs their pin and the time they clocked in/out is recorded in an SQL database on the server.
Ive found that the browser (firefox) occasionaly gets stuck when a user presses enter (maybe a dodgy internet connection) and prevents anyone else clocking in until refresh is pressed.
Is there a way to store the data locally then upload it to the server every so often? or another way to fix this issue?
many thanks!
-
thankyou!
-
Hi!
the following code sucessfully outputs a timestamp.
$datealt=strtotime('2012-03-13 ,23:13:00');
The following however does not:
$datealt=strtotime('$date ,$hours:$minutes:00');
I have checked if the variables echo out and they do..
any clues much appreciated
x
-
ledge! cheers addict!
x
-
I get the following error:
with the following code:
$username="****"; $password="****"; $database="checkmyw_database"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query3="SELECT * FROM hours WHERE (out1<>'0' AND in1=='0' OR out2<>'0' AND in2=='0') && (date==$date)"; $result3=mysql_query($query3); $num3=mysql_numrows($result3); mysql_close(); if($num3==0){ $clockedout="true";} echo $clockedout;
Any ideas why
-
SOLVED
<? $username="****"; $password="*****"; $database="******"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="select username,rop, sum(totalcost) as totalcost, sum(totalhours) as totalhours from hours group by username"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ ?> <html> <table><td><?php echo $row['username']; ?></td><td><?php echo $row['rop'] ; ?></td><td><?php echo $row['totalhours'] ; ?></td><td><?php echo $row['totalcost'] ; ?></td> </table> </html> <? } ?>
many thanks guys!
-
fab ive got that to work in php myadmin but how do i output it as an HTML table?
x
-
Hi!
i have a table:
Day Username Rate Hours Shift Cost
--------------------------------------------------------------------
MON Matt 8.5 2 £17
MON Imogen 6 2 £12
MON Matt 8.5 1 £8.5
MON Imogen 6 1 £6
--------------------------------------------------------------------
Im trying to output a table that shows the total cost for each user.
like:
User Rate Hours Wage
----------------------------------------
Matt 8.5 3 £25.5
Imogen 6 3 £18
----------------------------------------
How would i go about doing this??
many thanks!
x
-
blonde moment many thanks!
-
hii
I have made some code that works out the difference between two timecodes. IE
Time 1 Time 2 Time2-Time1
1330613232 - 1330613545 = 313
Im wanting to express the difference in terms of hours.
313 as a time code is 00:06:49 but I want it to show 0.12 hours.
how would I achieve this?
x
-
Solved - Cheers guys!
x
-
The databse has it stored as a 'TIME'
Basic Loop Question
in PHP Coding Help
Posted
Hi Thanks that makes sense,
I am using the system to email unique voucher codes upon the submission of customer details.
I have chosen to append the database record ID to the beginning of the code so that they can never be the same.
Thanks for your help!