Jump to content

Back To Basics Mysql_Query


Darkside

Recommended Posts

Shortened everything up to try find the prob. Started with a lot of info to INSERT into MYSQL table but found I had a bitten off more than I could chew.

 

 

Still got the same problem, hoping someone out there can help me sort out the problem.

 

Can anyone see errors in script. Not getting any error messages tho.

 

 

 

 

$rig = $_POST['rig'];
$medication = $_POST['medication'];

mysql_query("INSERT INTO tabletest (rig,medication)
VALUES ('".$rig."','".$medication."')");

$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message  = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

?>

 

 

 

 

PS. Merry Christmas to you all

Edited by Zane
Link to comment
Share on other sites

You have no variables named $query so the call of mysql_query($query) would give an error if you had error reporting on. I suggest adding this to the top of your php. It will display everything wrong with the page it's currently on

 

error_reporting(E_ALL);
ini_set('display_errors', '1');

 

As it stands there appears to be nothing wrong with your first call of just mysql_query("stuff");

Link to comment
Share on other sites

My head hurts... :-\

 

made a couple of changes that I thought would suffice... but apparently Im still off target. Still getting errors but (cant see how or where im going wrong???)

 

 

<?php

 

error_reporting(E_ALL);

ini_set('display_errors', '1');

 

 

if (isset($_POST['rig'], $_POST['medication']))

$rig = $_POST['rig'];

$medication = $_POST['medication'];

 

 

mysql_query("INSERT INTO tabletest (rig,medication)

VALUES ('".$rig."','".$medication."')");

 

 

 

 

?>

 

Thought I had defined the index with the...

if (isset($_POST['rig'], $_POST['medication']))

 

and thought the variables were already defined with

$rig = $_POST['rig'];

$medication = $_POST['medication'];

 

My head hurts. :hammer_time:

 

Any suggestions greatly appreciated.

Link to comment
Share on other sites

My head hurts... :-\

 

made a couple of changes that I thought would suffice... but apparently Im still off target. Still getting errors but (cant see how or where im going wrong???)

 

 

<?php

 

error_reporting(E_ALL);

ini_set('display_errors', '1');

 

 

if (isset($_POST['rig'], $_POST['medication']))

$rig = $_POST['rig'];

$medication = $_POST['medication'];

 

 

mysql_query("INSERT INTO tabletest (rig,medication)

VALUES ('".$rig."','".$medication."')");

 

 

 

 

?>

 

Thought I had defined the index with the...

if (isset($_POST['rig'], $_POST['medication']))

 

and thought the variables were already defined with

$rig = $_POST['rig'];

$medication = $_POST['medication'];

 

My head hurts. :hammer_time:

 

Any suggestions greatly appreciated.

oops forgot these are the errors im still getting.

 

you've got the connection to this database

Notice: Undefined index: medication in/home/hbcpl/public_html/australian.com/shorttest.php on line 30

 

Notice: Undefined variable: rig in/home/hbcpl/public_html/australian.com/shorttest.php on line 34

Edited by Darkside
Link to comment
Share on other sites

Try

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

if (isset($_POST['rig'], $_POST['medication'])) {
$rig = $_POST['rig'];
$medication = $_POST['medication'];

mysql_query("INSERT INTO tabletest (rig,medication)
VALUES ('".$rig."','".$medication."')");
}
?>

Link to comment
Share on other sites

Try

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

if (isset($_POST['rig'], $_POST['medication'])) {
$rig = $_POST['rig'];
$medication = $_POST['medication'];

mysql_query("INSERT INTO tabletest (rig,medication)
VALUES ('".$rig."','".$medication."')");
}
?>

Thanks again SC

 

That fixed all the errors, but for some reason its still not INSERTING into DATABASE table

Link to comment
Share on other sites

A lot easier to read like this:

mysql_query("INSERT INTO tabletest (rig,medication)
VALUES ('{$rig}','{$medication}')") or die(mysql_error());

 

OP, you need to check for errors. Read the link in my signature about debugging SQL.

Link to comment
Share on other sites

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

print '<pre>';
print_r($_POST);

if (isset($_POST['rig'], $_POST['medication'])) {
    $rig = $_POST['rig'];
    $medication = $_POST['medication'];

    $sql = "INSERT INTO tabletest (rig,medication) VALUES ('{$rig}','{$medication}')");
    $result = mysql_query($sql) or trigger_error("Query Failed! SQL: {$sql} - Error: ".mysql_error(), E_USER_ERROR);
}
?>

 

What do you get when running this?

Edited by Jessica
Link to comment
Share on other sites

It tells you that nothing have been posted the PHP script, via a form or otherwise, and thus it has nothing to add to the database.

 

Exactly, the print_r($_POST); is showing you that $_POST is empty. Where do you expect the posted data to be coming from?

Link to comment
Share on other sites

That message is telling you that nothing has been sent from the client to the server, via the POST method. Why that is, is something you have to figure out.

 

PS: Note that this will always be empty the first time you visit a page, that's normal and expected. Seeing as all browsers use the GET method when requesting a page, unless told otherwise.

Edited by Christian F.
Link to comment
Share on other sites

Exactly, the print_r($_POST); is showing you that $_POST is empty. Where do you expect the posted data to be coming from?

 

Hmmmm? I was expecting it to be coming from the form? Clearly Im overlooking something....

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shorttest</title>
</head>
<?php include 'shorttest.php'; ?>

<body>



<form action="inserted.php" method="post" enctype="multipart/form-data" name="workfitnessform" id="workfitnessform"><H1> </H1>
 <h3> </h3>
 <table width="380" border="1">
   <tr>
     <th colspan="3" scope="col"></th>
   </tr>
   <tr>
     <th colspan="3" scope="row"> </th>
   </tr>
   <tr>
     <th width="287" scope="row"><div align="left">

     </div></th>
     <td colspan="2" rowspan="2"><h1 align="center">RIG</h1>
       <label for="textfield"></label>
     <input type="text" name="rig" id="col2" /></td>
   </tr>
   <tr>
     <th scope="row"><div align="left">

     </div></th>
   </tr>
   <tr>
     <th scope="row"> </th>
     <td width="72"><div align="center"><strong>YES</strong></div></td>
     <td width="73"><div align="center"><strong>NO</strong></div></td>
   </tr>
   <tr>
     <th scope="row"><p align="left">Are you presently taking any medication of any kind?</p>
      </th>
     <td><input type="radio" name="medication" id="col3" /></td>
     <td><input type="radio" name="medication" id="col3" /></td>
   </tr>
   <tr>

   </tr>
    <tr>
     <th colspan="3" scope="row">
     <input type="submit" name="submit" id="submit" /></th>
   </tr>
 </table>

</form>



</body>
</html>

 

PS. I know its messy, my excuse at this point is that I have just pulled 36 straight hrs of travel and work and Im just too shattered to tidy it up right now.

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.