Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SQL database query

Featured Replies

Basically the query will not show up at all

 

It just shows up with the default values such as date,time,user,entry and doesn't actually show anything from the DB can anyone here help me? I have used PHPDESIGNER and also dreamweaver and still can't fix the problem.

 

It shows no errors when I go to the PHP file on the Localhost

 

<?php
require "db.php";
$result = mysql_query("SELECT * FROM `blogentries`");
while($r=mysql_fetch_array($result)){;
$id = $r["id"];
$self = $_SERVER['PHP_SELF'];

echo "Date: ";
echo $row['date'];
echo "<br>";
echo "User: ";
echo $row['user'];
echo "<br>";
echo "Time: ";
echo $row['time'];
echo "<br>";
echo "Entry: ";
echo $row['entry'];
echo "<br>";
echo "<a href = \"$self?id=$id\">delete</a>";
echo "<hr>";
}
if(isset($_GET['id']))
{
$id = $_GET['id'];
// --------- here code to connect to mysql and select database -----------
require "db.php";
$query= mysql_query("delete FROM blogentries where id =$id")or die(mysql_error());
}
?>

 

Can anyone help, thanks, much appreciated! :p BTW I LOVE PHP :>

Basically the query will not show up at all

This is probably because you're using $row instead of $r inside the loop in some places!

 

Either change all $r to $row or vice-versa. Does that work now?

could be that you need to change

while($r=mysql_fetch_array($result)){;

to

while($row = mysql_fetch_array($result)){

 

 

Note I also removed the ; off the end since that is pointless...

 

 

  • Author

could be that you need to change

while($r=mysql_fetch_array($result)){;

to

while($row = mysql_fetch_array($result)){

 

 

Note I also removed the ; off the end since that is pointless...

 

Yes thankyou Jay, I should of known this, thankyou for taking the time to help me :p

Don't forget that if you do that change, you also need this one:

 

$id = $r["id"];

to

 

$id = $row["id"];

  • Author

Sorry to bring this up again but I have this code here and it will not insert the data into the mysql db

 

here is the code:

I think it may be something to do with my Ifset

 

<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
<body>
<center class="style1">
 <u><span class="style1">You acknowledge that your IP will be recorded for security purposes, any abuse of this form may result in police action being taken. <br>This form will not tell you when you have sent the enquiry.</span></u>
</center>
<?php
if(isset($_POST['submit'])) 
 {
$dnname = $_POST["name"];
$dnemail = $_POST["email"];
$dnenq = $_POST["enquiry"];
$dnip = $_POST["ip"];


$con = mysql_connect("********","********","********");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("*********", $con);

$result=mysql_query("INSERT INTO `contactus` (name,email,enquiry,ip)
VALUES ('$dnname','$dnemail','$dnenq','$dnip')");

mysql_close($con);
}
?>
<form action="<?php echo "$PHP_SELF"; ?>" method="post" >
<p align="center" class="style1"><u>Your Name:</u></p>
<div align="center" class="style1">
 <input name="name"  type="text" value=""/>
</div>
<p align="center" class="style1"><u>Email:</u></p>
<div align="center" class="style1">
 <input name="email" type="text" value="" size="40" maxlength="40">
</div>
<p align="center" class="style1"><u>IP:</u></p>
<div align="center" class="style1">
 <input name="ip"  type="text" readonly="readonly" value="<?php echo $_SERVER["REMOTE_ADDR"]; ?>"/>
</div>
<p align="center" class="style1"><u>Enquiry:</u></p>
<div align="center">
 <p class="style1">
   <textarea name="enquiry" cols="70" rows="5"></textarea>
   </p>
 <p>
   <span class="style1">
   <input type="submit" value="Submit Form!" />
   </span></p>
</div>
</form>
</body>

 

Any help is appreciated! :p, Thankyou :>

You should try giving the submit button a name like:

<input type="submit" name="submit" value="Submit Form!" />

 

and you query should be more like:

$result = mysql_query("INSERT INTO `contactus` (`name`, `email`, `enquiry`, `ip`) VALUES ('".$dnname."', '".$dnemail."', '".$dnenq."', '".$dnip."')");

Also you need to SANITIZE the data you're using on SQL queries.

 

Change

 

for each piece of _POST data

$text = mysql_real_escape_string($_POST['text']);

 

and for _GET data

$text = mysql_real_escape_string($_GET['text']);

 

for ints cast them to an integer using (int)$var.

 

Remember NEVER TRUST user input.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.