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
Related
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 6 years ago.
Improve this question
I have two submit buttons that get values from two forms and insert them in a database. The problem is that I need to get the last inserted id from the first table (courses) to insert into the second table (students) but it does not work. This what I did:
<?php
$course_name = // the value of the field for the course name
$student_name = // The first name of the student
$student_age = // The age of the student
$last_id = // The last id of table courses
if(isset($_POST['submit1'])){
$query1 = "INSERT INTO courses (course_name)VALUES ('$course_name')";
if ($object->query($query1) === true){
$last_id = LAST_INSERT_ID();
$good = "the course has been created";
}
else{
$bad = "Error: " .$query1.$object->error;
}
}
if(isset($_POST['submit2'])){
$query2 = "INSERT INTO students (course_id,student_name, student_age)VALUES ('last_id','$student_name','student_age')";
if ($object->query($query2) === true){
$good = "the student has been created";
}
else{
$bad = "Error: " .$query2.$object->error;
}
}
?>
I do not know why it does not work.
You have not mentioned if you are using PDO or mysqli etc etc. If it's mysqli it $mysqli->insert_id;
if ($object->query($query1) === true){
$last_id = $object->insert_id
$good = "the course has been created";
}
OTH, if you are using PDO it's lastInsertId
if ($object->query($query1) === true){
$last_id = $object->lastInsertId()
$good = "the course has been created";
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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.
Improve this question
I have a problem with my code. I want to make a Seesion which display the current login user
Thank you !
$link = mysql_connect($DB_server, $DB_user, $DB_password,$DB_name);
mysql_select_db('linux', $link) or die(mysql_error());
$uid = 0;
if(isset($_GET["id"]))
{
$uid = $_GET["id"];
}
$profilname = mysql_query("SELECT U_Benutzername ,U_ID FROM u_user WHERE U_ID = '$uid'");
$emailadresse =mysql_query("SELECT U_login ,U_ID FROM u_user WHERE U_ID = '$uid'");
$_SESSION['profilname'] = $profilname;
$_SESSION['email'] =$emailadresse;
echo "Benutzername: $profilname";
echo "<br/>";
echo "Email: $profilname";
You have a typo...
$lid = $_GET["id"];
should probably be
$uid = $_GET["id"];
change your mysql query to:
if($uid!=0) {
$ref = mysql_query("SELECT * FROM u_user WHERE U_ID = '$uid'");
$row = mysql_fetch_array($ref);
$profilname = $row["U_Benutzername"];
$emailadresse= $row["U_login"];
$_SESSION['profilname'] = $profilname;
$_SESSION['email'] =$emailadresse;
}
to display it:
echo $_SESSION['profilname'];
BUT:
You wont get far with this, this is mysql_-code and its deprecated.
You have to use mysqli in newer PHP-Versions.
http://php.net/manual/de/book.mysqli.php
Change $lid = $_GET["id"]; to $uid = $_GET["id"];, and it also is a good idea to sanitize the data from $_GET,
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."'");
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 am a beginner . I made a php html combined page(viewemployees.php) to display my table from oracle data base. It worked fine. Then i made a page to edit my data base table(editemployees.php). that page has two functions. It displays the original table and a simple form which should contain the elements to update the table. When we place values in the form it directs us to a new php page(een.php) where it updates table and returns back to editemployees.php showing the updated table. but i am stuck when i fill in the form AND NOTHING happens. Even I have placed a condition that to echo a line if new value field is null. still that line is not echoed. This is some weird thing. I am posting both of my edit and view pages code click the link. kindly help.
In simple my table update is not working and showing undefined variable error at line 4 of een.php. Why is taht variabl undefined?? can anyone help please
https://www.dropbox.com/sh/xtuvotdy7c9wr1v/AADrNSlC_EJ0YkyDDkhe8mKGa?dl=0
<?php
include("connection.php");
$empid = $_POST['EMPLOYEE ID'];
$field = $_POST['EDIT FIELD'];
$nfield = $_POST['NEW VALUE'];
echo $field;
if( empty($_POST['NEW VALUE'] )){
echo "type new field properly";
}
else
{
$e = filter_var($empid, FILTER_SANITIZE_EMAIL);
$f = filter_var($field, FILTER_SANITIZE_EMAIL);
$nf = filter_var($nfield, FILTER_SANITIZE_EMAIL);
}
if( $e==$empid && $f==$field && $nf==$nfield)
{
if ($field=="age" || $field=="sal"){
$sel = "seleect * from employ";
$st = oci_parse(conn, $sel);
oci_execute($st);
$query = " update employ set $field = $nfield where empid = $empid";
$stmt = oci_parse($conn,$query);
oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
oci_free_statement($updateTitleInserted);
oci_close($conn);
echo oci_error();
header("Location: home.html");
}
else{
$query = "update employ set $field = '$nfield' where empid = $empid";
$stmt = oci_parse($conn,$query);
oci_execute($stmt,OCI_COMMIT_ON_SUCCESS);
oci_free_statement($updateTitleInserted);
oci_close($conn);
echo oci_error();
echo $field;
}
}
else
echo "wrong data entry go back and enter again";
?>
This line does not make sense.
$empid = $_POST["EMPLOYER ID"];
A post variable name cannot contain a space.
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'