Jump to content

Updating table: what am I missing?


RyanSF07

Recommended Posts

Hi All,

 

If you can help here, great.

 

This code should update a quiz question. Making an edit to a quiz question, however, and clicking "update info" I only get the response: The quiz has been succesfully updated.  -- unfortunately, the quiz is not, in fact, succesfully updated.

There are no problems with the connection to the database. I'm missing something.. what is it?

 

All suggestions welcome. Thank you very much for your time and help.

Ryan

 

<?php

session_start();

header("Cache-control: private"); //IE 6 Fix

include("contentdb.php");

include("qinsert.php");

?>

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 

"http://www.w3.org/TR/html4/loose.dtd">

 

<html>

<head>

<link href="main_styles.css" rel="stylesheet" type="text/css">

</head>

<body>

 

<?php

$id = $_GET['id'];

$update = $_POST['update'];

$question = $_POST['question'];

$opt1 = $_POST['opt1'];

$opt2 = $_POST['opt2'];

$opt3 = $_POST['opt3'];

$answer = $_POST['answer'];

 

 

if($update)

{

$sql = "UPDATE $table SET question='$question', opt1='$opt1', opt2='$opt2', opt3='$opt3', answer='$answer' WHERE id='$id'";

$result = mysql_query($sql);

echo "<br><br>The quiz has been succesfully updated.<br><br>\n";

}

else if($id)

{

$result = mysql_query("SELECT * FROM $table WHERE id=$id",$db);

$myrow = mysql_fetch_array($result);

?>

 

 

Edit this question.<?echo "WTF? $_GET[id] $id";?>

<form method="post" action="editquiz_updateQ.php">

<input type="hidden" name="id" value="<?php echo $myrow['id']?>">

    <b>Question:</b><br>

    <input type="Text" name="question" value="<?php echo $myrow['question']?>" size="50">

    <br>

    <b>Option 1:</b><br>

    <input type="Text" name="opt1" value="<?php echo $myrow['opt1']?>" size="30">

    <br>

    <b>Option 2:</b><br>

    <input type="Text" name="opt2" value="<?php echo $myrow['opt2']?>" size="30">

    <br>

    <b>Option 3:</b><br>

    <input type="Text" name="opt3" value="<?php echo $myrow['opt3']?>" size="30">

    <br>

    <b>Answer</b> (must be identical to correct option):<br>

    <input type="Text" name="answer" value="<?php echo $myrow['answer']?>" size="30">

    <br>

    <br>

<input type="Submit" name="update" value="Update information"></form>

<?

 

}

 

?>

 

</body>

</HTML>

Link to comment
https://forums.phpfreaks.com/topic/37973-updating-table-what-am-i-missing/
Share on other sites

Try this:

 

<?php

if(!$id)
{
$sql = "UPDATE $table SET question='$question', opt1='$opt1', opt2='$opt2', opt3='$opt3', answer='$answer' WHERE id='$id'";
$result = mysql_query($sql);
echo "

The quiz has been succesfully updated.

\n";
}
else if(!$update)
{
$result = mysql_query("SELECT * FROM $table WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);

?>

 

basically it does the same thing. If there is no $id set then it runs the first query. if there is an $id set, but no $update set, then it runs the second one.

btw, the reason I think that is because i believe it would have to be if ($id == True) or something, because you have to tell the if statement what to check for. just telling it id doesn't mean anything because id could return true or false and still be correct as far as if($id) is concerned.

 

i could be wrong on this, but it works on my server.

Hi Ronald,

 

Thank you for your help. Unfortunately that did not do the trick.. bummer.

 

I tried $id==True too, but that just deleted the whole question.

 

If you have any other ideas, I'd love to hear them!

I understand though that this all volunteer advice and you are probably extremely busy.

Thanks again for your help. I'll keep at it. Can't wait to solve this  :)

Ryan

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.