Jump to content

Recommended Posts

Hey everyone,

 

I have a form that goes to a processing page, there is a drop down menu on the form that gets locations from a database. The code for the form page is first and then process page.

 

<?
// Connect database
mysql_connect("localhost","USERNAME TAKEN OUT","PASSWORD TAKEN OUT");
mysql_select_db("wowbasec_class"); 

// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&&$select!=""){
$select=$_GET['select'];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<table width="70" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#00FFFF">
  <tr>
    <td height="34"><div align="center">Character Add Page </div></td>
  </tr>
  <tr>
    <td height="208"><form action="addcharfile.php" method="post" name="form1">
      <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="191"><div align="right">Name:</div></td>
          <td width="309"><input name="name" type="text" id="name"></td>
        </tr>
        <tr>
          <td><div align="right">Location:</div></td>
          <td><select name="location" id="location">
<option value="">--- Select ---</option>
<?
// Get records from database (table "name_list").
$list=mysql_query("select * from location order by id asc");

// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['id']; ?>" <? if($row_list['id']==$select){ echo "selected"; } ?>><? echo $row_list['name']; ?></option>
</select>
</td>
        </tr>
        <tr>
          <td><div align="right">Health:</div></td>
          <td><input name="health" type="text" id="health"></td>
        </tr>
        <tr>
          <td><div align="right">Mana:</div></td>
          <td><input name="mana" type="text" id="mana"></td>
        </tr>
        <tr>
          <td><div align="right">Notes:</div></td>
          <td><textarea name="notes" id="notes"></textarea></td>
        </tr>
        <tr>
          <td colspan="2"><div align="center">
            <input type="submit" name="Submit" value="Add">
          </div></td>
        </tr>
      </table>
    </form>
    </td>
  </tr>
  <tr>
    <td> </td>
  </tr>
</table>
</body>
</html>
<?
// End while loop.
}
?>

 

<?

$connection = mysql_connect("localhost","USERNAME TAKEN OUT","PASSWORD TAKEN OUT");

mysql_select_db("wowbasec_class", $connection);

// Get values from form.
$name=$_POST['name'];
$location=$_POST['location'];
$health=$_POST['health']; 
$mana=$_POST['mana']; 
$notes=$_POST['notes']; 

// Insert all parameters into database.
// The id field is auto increment. You don't have to insert any value 
$sql = mysql_query("insert into char(name, location, health, mana, notes) values('$name', '$location', '$health', '$mana', '$notes')");

if (!mysql_query($sql,$connection))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

// Close database connection
mysql_close(); 

?>

 

Any help is apreciated,

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/155556-query-is-empty/
Share on other sites

It means that your SQL statement is messed up somewhere... It may have to do with the information that you are passing... You can try this:

 

Change from this:

values('$name', '$location', '$health', '$mana', '$notes')

 

to this:

values(\"$name\",\"$location\",\"$health\",\"$mana\",\"$notes\")

 

and make sure you use the addslashes function on the variables you are passing to the query:

http://us.php.net/addslashes

 

Hope this helps!

Link to comment
https://forums.phpfreaks.com/topic/155556-query-is-empty/#findComment-822182
Share on other sites

Oh come on!

$sql = mysql_query("insert into char(name, location, health, mana, notes) values('$name', '$location', '$health', '$mana', '$notes')");

if (!mysql_query($sql,$connection))

 

You're doing the query twice. Try:

 

$sql = "INSERT INTO char (name, location, health, mana, notes) VALUES ('$name', '$location', '$health', '$mana', '$notes')";

if (!mysql_query($sql,$connection))

Link to comment
https://forums.phpfreaks.com/topic/155556-query-is-empty/#findComment-822192
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.