What's wrong in my udate/edit php code ?

princeoo7

On a Journey called Life :P
Skilled
I am trying to learn php, mysql and html with css around and trying to build a web site for seeing my skills
<


had the Iframe problem but as the solution is not there do i have moved on and choose to let the login page to open in new windows and admin can work there.

so now the next problem i am facing is the edit or update mysql table data with an php webpage.

here are the codes :

<code>

<?php

$hostname = "localhost";//host name

$dbname = "a_test";//database name

$username = "root";//username you use to login to php my admin

$password = "";//password you use to login

//CONNECTION OBJECT

//This Keeps the Connection to the Databade

$conn = new MySQLi($hostname, $username, $password, $dbname) or die('Can not connect to database')

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Update</title>

<style type="text/css">

body {

background-color: #000;

}

body,td,th {

color: #FFF;

}

</style>

</head>

<body>

<?php

if(isset($_POST['Submit'])){//if the submit button is clicked

$page_no = $_POST['page_no'];

$data = $_POST['data'];

$update = "UPDATE cms_content SET data='$data' WHERE cms_content page_no = '$page_no'";

$conn->query($update) or die("Cannot update");//update or error

}

?>

<?php

//Create a query

$sql = "SELECT * FROM cms_contet WHERE page_no = '' ";

//submit the query and capture the result

$result = $conn->query($sql) or die(mysql_error());

$query=getenv(QUERY_STRING);

parse_str($query);

?>

<h2>Update Record </h2>

<form action="" method="post">

<?php

while ($row = $result->fetch_assoc()) {?>

<table border="0" cellspacing="10">

<tr>

<td>Page NO:</td> <td> <input type="text" name="page_no" value=""></td>

</tr>

<tr>

<td>Data:</td> <td><textarea name="data" rows="50" cols="50"><?php echo $row['data']; ?></textarea></td>

</tr>

<?php }

?>

<tr>

<td><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"></td>

</tr>

</table>



</form>



<?php

if($update){//if the update worked

echo "Update successful!";

}

?>



</body>

</html>
</code>

I did got it working where it was able to update the table contant of data column, but as i wanted to add select page option and did some change, it all screwed up
<


not i can see anything not even the table or text.

please help me out
<


thank you for reading the thread.

have a nice day / night ahead.
 
Could it be typos in the SQL query string which I see " [font=helvetica, arial, sans-serif] cms_contet " instead of " [/font][font=helvetica, arial, sans-serif] cms_content " (missing N). ?[/font]
 
tongu23e.gif
my bad
sad.gif
yes it was that n missing but still i am getting this error message

Code:
[b]Notice[/b]: Undefined variable: page_no in [b]C:\xampp\htdocs\myweb\update.php[/b] on line [b]35[/b]

[b]	Update Record[/b]

	 

[b]Notice[/b]: Undefined variable: update in [b]C:\xampp\htdocs\myweb\update.php[/b] on line [b]62[/b]

now i am able to see the update the record button but still table and form inside it is missing
sad.gif
 
tongu23e.gif
my bad
sad.gif
yes it was that n missing but still i am getting this error message

Code:
[b]Notice[/b]: Undefined variable: page_no in [b]C:\xampp\htdocs\myweb\update.php[/b] on line [b]35[/b]

[b]	Update Record[/b]
[b]Notice[/b]: Undefined variable: update in [b]C:\xampp\htdocs\myweb\update.php[/b] on line [b]62[/b]

now i am able to see the update the record button but still table and form inside it is missing
sad.gif

You have to change the update query i think.

old: $update = "UPDATE cms_content SET data='$data' WHERE cms_content page_no = '$page_no'";

new: $update = "UPDATE cms_content SET data='$data' WHERE cms_content.page_no = '$page_no'";
 
Back
Top