question about php and sql
question about php and sql
dont now if you now, when you send somthing with normal post, thei give you a recipe with a tralink number right ... well i am wonderig if it is posible to make a script with a data base, that for exemple, with a web form type in that number wich is normali here in spain 13 digit long, it will generate you a new one but diferent like "ta2-0123456789" , and i need it to staore the post office number and the random generated one to, so when i lock at it a now this number is for this code?
can this by made with the normal INSERT INTO .. thing or thoes requere someting alse??
P.S: sorry for the looong post
can this by made with the normal INSERT INTO .. thing or thoes requere someting alse??
P.S: sorry for the looong post
Re: question about php and sql
I don't see why not. What are you actually trying to do though ?ta2shop wrote:can this by made with the normal INSERT INTO .. thing or thoes requere someting alse??
Also as this is an SQL question, moved to the SQl forum
Re: question about php and sql
well it is a bit hard for my to explin it so i will start with the html form , i thik a can explain it better like so.
Re: question about php and sql
ok, got stuk on this.
i dont even now how to explain this.
i made the table and the form, it has 2 fields, one for inserting the postal code, and an odher wher the randome code will by displayed.
a do not now how to do the php part so that it will display in that place when the button is presed.
the codes!
html
thanks.
i dont even now how to explain this.
i made the table and the form, it has 2 fields, one for inserting the postal code, and an odher wher the randome code will by displayed.
a do not now how to do the php part so that it will display in that place when the button is presed.
the codes!
html
<div id="wrapper"> <div id="top"> Generate a Code! </div> <div id="form"> <form action="index.php" method="post"> <table align="center" border="0" cellpadding="2" cellspacing="2"> <tr align="center"> <td>Postal Code</td> <td>Random Generated Code</td> </tr> <tr align="center"> <td><input type="text" name="postal" size="13" class="field" /></td> <td><input type="text" name="random" size="13" class="field" value="<?php echo $random; ?>" /></td> </tr> <tr align="center"> <td colspan="2"><input type="submit" name="generate" value="Generate" class="btn" /></td> </tr> </table> </form> </div> </div> <div id="lowbox"> <div id="top2"> Serch the Results! </div> </div>i havent made the php part becouse i do not now how
thanks.
Re: question about php and sql
well if you want random numbers you can use the mt_rand function. Or see my video on a random password function.
Re: question about php and sql
i already viewd your video, and i am planing on using the
how to get the random number and how to display it in the input field?
rand(0123456789,9876543210);the problem is i dont now how to do it.
how to get the random number and how to display it in the input field?
Re: question about php and sql
Pretty simple. You store it in a variable and display that variable.
<?php $rand = rand(0. 9); // or whichever numbers you want ?> <input type="text" value="<?php echo $rand; ?>" />
Please check out my CodeCanyon items.
Re: question about php and sql
i now that , but first i have to type the postal code, and by hiting the gebnerate btn, it will give my the random number in that input field.
and i alsow need to store them both in the DB so i will now witch random code beloncs to what postal code.
and i alsow need to store them both in the DB so i will now witch random code beloncs to what postal code.
Re: question about php and sql
Well do you need the user to be able to edit the random number ? If not you could just use the SQL...
INSERT INTO `table` (`post_code`, `random`) VALUES ('{$post_code}', {$rand});ie, generating the random number in the backend only,
Re: question about php and sql
i will by the only user, and i need the random code to give it to the customer, so hy can track his order.
Re: question about php and sql
ok ok i got somting ...
now the script gives you a randome code and it is biing stored in the DB, but i cant get it to display in the input field!
the php.
now the script gives you a randome code and it is biing stored in the DB, but i cant get it to display in the input field!
the php.
<?php $connect = mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("ta2shop") or die(mysql_error()); // form data $postal = $_POST['postal']; $random = 'TA2_'.rand(0123456789,9876543210); $date = date("Y-m-d"); if(isset($_POST['generate'])) { if($_POST['postal']) { $query = mysql_query("INSERT INTO postal_codes VALUES('','$postal','$random','$date')") or die(mysql_error()); echo'<center>Succses, your traker code is: '.$random.' </center>'; } else { echo"<center>You must provide a postal code!</center>"; } } ?>any sugestions.
Re: question about php and sql
to display it into a input field just do the following:
<input type='text' name='random' value='<?php echo $rand; ?>'
Re: question about php and sql
i alreadi did!Carbine wrote:to display it into a input field just do the following:<input type='text' name='random' value='<?php echo $rand; ?>'
<form action="index.php" method="post"> <table align="center" border="0" cellpadding="2" cellspacing="2"> <tr align="center"> <td>Postal Code</td> <td>Random Generated Code</td> </tr> <tr align="center"> <td><input type="text" name="postal" size="13" class="field" /></td> <td><input type="text" name="random" size="13" class="field" value='<?php echo $random; ?>' /></td> </tr> <tr align="center"> <td colspan="2"><input type="submit" name="generate" value="Generate" class="btn" /></td> </tr> </table> </form>and still nothing
Re: question about php and sql
I don't know if this will do anything but change:
'<?php echo $random; ?>'to:
"<?php echo $random; ?>"Sometimes the kind of quotation marks have an effect, that's the only help I can give till a professional comes on and replys
Re: question about php and sql
Does it need to be displayed in the input field if the user is told the code afterwards anyway
Re: question about php and sql
Yeah, I was kind of wondering that? If you mean as soon as they press generate and it does it without reloading the page, then you might want to look into javascript.
Re: question about php and sql
god why am i soo stupid????
a was thinking about the design, but that is not important right now .
anyway i tried to add a if thing to check if the postal number is alreadi in the DB, and it prints a error.
any ideas:
a was thinking about the design, but that is not important right now .
anyway i tried to add a if thing to check if the postal number is alreadi in the DB, and it prints a error.
any ideas:
<?php $connect = mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("ta2shop") or die(mysql_error()); // form data $postal = $_POST['postal']; $random = 'TA2_'.uniqid(rand(0123456789,9876543210)); $date = date("Y-m-d"); if(isset($_POST['generate'])) { if($_POST['postal']) { $query = mysql_query("INSERT INTO postal_codes VALUES('','$postal','$random','$date')") or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { if($row['postal']!= $postal) { echo'<center>Succses, your traker code is: '.$random.' </center>'; } else { echo $random .'Already in Use'; } } } else { echo"<center>You must provide a postal code!</center>"; } } ?>thanks
Re: question about php and sql
Well, if you meen to see if the postal is already in use before it is submitted, and if it is in use don't submit the information, I'd do it this way for me:(P.S if it doesn't work, tell me. I just quickly write that, and don't have the databases to test it)
<?php $connect = mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("ta2shop") or die(mysql_error()); // form data $postal = $_POST['postal']; $random = 'TA2_'.uniqid(rand(0123456789,9876543210)); $date = date("Y-m-d"); if (isset($_POST['generate'])) { if($_POST['postal']) { $check = mysql_query("SELECT * FROM postal_codes WHERE '$postal'=postal"); $numrows = mysql_num_rows($check); if ($numrows>=1) die("Postal code has already been used"); else { $query = mysql_query("INSERT INTO postal_codes VALUES('','$postal','$random','$date')") or die(mysql_error()); echo "<center>Success, your tracker ID is:".$random."</center>"; } } else echo "<center>You must provide a postal code!</center>"; } ?>
Re: question about php and sql
The above method is correct, although it would be better to use the mysql COUNT() function.
also
also
$query = mysql_query("INSERT INTO postal_codes VALUES('','$postal','$random','$date')") or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { if($row['postal']!= $postal) { echo'<center>Succses, your traker code is: '.$random.' </center>'; } else { echo $random .'Already in Use'; } }this is wrong, an INSERT query does not work in the same way as a SELECT, ie you cannot fetch its result.