Jump to content

php script generates fatal error on mysql update command


Poddy

Recommended Posts

hi, i'm trying to build a form which you answer questions and it stores them on a mysql database

while the user is identified by an integer value in user_id field in the table..

 

however when i try to UPDATE the row it just gives me the 500 internal error message which i know is a fatal error in my php script..

 

when i remove the update command it works perfectly... it's just dosent add it to the the database which i need it to..

 

when i comment this row everything works fine, but nothing gives the order to put it into the database

$query = "UPDATE users WHERE user_id='12345' SET q1='$q1', q2='$q2', q3='$q3', q4='$q4' "
mysql_query($query) or die('Error, update query failed')

 

<html>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';
$dbname = 'users';
  
  $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
  mysql_select_db($dbname) or die				('Error selecting database');

print_r($_POST);## Uncomment this to have the POST variables printed
if(isset($_POST['submit'])){
$q1 = mysql_real_escape_string($_POST['q1']);
$q2 = mysql_real_escape_string($_POST['q2']);
$q3 = mysql_real_escape_string($_POST['q3']);
$q4 = mysql_real_escape_string($_POST['q4']);


$query = "UPDATE users WHERE user_id='12345' SET q1='$q1', q2='$q2', q3='$q3', q4='$q4' "
mysql_query($query) or die('Error, update query failed')

}



?>

<div align="center"><h1>Title</h1></div>

<p align="center">please answer these questions</p>

<form action="<?php echo $PHP_SELF?>" method="post" name="questions">

<?php
$query  = "SELECT * FROM questions WHERE q_id='1'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['q_txt'];
?>

<input name="q1" type="text"><br>
<label>
<?php
$query  = "SELECT * FROM `questions` WHERE q_id='2'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['q_txt'];
?>
</label> 
<input name="q2" type="text"><br>
<label>
<?php
$query  = "SELECT * FROM `questions` WHERE q_id='3'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['q_txt'];
?>
</label> 
<input name="q3" type="text"><br>
<label>
<?php
$query  = "SELECT * FROM `questions` WHERE q_id='4'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['q_txt'];
?>
</label> 
<input name="q4" type="text"><br>
<br>
<input name="submit" value="Submit" type="submit">
</p>
</form>
</body>
</html>

 

 

Link to comment
Share on other sites

<?php

if(isset($_POST['submit'])){

$q1 = mysql_real_escape_string($_POST['q1']);
$q2 = mysql_real_escape_string($_POST['q2']);
$q3 = mysql_real_escape_string($_POST['q3']);
$q4 = mysql_real_escape_string($_POST['q4']);


$query ="UPDATE users SET q1='$q1', q2='$q2', q3='$q3', q4='$q4' where user_id='12345' ";
$result="mysql_query($query) or die('Error, update 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.