Solved

PHP Form/Mysql Issues

Posted on 2011-03-08
3
192 Views
Last Modified: 2013-12-25
Okay,
I've taken some of your advice, example codes, read some URLs & have build the following but it is not pulling the data from my mysql database so I can see it to edit it. Can soomeone take a look at this to see where my mistake is? I've also attached a photo of the fields I'm trying to edit to help you better understand what I am doing. Thanks

<?php

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

mysql_select_db("mydb", $con);

$result = mysql_query("SELECT * FROM mytable ");

$i=0;


while ($i < $num) {
$due_ge=mysql_result($result,$i,"due_ge");
$due_rk=mysql_result($result,$i,"due_rk");
$due_ny=mysql_result($result,$i,"due_ny");

?>

<form action="updated.php">
<input type="hidden" name="id" value="<? echo "$id"; ?>">
DATE1: <input type="date" name="due_ge" value="<? echo "$due_ge"?>"><br>
DATE2: <input type="date" name="due_rk" value="<? echo "$due_rk"?>"><br>
DATE3: <input type="date" name="due_ny" value="<? echo "$due_ny"?>"><br>
<input type="Submit" value="Update">
</form>

<?php
++$i;
} 
?>

Open in new window

editeditedit.JPG
0
Comment
Question by:wantabe2
  • 3
3 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35071397
Use this at the top to see what's wrong

$con = mysql_connect("localhost","uname","password") or die(mysql_error());
mysql_select_db("mydb", $con) or die(mysql_error());;

$result = mysql_query("SELECT * FROM mytable ") or die(mysql_error());;
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35071431
Aso, there is no $num variable

<?php
$con = mysql_connect("localhost","uname","password") or die(mysql_error());
mysql_select_db("mydb", $con) or die(mysql_error());;
$result = mysql_query("SELECT * FROM mytable ") or die(mysql_error());;
$num = mysql_num_rows($result);
$i=0;

while ($i < $num) {
$due_ge=mysql_result($result,$i,"due_ge");
$due_rk=mysql_result($result,$i,"due_rk");
$due_ny=mysql_result($result,$i,"due_ny");

?>

<form action="updated.php">
<input type="hidden" name="id" value="<? echo "$id"; ?>">
DATE1: <input type="date" name="due_ge" value="<? echo "$due_ge"?>"><br>
DATE2: <input type="date" name="due_rk" value="<? echo "$due_rk"?>"><br>
DATE3: <input type="date" name="due_ny" value="<? echo "$due_ny"?>"><br>
<input type="Submit" value="Update">
</form>

<?php
++$i;
} 

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35071460
I've noticed that there is no $id declared and for each record there is a form generated - is that correct thing to do ?

add
error_reporting(E_ALL);
to the top of the script and this will tell you more.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now