[Solved] Sql update statement for unique field

If you update (or insert into table), and the new inserted/updated col1 value is already being used on some row, your query should fail with unique constraint violation error. Make your application handle this error/exception properly and there’s really no need to check the existence of this value before the update/insert. The less queries your … Read more

[Solved] Minus a day in DATEDIFF query

I just change my check out string from this $check_out = date(“Y-m-d” strtotime($_POST[‘co’]) to $check_out = date(“Y-m-d”, strtotime(‘-1 day’, strtotime($_POST[‘co’]))); And remove the DATEDIFF() & ABS() in the query like this below SELECT r.*, rr.rid, SUM(rr.rate) as totalsum, rr.sdate, rr.edate FROM rooms r LEFT JOIN rates as rr ON r.id=rr.rid WHERE rr.sdate >= :ci AND … Read more

[Solved] error in mysql query string [closed]

Let me convert your code to MySQLi at least. MySQL is already deprecated. <?php /* ESTABLISH CONNECTION */ $connect=mysqli_connect(“YourHost”,”YourUsername”,”YourPassword”,”YourDatabase”); /* REPLACE NECESSARY DATA */ if(mysqli_connect_errno()){ echo “Error”.mysqli_connect_error(); } /* REPLACE THE NECESSARY POST DATA BELOW AND PRACTICE ESCAPING STRINGS BEFORE USING IT INTO A QUERY TO AVOID SOME SQL INJECTIONS */ $uname=mysqli_real_escape_string($connect,$_POST[‘username’]); $pass=mysqli_real_escape_string($connect,$_POST[‘password’]); $query = … Read more

[Solved] Sql update statement for unique field

The SQL UPDATE statement is a powerful tool for updating data in a database. It can be used to update a single field or multiple fields in a table. When updating a unique field, it is important to ensure that the value being updated is unique and does not already exist in the table. This … Read more

[Solved] PHP/MySQL text and reference [closed]

first, create 3 columns. id, name, then the url. then output it like this <a href=”https://stackoverflow.com/questions/25077589/$url”><p>$name</p></a> But I would like to tell you frankly that this question is very basic, this forum may hinder you from learning if you did not challenge yourself. 🙂 2 solved PHP/MySQL text and reference [closed]

[Solved] Copy current record to another table with php and mysql

Do you mean something like this? $sql = “INSERT INTO prueba (nombre) VALUES ($nombre) WHERE id = ‘$id'”; 1)use mysqli instead of mysql 2) instead of $row[0] use $row[nombre_ID] (if thats what its called) 3) do the same for $row[1] to like $row[nombre] 4) change mysql_fetch_row($query) to mysqli_fetch_array($query,MYSQLI_ASSOC) 6 solved Copy current record to another … Read more

[Solved] How do you check for matching value in third column based on distinct combinations of other two columns?

You can group by building, location for the rows where object in (‘WALL’, ‘WINDOW’): select building, location, ‘FLAG’ action from tablename where object in (‘WALL’, ‘WINDOW’) group by building, location having count(distinct object) < 2 The condition count(distinct object) < 2 in the having clause returns combination of building, location where ‘WALL’ and ‘WINDOW’ do … Read more

[Solved] Symfony output of data in date grouped tables

example from doctrine document: The INDEX BY construct is nothing that directly translates into SQL but that affects object and array hydration. After each FROM and JOIN clause you specify by which field this class should be indexed in the result. By default a result is incremented by numerical keys starting with 0. However with … Read more

[Solved] php mysql car parking query [closed]

Your query is referencing return_date, which isn’t a column in the airport_car_parking table. As for the logic of the query, you want to make sure that the $departure_date isn’t between any row’s departure_date or arrival_date. I would recommend the following query – $chk_date_sql=”SELECT * FROM airport_car_parking WHERE ‘$departure_date’ BETWEEN departure_date AND arrival_date;”; And then that … Read more

[Solved] Is this PHP code vulnerable to SQL injection? [duplicate]

Yes, it’s vulnerable. You’re talking values directly from user input and placing it into your query. You should look at mysql_real_escape_string, or (preferably) use MySQLi which provides parameterised queries. SQL injections are caused by user data being injected as SQL code instead of data. The only true way to secure a query is to use … Read more