Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Im getting query error, im using the like LIKE sql function to search for the name submitted by the user.
But msqli_query is giving an error if i remove the LIKE function it works but doesn't works with the LIKE function
<!DOCTYPE html>
<html>
<head>
<title>Search Users</title>
</head>
<body>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"method="GET">
Name: <input type="text" name="name"></input>
<input type="submit" name="searchusers" value="Submit"></input> </br>
</body>
</html>
<?php require('connect.php');
$name = #$_GET['name'];
if ($_SERVER["REQUEST_METHOD"] == "GET")
{
$select123 ="SELECT username FROM users WHERE username LIKE ='%".$name."%'";
$check = mysqli_query($conn, $select123) or die("query error");
mysqli_num_rows($check) or die("Couldnt not find the Specified username");
}
?>
Please help
Remove = near keyword like :
$select123 ="SELECT username FROM users WHERE username LIKE '%".$name."%'";
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Please im trying to insert data from a table to another. the issue is that i find duplicate records in database when applying the code below:
<?php
include ('lib/connexion.php');
$id_article = $_GET['num'];
$requete = "Select * from products where product_id=$id_article";
$resultats = mysql_query ($requete);
if($resultats === FALSE) {
die(mysql_error()); // TODO: better error handling
}
?>
<html>
<head>
<title>APP crud</title>
</head>
<body>
<?php
while ($ligne =mysql_fetch_array ($resultats)){
$sql2 ="INSERT INTO panier (product_title, description, prix)
VALUES ('".$ligne[1]."','".$ligne[2]."','".$ligne[3]."' ) ";
mysql_query ($sql2) or die ('Erreur : ' .mysql_error());
$resultats2 = mysql_query ($sql2);
if($resultats2 === FALSE) {
die(mysql_error()); // TODO: better error handling
}
header('Location: panier.php');
?>
Supprimer
Modifier
Ajouter
Retour
<?php } ?>
</body>
<html>
Can someone tell me why this happens? thanks.
Making this as a community wiki (I've nothing to gain here, or wanting to gain) and pulled from comments to close this with:
Because, you're doing this twice: mysql_query ($sql2)
"Remove this line mysql_query ($sql2) or die ('Erreur : ' .mysql_error()); – devpro"
and
"Mysql_ is deprecated use mysqli_* or PDO – devpro"*
and
"you could also ALTER your column(s) as UNIQUE. That will guarantee that no duplicates ever gets inserted."
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So I'm trying to fetch a value from a table in my database into a placeholder for an html input element. Code is as follows:
<input type="text" name="timesats" placeholder="
<?php
include($_SERVER['DOCUMENT_ROOT'].'/paycheck/scripts/connect.php');
$user = $_SESSION['user'];
$sql = "SELECT timesats WHERE email='$user'";
$query= mysqli_query($dbc,$sql);
$result = mysqli_fetch_object($query);
echo($result);
?>
">
$dbc contains the values for connection.
I'm getting no errors so its really hard to debug. The value from the table is not null.
Try
<?php
include($_SERVER['DOCUMENT_ROOT'].'/paycheck/scripts/connect.php');
$user = $_SESSION['user'];
$sql = "SELECT timesats WHERE email='$user'";
$query= mysqli_query($dbc,$sql);
while ($obj = mysqli_fetch_object($query)) {
$ph = $obj->timesats;
}
?>
<input type="text" name="timesats" placeholder="<?php echo $ph; ?>"/>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have been struggling for about a week now and still have not got any results. I have read the following questions:
Unable to insert form data in MySQL database
Connection to database seems successful but INSERT INTO sends no data
PHP MySQL not inserting into database
https://askubuntu.com/questions/435746/unable-to-send-data-to-mysql-database-it-is-not-taking-by-my-php-code
I tried everything suggested in the above questions' answers. After reviewing my code, if you still think that the above questions' solution relates then please do tell.
My code -
connect.php -
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "practice_user";
// Create connection
$con = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($con->connect_error) {
echo "Connection failed: " . $con->connect_error;
}
else {
echo "Success";
}
//Insert data into database
$sql = "INSERT INTO simple_login (name,email) VALUES('{$mysqli->real_escape_string($_POST['name'])}','{$mysqli->real_escape_string($_POST['email'])}')";
$insert = $mysqli->query($sql);
if(!$insert)
{
echo $mysqli->error;
}
$mysqli->close();
register.html -
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="connect.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
As usual I am getting a "Successful" message for connection. Also it is not outputting any error message(if I have not appropriately tried to output insertion error in the given code, please do tell in the comments).
Thank you in anticipation.
I'll post this here, we all make mistakes so don't worry! As suggested your $mysqli function is undefined, you've stored your mysqli instance as the $con variable, so you should refer any mysqli functions on that.
Examine http://php.net/manual/en/mysqli.query.php for more information!
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
when attempting to connect to the database - connect, the following error is provided:Parse error: syntax error, unexpected ',' in C:\xampp\htdocs\newlogin\forgotpass.php on line 19
<form action="" method="POST">
your email: <br /><input ="text" name="email" size"30"/><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
$email= $POST['email'];
$submit =$POST['submit'];
//
-->$connect= ("localhost","root","black$23");
mysql_select_db ("login_site",$connect);
if ($submit) {
$email_check = mysql_query("SELECT * FROM users WHERE email='".$email."'");
$count=mysql_num_rows($email_check);
if ($count !=0){
$random=rand(72891, 92729);
$new_password=$random;
$email_password=$new_password;
require('blowfish.php');
require('bcrypt.class.php');
$bcrypt= new Bcrypt(4);
$new_password= $bcrypt->hash($new_password);
echo $new_password;
mysql_query("update users set password='".$new_password."'where email='".$email."'");
}
else{
echo "This email does not exist.";
}
}
?>
</body>
</html>
Line 10 (-->$connect= ("localhost","root","black$23");) should be:
$connect = mysql_connect("localhost","root","black$23");
Note, mysql_* functions are deprecated, use mysqli_* or PDOs instead.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to create a self-submitting page that will create a form for a user to fill out. The information will be stored in a MySQL database. The form seems to be working, but I can't insert the information from the form into a database for some reason. Here's what I have:
<!DOCTYPE html>
<html>
<head>
<title>MySQL Test</title>
</head>
<body>
<h1>MySQL Test</h1>
<?php
if($_SERVER["REQUEST_METHOD"] == "GET") {
?>
<form action="" method="post">
<input type="text" name="name" placeholder="Name" /><br />
<input type="submit" value="Send" />
</form>
<?php
} else if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$server = new PDO("mysql:dbname=test;host=localhost", "root", "root");
$server->execute("INSERT INTO test ('name') VALUES $name;");
}
?>
</body>
</html>
What should I change?
your insert should look as follows:
$name = $_POST["name"];
$server = new PDO("mysql:dbname=test;host=localhost", "root", "root");
$stmt = $server->prepare("INSERT INTO test (name) VALUES (:name)");
$stmt->bindParam(':name', $name);
$stmt->execute();
Please do your insert like this:
$name = "john";
$query = "INSERT INTO test(col) VALUES(:name);";
$statement = $server->prepare($query);
$statement->execute(array(":name" => $name));
This is called using prepared statements, it's very easy and will avoid sql-injection. You can execute multiple variables on multiple cols on your query by separating with commas after each ":col" => $colVal, but that's not needed here, just a tip.
You can do it for updates aswell.
Remember to check if your being-inserted value is empty or not.