Jump to content

Recommended Posts

heres the code...

 

<?php
mysql_connect("localhost","peter","tizer") or die("Error: ".mysqlerror());

mysql_select_db("matquant");

//replace TestTable with the name of your table

//also in a real app you would get the id dynamically

$idtochange=$_POST['idtochange'];

$sql="select * from `quantites` where id = $idtochange";

$query=mysql_query($sql);

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

$id = $row['id'];

$material = $row['material'];

$quantity = $row['quantity'];

$unit = $row['unit'];

//we will echo these into the proper fields

}

mysql_free_result($query);

?>

<html>
<head>

<title>Edit material list</title>

<link href="css/quant1.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="leftcol">


<form "method="post">
<p><br/>
  
  <input type="text"value="1" name="idtochange" >
<p>
  
  <input type="submit"value="submit changes"/>
  
</form>

<form action="changequan.php"method="post">
<p>Material Id currently active<br/>
  
  <input type="text"value="<?php echo $id;?>" name="id" disabled/>  </p>
<p>
  
  Enter new material name: </p>
  
  <input type="text"value="<?php echo $material;?>" name="material"/>
  <br/>
  
  change quantity:
  
  <input type="text"value="<?php echo $quantity;?>" name="quantity"/>
  
  <br/>
  
  unit of mesurement for quantity<br/>
  
  <input type="text"value="<?php echo $unit;?>" name="unit"/>
  
  <br/>
</p>

<input type="submit"value="submit changes"/>

</form>
</div>
<div id="rightcol"><?php 

// make connection
mysql_connect ("localhost", "peter", "tizer") or die ('I cannot connect to the database becuase: ' . mysql_error());

mysql_select_db ("matquant");

// build query
$query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); 



// display results
while ($row = mysql_fetch_array($query)) {

echo "<br />  .....  "   .$row ['id'].		"   .......  "  .$row ['material'].		 "  ......   "    .$row['quantity'].  "  ......   "    .$row['unit']. "<br />";}
echo mysql_error();
?>

<a href="index.html">Home </a> <p> <a href="quanform.php">Insert new material and quantity form</a></p></div>
</body>

</html>

 

I'm struggling with php.  Any help anyone can give would be appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/211840-simple-code-cant-see-problem/
Share on other sites

I just quickly looked because you didnt provide a problem, but this is what i noticed so far.

<input type="text"value="1" name="idtochange" > is missing an endtag. so it should look like:

<input type="text"value="1" name="idtochange" />

your submit button doens't have a name so it should look more like:

<input type="submit" name="submit" value="submit changes" />

thanks for that,  its getting late lol. 

 

I am new to php and miss the obvious bits.

 

Sorry about the crap original post.  I will try to describe my problem better.

 

I am simply trying to make a form that will update materials in a list.  my page has the form on 1 side and the list on the right.

 

I want to enter an ID in the first instance and then for the form to be populated with the data in the table with the id.

 

 

I have 2 files .  the form page and , ill call it the update engine....

 

The form page is below (between the horizontal rules. and throws the following errors on load.

 

 

Notice: Undefined index: idtochange in C:\wamp\www\parkhall\changequanform.php on line 11

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 17

 

Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 31


 

[code=php:0]<?php
mysql_connect("localhost","peter","tizer") or die("Error: ".mysqlerror());

mysql_select_db("matquant");

//replace TestTable with the name of your table

//also in a real app you would get the id dynamically

$idtochange=$_POST['idtochange'];   // <<<<<<<<<<<<<<<<<<<<<<< line 11

$sql="select * from `quantites` where 'id' = $idtochange";

$query=mysql_query($sql);

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

$id = $row['id'];

$material = $row['material'];

$quantity = $row['quantity'];

$unit = $row['unit'];

//we will echo these into the proper fields

}

mysql_free_result($query);

?>

<html>
<head>

<title>Edit material list</title>

<link href="css/quant1.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="leftcol">


<form "method="post">
<p><br/>
  
  <input type="text"value="1" name="idtochange" />
<p>
  
  <input type="submit"value="submit changes"/>
  
</form>

<form action="changequan.php"method="post">
<p>Material Id currently active<br/>
  
  <input type="text"value="<?php echo $id;?>" name="id" disabled/>  </p>
<p>
  
  Enter new material name: </p>
  
  <input type="text"value="<?php echo $material;?>" name="material"/>
  <br/>
  
  change quantity:
  
  <input type="text"value="<?php echo $quantity;?>" name="quantity"/>
  
  <br/>
  
  unit of mesurement for quantity<br/>
  
  <input type="text"value="<?php echo $unit;?>" name="unit"/>
  
  <br/>
</p>

<input type="submit"value="submit changes"/>

</form>
</div>
<div id="rightcol"><?php 

// make connection
mysql_connect ("localhost", "peter", "tizer") or die ('I cannot connect to the database becuase: ' . mysql_error());

mysql_select_db ("matquant");

// build query
$query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); 



// display results
while ($row = mysql_fetch_array($query)) {

echo "<br />  .....  "   .$row ['id'].		"   .......  "  .$row ['material'].		 "  ......   "    .$row['quantity'].  "  ......   "    .$row['unit']. "<br />";}
echo mysql_error();
?>

<a href="index.html">Home </a> <p> <a href="quanform.php">Insert new material and quantity form</a></p></div>
</body>

</html>

[/code]


 

 

Again, the errors on load of above....  to save scrolling

 

 

Notice: Undefined index: idtochange in C:\wamp\www\parkhall\changequanform.php on line 11

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 17

 

Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 31

 


 

When I use the first form submit button, it works and updates the id for the second form section, and populates the text boxes with the data.

 


 

this is the other file, the php for the formpage.

<?php



mysql_connect("localhost","peter","tizer") or die ("Error: ".mysqlerror());

mysql_select_db("matquant");



$id=$_POST['id'];

$material=$_POST['material'];

$quantity=$_POST['quantity'];

$unit=$_POST['unit'];



$sql="UPDATE `quantites` SET `material` = '$material',`quantity` = '$quantity',`unit` = '$unit' WHERE `quantites`.`id` = '$id' LIMIT 1";

mysql_query($sql)or die("Error: ".mysql_error());

echo"Database updated. <a href='changequanform.php'>Return to edit info</a>";

?>

 

It throws errors when I submit the second part of the form and I have just changes something and broken it further. Any help will be graciously recieved.

 

Regards

Peter

 

 

 

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.