Jump to content

[SOLVED] update trouble: new take


RyanSF07

Recommended Posts

Hi All,

 

Thanks for your help during these past couple days. I'm enjoying this forum.

 

I've run into trouble with php/mysql for editing a quiz question in an esl quiz app.

 

In the 'edit quiz' pages of this app, one page identifies all of the question of a quiz built by a particular registered user.

 

From this page the user can select a question to edit. (Works great)

 

The user is then taken to a page where the question form is populated. Here is the code for that:

 

<?php
$id = $_GET['id'];
$update = $_POST['update'];
$question = $_POST['question']; 
$opt1 = $_POST['opt1'];
$opt2 = $_POST['opt2'];
$opt3 = $_POST['opt3'];
$answer = $_POST['answer'];

if($id) {
$sql = "SELECT * FROM $table WHERE id=$id";
$query_result = mysql_query($sql);
$myrow = mysql_fetch_array($query_result);
?>

Edit this question.<?echo "$_GET[id] $id $_SESSION[get]";?>
<form method="post" name="update" action="editquiz_updateQ_processor.php?$_GET[id];">
<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>
<?
}
?>

 

Note, this code is working and echoing the id's produces the correct values.

 

The third page is the 'processor.' It is meant to take the data and insert it into the quiz table.

On all of the other pages I'm made for notes, title, by, transcript, etc, this works.

On this page, however, with this code.. nothing works.

 

I've tried so many suggestions that my eyes are missing something. Please look this part over and point out my mistake. Thank you very much for your time and help  :)

 

<?php
$id = $_GET[id];
$update = $_POST[update];
$question = $_POST[question]; 
$opt1 = $_POST[opt1];
$opt2 = $_POST[opt2];
$opt3 = $_POST[opt3];
$answer = $_POST[answer];
  
if ($_POST[update]) {
$query = "UPDATE quiz SET question = '$question', opt1='$opt1', opt2='$opt2', opt3='$opt3', answer='$answer' WHERE id='$id'";

$result = mysql_query($query);
echo "Update is successful! Thank You";}

else{ echo "Failed updating: " . mysql_error() . "\n$sql\n"; }
?>

 

In testing, this last part fails to work. The app reports "Upate is successful! Thank You" , but the update did not in fact occure.

 

Looking forward to hearing from you.

Ryan

Link to comment
Share on other sites

What do you get if you add echo $query ?  That should help to show what's going wrong.

 

Also, your failed clause in the second script uses $sql, but the query is called $query.  That doesn't make a difference now, but would if the query failed :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.