I'm just happy I got it right And I haven't quite got round to using the COUNT function yet, I'd rather research it first than just use it and hope for the best And I cba to research it atmjacek wrote:The above method is correct, although it would be better to use the mysql COUNT() function.
question about php and sql
Re: question about php and sql
Re: question about php and sql
thanks guys, it is working now with carabine's method, lock:
<?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']) { $check = mysql_query("SELECT postal_code FROM postal_codes WHERE '$postal'=postal"); $numrows = mysql_num_rows($check); if ($numrows!=1) echo"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>"; } ?>but now sql prints this:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\trabajos\ta2shop - tienda\administracion\postal-code\index.php on line 46
Re: question about php and sql
Check the query in the '$check' variable and change it to your database details. I didn't know what the fields were, but there is something wrong with the query and that's most likely it.
Re: question about php and sql
I was thinking more of
WHERE `postal` = '$postal_code'Unsure on the column names though
Re: question about php and sql
The other way round works on my scriptsjacek wrote:I was thinking more of
WHERE `postal` = '$postal_code'Unsure on the column names though
And it would be
WHERE 'postal_code' = '$postal'If you look at the query in the above post by him that looks right.
Re: question about php and sql
it is ok, it worck now with no errors.
now i will meke the final check , i hope! the check to see if it is < then 13 or > then 13.
thanks for the help.
now i will meke the final check , i hope! the check to see if it is < then 13 or > then 13.
thanks for the help.