Jump to content

Php And Mysql


EmperorZenos
 Share

Recommended Posts

I'm trying to make a page that displays a row's name and content (in which the data is taken from a MySQL) and use UPDATE the same rows using a POST method to a different page. The content is shown within an if function that gets which mode the user is currently in. I will spare the outer parts of the page, but there is a good safe connection. I know this because in another mode, it displays information from the MySQL database perfectly.The following is the content of the page, with a part omitted. (Password.)

if ($mode == "E") {$pass = $_GET['pass'];$id = $_GET['id'];if ($pass="") {$sql_list = "SELECT * FROM ZAX WHERE ID=$id";$id=$row['ID'];$title=$row['Name'];$content=$row['Content'];$result_list = mysql_query($sql_list);?><h1>Currently Editing: <?php echo $row['Name']; ?></h1><hr /><?php echo $id;?><hr /><form action="editZAX.php" method="post"><textarea name="updc" cols="99" rows="30"><?php echo $row['Content']; ?></textarea><input type="submit" name="croker" /></form><br /><?php}else{echo 'Invalid password';}}

Also, "editZAX"'s code, some things omitted too;

<?php$sqlloc="";$sqlname="";$sqlpass="";$sqlcon=mysql_connect($sqlloc,$sqlname,$sqlpass);mysql_select_db("a8949742_sm");$sql_list = "SELECT * FROM `ZAX` WHERE ID=$id";$id=$row['ID'];$title=$row['Name'];$content=$row['Content'];$result_list = mysql_query($sql_list);if ($_POST['croker']) {$updc = $_POST['updc'];$sql = "UPDATE ZAXSET Content = '$updc'WHERE ID = '$id'";mysql_query($sql) or die ('Error: ' . mysql_error());echo 'Content Updated. View the changes <a href="ZAX.php?zax=' . $row['Name'] . '">here</a>.<br />To be redirected to the ACP, click <a href="acp.php?passfield=p3tri0z&logbtn=Submit+Query">here</a>.<br />To be redirected to the Main Site, click <a href="default.php">here</a>.';$file_name = "adminlog.txt";$time = date("d/m/Y h:i A" ,time());$ip = $_SERVER['REMOTE_ADDR'];$fp = fopen($file_name, "a");fwrite($fp, "IP: ".$ip." - Access: ".$time." Updated " . $row['Name'] . " \n");fclose($fp);}?>

The data from the MySQL database is not showing, and I can't spot anything wrong.

Edited by EmperorZenos
Link to comment
Share on other sites

In the first piece of code you're never actually running the query. In the second piece of code you don't have any value for $id for the query, and it looks like you're trying to get information from the rows before you've ran the query. You're also not checking for MySQL errors anywhere. You should check for errors and print the error messages from MySQL.

Link to comment
Share on other sites

In the first piece of code you're never actually running the query. In the second piece of code you don't have any value for $id for the query, and it looks like you're trying to get information from the rows before you've ran the query. You're also not checking for MySQL errors anywhere. You should check for errors and print the error messages from MySQL.
I fixed the first code. You probably were right, I declared $row as a variable and did in a fashion as such:
<?phpif ($_POST['croker']) {	$sqlloc="";	$sqlname="";	$sqlpass="";	$sqlcon=mysql_connect($sqlloc,$sqlname,$sqlpass);	mysql_select_db("a8949742_sm");	$id = $_POST['id'];	$sql_list = "SELECT * FROM ZAX WHERE ID=$id";	$result_list = mysql_query($sql_list);	$row = mysql_fetch_array($result_list);	$title=$row['Name'];	$content=$row['Content'];	$result_list = mysql_query($sql_list);	$updc = $_POST['updc'];	$sql = "UPDATE ZAX	SET Content = '$updc'	WHERE ID = '$id'";	mysql_query($sql) or die ('Error: ' . mysql_error());	echo $id . '<br />';	echo 'Content Updated. View the changes <a href="ZAX.php?zax=' . $row['Name'] . '">here</a>.<br />	To be redirected to the ACP, click <a href="acp.php?passfield=p3tri0z&logbtn=Submit+Query">here</a>.<br />	To be redirected to the Main Site, click <a href="default.php">here</a>.';	$file_name = "adminlog.txt";	$time = date("d/m/Y h:i A" ,time());	$ip = $_SERVER['REMOTE_ADDR'];	$fp = fopen($file_name, "a");	fwrite($fp, "IP: ".$ip." - Access: ".$time." Updated " . $row['Name'] . " \n");	fclose($fp);}?>

This page is in a $_POST method, I added an input field who's Update:As I was typing this message, I caught an error made by myself. The input field I added used a wrong attribute. Instead of name='id' I used id='id' which I promptly fix. But thanks for all of your help and attention.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...