Re: [PHP] Error Querying Database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Maybe because in one script your trying to run a query with values that haven't yet been submitted from your form.

Also, i would remove the action attribute on the form, ad the default action for form elements in the html spec is itself anyway, and that $_SERVER variable won't necessarily be what you expect if someone is trying to attack your site.

Thanks,
Ash
http://www.ashleysheridan.co.uk

----- Reply message -----
From: "Gary" <gpaul@xxxxxxxxxxxxxxxx>
Date: Wed, Dec 15, 2010 18:42
Subject: [PHP] Error Querying Database
To: <php-general@xxxxxxxxxxxxx>

I cant seem to get this to connect.  This is to my local testing server, 
which is on, so we need not worry that I have posted the UN/PW.

This is a duplicate of a script I have used countless times and it worked. 
The error message is 'Error querying database.'

Some one point out the error of my ways?

Gary


<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<tr>
<td>
<label>Name of Beer</label></td><td><input name="beername" type="text" />
</td>
</tr>
<tr>
<td>
<label>Maker of Beer</label></td><td><input name="manu" type="text" />
</td>
</tr>
<tr>
<td>
<label>Type of Beer</label></td>
<td><select name="type" size="1" id="type">
  <option>Imported</option>
  <option>Domestic</option>
  <option>Craft</option>
  <option>Light</option>
</select>
<!--<select name="avail" size="1" id="avail">
  <option>Available</option>
  <option>Sold</option>
</select>-->
</td>
</tr>
<tr>
<td><label>Sold in</label>
</td><td><input type="checkbox" name="singles" value="Yes" /> Singles<br />
<input type="checkbox" name="six" value="Yes" /> Six Packs <br />
<input type="checkbox" name="can" value="Yes" /> Cans<br />
<input type="checkbox" name="bottles" value="Yes" /> Bottles <br />
<input type="checkbox" name="tap" value="Yes" /> Draft <br />
<tr>
<td>
<label>Size</label></td><td><input name="size" type="text" />
</td></tr>
<tr><td>
<label>Description</label></td><td><textarea name="desc" cols="40" 
rows="5"></textarea>
</td></tr>
<tr><td>
<input name="submit" type="submit" value="Submit" /></td></tr>
</form>
</table>
</div>
<div id="list">
<?php
$beername = $_POST['beername'];
$manu = $_POST['manu'];
$type = $_POST['type'];
$singles = $_POST['singles'];
$six = $_POST['six'];
$can = $_POST['can'];
$bottles = $_POST['bottles'];
$tap = $_POST['tap'];
$size = $_POST['size'];
$desc = $_POST['desc'];
$ip= $_SERVER['REMOTE_ADDR'];

$dbc = mysqli_connect('localhost','root','','rr')or die('Error connecting 
with MySQL Database');

$query = "INSERT INTO beer (beername, manu, type, singles, six, can, 
bottles, tap, size, desc, ip )"." VALUES ('$beername', '$manu', '$type', 
'$singles', '$six', '$can', '$bottles', '$tap', '$size', '$desc', '$ip' )";

$result = mysqli_query($dbc, $query)
or die('Error querying database.');


mysqli_close($dbc);



-- 
Gary 



__________ Information from ESET Smart Security, version of virus signature database 5706 (20101215) __________

The message was checked by ESET Smart Security.

http://www.eset.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux