PHPMyAdmin Query error in php #1064 [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
<?php
//GET FACEBOOK LIKE DATA TO FACEBOOK SERVERS
function readFacebookLikes($url) {
$query = "select like_count from link_stat WHERE url ='" . $url ."'";
$s = file_get_contents("https://api.facebook.com/method/fql.query?query=".
urlencode($query)."&format=json");
preg_match("#(\"like_count\"):([0-9]*)#",$s,$ar);
if(isset($ar[2])) return $ar[2]; else return null;
}
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('odrinhasedm') or die(mysql_error());
$query=mysql_query("select nome, url from participacao") or die(mysql_error());
while($res=mysql_fetch_array($query))
{
$likes = "http://[ip]/evento-odrinhas-edm-open-air/".$res['url'];
$links = $res['url'];
$contador = readFacebookLikes($likes);
//echo'<tr><td>'.$res['nome'].'</td><td>'.$contador.'</td></tr>';
$query1 = "UPDATE participacao set likes = $contador WHERE url = $links ";
mysql_query($query1) or die (mysql_error());
}
?>
Why is this query1 not working? (PHPMyAdmin errror #1064)
I have a project that creates a page per user on a form and each page has its own Facebook like system, now I have a way to get that data and show it on a table, but I want to insert that data into my database to sort it. Is it easier to add the values to my db or sort the table directly in php?
I have a query that is working and its pulling the URLs to the PHP file, then I want to create another query to insert the data into the database with "update".

I think url is a string. So you must have quotes around the values:
UPDATE participacao set likes = $contador WHERE url = '$links'

Related

Query with WHERE clause not working using mysqli bind_param() [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am creating a webservice where I need to get some data from mysql and retrieve it in a mobile app.
I have been trying all day to do a query with a WHERE statement, but no success.
The normal query, without the WHERE is working perfectly though.
Also I went through all the similar questions on stack overflow and other forums, but none is the same problem as mine.
This is my current code:
<?php
$con=mysqli_connect("Hidden credentials");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($stmt = $con->prepare("SELECT
team.id as teamId,
team.team_name as teamName,
user.id as userId,
user.username as username,
team_members.role as role
FROM team_members
inner join user on team_members.user_id = user.id
inner join team on team_members.team_id = team.id
where user.id = ?
")) {
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$resultArray = array();
$tempArray = array();
while($row = $result->fetch_object())
{
$tempArray = $row;
array_push($resultArray, $tempArray);
}
echo json_encode($resultArray);
$stmt->close();
}
?>
If I remove the line where user.id=? it gets the data correctly.
Running the query on phpMyAdmin is everything ok, so it's not any issue on the query.
The variable $id doesn't exist (in your code). If you want to set the variable dynamically you can use $id = $_GET['id'];. This will take the value from the url and put it in the variable!
Your QUERY doesn't work because your variable id doesn't exists (in code what you showing).
Fix: create variable id and put some data to this variable.
For example:
$id = 5;
Or dynamcially:
From URL with GET method:
$id = $_GET['id'];
this allows you to get parameter from URL. But you must set this parameter by link. For example: <a href="index.php?id=5">. By clicking on this a tag you will be redirected to page index.php with parameter id which equals to 5.
From POST method:
for example you have this FORM:
<form method="post">
<input type="number" name="id">
<input type="submit" name="submit">
</form>
after submiting this FORM values will be saved in $_POST. You can access them by $_POST["name"]. In this case $_POST["id"].
$id = $_POST["id"];
From SESSION:
$id = $_SESSION["id"];
but first you have define $_SESSION["id"]. You can access this variable ($_SESSION["id"]) in other pages of your domain.

Update query is not working - need to look [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Can anyone tell where am I wrong in the query. The database in not updating irrespective of the value
<?php
// ================= UPDATE =========================
if ($_POST['SUBMIT']=='SUBMIT')
{
$fixture_id = "$_GET[id]";
$m_date = "$_POST[match_date]";
$m_time = "$_POST[match_time]";
$m_report = "$_POST[match_report]";
$m_a_result = "$_POST[team_a_result]";
$m_b_result = "$_POST[team_b_result]";
$updt = mysql_query("UPDATE `fixture` SET match_date='$m_date', match_time='$m_time', match_report='$m_report', match_a_result='$m_a_result', match_b_result='$m_b_result', status = 1 WHERE id = '$fixture_id'");
header("location:view_fixture.php?msg= You have inserted result successfully...");
}
else
{
header("location:result_update.php?msg= Something went wrong...");
}
// ================================================================================
?>
Before executing this make sure your submit button have a string value of "SUBMIT"
Try this ..
<?php
$fixture_id = $_GET[id];
if ($_POST['SUBMIT']=='SUBMIT')
{
$m_date = $_POST['match_date'];
$m_time = $_POST['match_time'];
$m_report = $_POST['match_report'];
$m_a_result = $_POST['team_a_result'];
$m_b_result = $_POST['team_b_result'];
$updt = mysql_query("UPDATE `fixture` SET match_date= '$m_date', match_time='$m_time', match_report='$m_report', match_a_result='$m_a_result', match_b_result='$m_b_result', status = 1 WHERE id = '$fixture_id'");
header("location:view_fixture.php?msg= You have inserted result successfully...");
}
else
{
header("location:result_update.php?msg= Something went wrong...");
}
?>
Please DO NOT USE mysql_* . It is now deprecated

Php, mysql script. *should* work as I see it, but don't [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So, I got this script: http://pastebin.com/HHnUWnyB
The thing is that it isn't working, and I got no idea why, I've looked at it, over and over, and to me it should work, but doesn't. So now I'm turning to the experts!
Instead of updating in the mysql db it just returns an empty page...
Thanks in advance!
Update: found the exact but that isn't working:http://pastebin.com/pQrdQUPq
$username = 'test'; // note, isn't this in original script, it's called from a database, but whatever
if(isset($_POST['generate'])) {
$newkey = 'something';
$query = sprintf('UPDATE `users` SET `key`=%s WHERE `username`="%s"',
mysqli_real_escape_string($db, $newkey),
mysqli_real_escape_string($db, $username));
mysqli_query($db, $query);
};
seems like either POST['disable'] or POST['generate'] are not set. Check that those variables are being posted. Theres also a bunch of BAD SYNTAX: There are many extra ending brackets, and unnecessary semicolons.
Also try changing this:
$query = sprintf('UPDATE `users` SET `key`=%s WHERE `username`="%s"',
to this:
$query = sprintf("UPDATE `users` SET `key`='%s' WHERE `username`='%s'",
So you should have this:
$username = 'test'; // note, isn't this in original script, it's called from a database, but whatever
if (isset($_POST['generate'])) {
$newkey = 'something';
$query = sprintf("UPDATE `users` SET `key`='%s' WHERE `username`='%s'", mysqli_real_escape_string($db, $newkey), mysqli_real_escape_string($db, $username));
mysqli_query($db, $query);
}

How do I display url [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a site in which people can click on names and will be redirected to the corresponding URL
id | name | url
1 | facebook | www.fb.com
I have 1,200,000,023 URL I want to display. URLs which loggedin user have not visited.
My signup information are stored in userdb.php like this:
1|username|a84894gf5sag4f684gh68fh45g|email#gmail.com|NA
My display.php is
<?php
mysql_connect('mysql', '1', 'Py');
mysql_select_db('a5803761_add');
$query =mysql_query('select * from addimage order by ID DESC');
while( $row = mysql_fetch_assoc($query) )
{
echo '<div style="min-width:300px;height:100px;border:red 5px;float:left;">'.$row['name'].'</div>';
}
?>
First, you have to store which user visited which url already. This table should have a structure like that:
CREATE TABLE VISITED(ID INT AUTO_INCREMENT,
USER_ID INT,
URL_ID INT,
PRIMARY KEY(ID),
KEY(USER_ID),
KEY(URL_ID));
Then you have to interprep the users' click to store if they visit an url (with jQuery maybe, and send back this with AJAX) or use a redirecter PHP which logs the clicked url and then redirect the user to this.
If you consider the second one, this PHP should be something:
<?php
//You should check here for the URL to be an integer
$res = mysql_query('SELECT url FROM addimage WHERE id='.$url_id.';');
if (mysql_num_rows($res)>0) {
mysql_query('INSERT INTO VISITED VALUES(NULL,'.$_SESSION['logged_in_user_id'].','.$url_id.');');
$row = mysql_fetch_array($res);
Header('Location: http://'.$row[0]);
}
?>
After that, when you list your URLs, you have to check which are the user didn't visit yet:
<?php
mysql_connect('mysql', '1', 'Py');
mysql_select_db('a5803761_add');
$sql = 'select addimage.id, addimage.name, VISITED.USER_ID from addimage ';
$sql .= 'LEFT JOIN VISITED ON (addimage.id = VISITED.URL_ID) ';
$sql .= 'WHERE (VISITED.USER_ID='.$_SESSION['logged_in_user_id'].');';
$query =mysql_query('order by ID DESC');
while( $row = mysql_fetch_assoc($query) )
{
if ($row[2] == 'NULL') {
echo '<div style="min-width:300px;height:100px;border:red 5px;float:left;">'.$row['name'].'</div>';
}
}
?>
But I think it's not a good idea to list such a lot of urls in one HTML, probably the browser will eat up all the memory. Maybe you should do some kind of filter or paging mechanins.
Please consider this code as an example only, and modify it for your needs.
On the other hand, as others suggested, DO NOT use mysql_ extensions, use mysqli or PDO.
I would advise you to use mysqli or PDO. O, and write "http://" into link.

I get error when i use mysqli select [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
<?php if($_POST) {
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$mysqli = new mysqli('localhost','root','','movie_posters');
$query = $mysqli->query("SELECT password FROM users WHERE username = '"$username"'");
} ?>
When I try this code on WAMP, I get error like; this http://i.stack.imgur.com/qcifR.jpg
What can I do ?
Do not use single and double quotes in your query.
This is the right way:
$query = $mysqli->query("SELECT password FROM users WHERE username = '$username'");
Otherwise, you will not print $username's value.
You have to put periods before and after you variable.
In your example:
$query = $mysqli->query("SELECT password FROM users WHERE username = '".$username."'");

Categories