November 6, 200916 yr 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! BTW I LOVE PHP :>
November 6, 200916 yr 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?
November 6, 200916 yr 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...
November 6, 200916 yr 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
November 6, 200916 yr Don't forget that if you do that change, you also need this one: $id = $r["id"]; to $id = $row["id"];
November 6, 200916 yr 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! , Thankyou :>
November 7, 200916 yr 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."')");
November 11, 200916 yr 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