Jump to content

[SOLVED] html instead of header?


contra10

Recommended Posts

could this code be possible?

 

<?php

echo "$recievingid";
if (isset($_POST['checkbox']) and ($_POST['delete'])) { 

$checkboxid = mysql_real_escape_string($_POST['checkbox']);	
mysql_query("DELETE FROM inbox WHERE iid='$checkboxid'");
?>
<meta HTTP-EQUIV="REFRESH" content="0; url=<?php
if(is_numeric($_GET['user'])){

$id = $_GET['user'];
}

mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error());

$fr= "SELECT `recid` FROM `inbox` WHERE `recid` = '$id'";
$fri = mysql_query($fr) or die(mysql_error());

while($frie = mysql_fetch_array($fri)) 
{ 
$rep="{$frie['recid']}"; 
}
echo "http://localhost/inbox/index.php?user=$recievingid";?>">
<?php
}


?>

 

im trying to use php but i can't echo the value in the header...however if i input the actual userid then it works and if i echo $recievingid above the code i can see the value...just doesn't work in the url...trying it without header location...everything echoes correctly in the url except the variable doesn't show

 

i tried it with

echo "http://localhost/inbox/index.php?user=$rep";?>">

as well

Link to comment
Share on other sites

^ If you dont know the answer dont say there isnt one. (lol thought it was a random poster)

 

To the answer;

I don't know why but i cringe when i see inline php/html, use this (easier and better):

 

<?php

// Post Edit: Might want to connect to mysql, you MUST be conected to mysql before you call mysql_escape_String or mysql_real_escape_String.
$ch = mysql_connect("localhost","root","");

// If there is a form being submitted?
if(isset($_POST['checkbox']) && isset($_POST['delete'])){

// Santize this client input?
$checkboxid = mysql_real_escape_string($_POST['checkbox']);

// Execute and store the mysql result resource
$result = mysql_query("DELETE FROM `inbox` WHERE `iid`='".$checkboxid."'") or die(mysql_error());

// Sanity Check? (Sanity check basicall means check if the values are what the should be).
if(is_numeric($_GET['user'])){
	$id = $_GET['user'];
}else{
	// Error? Default user id?
}

// Select he mysql db. is this needed? u should only need one database.
mysql_select_db("registration") or die(mysql_error());

// Execute the mysql query and store the result resource
$result = mysql_query("SELECT `recid` FROM `inbox` WHERE `recid` = '".$id."'") or die(mysql_error());

// Loop each result row
while($row = mysql_fetch_array($result,MYSQL_BOTH)){
	$rep = $row['recid'];
}

// Create the URL string
$url = "http://localhost/inbox/index.php?user=".$recievingid; // Should this be $rep ?????

// Finall Echo the meta tag
echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">');

?>

 

MAKE SURE you take note of all my comments in the code, and all the subtle/little changes i made to your code, it should be easier to read/understand and cleaner looking, if you can code this way you should have much less trouble.

 

Sanitize/Sanity Check = To cleanse or "make safe" an outside variable or foreign data.

Inline php/html = Where you keep breaking in and out of php: <?php echo("<ht"); ?>ml>

---

 

Hope this helps,

Link to comment
Share on other sites

i thought that was going to work...looked perfect...it still doesn't echo the id number i checked to see if my mysql was connect in regards to tables and rows and they are fine

 

heres my full form code the updated code, sry for length

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="1" width="600" align="left">
<tr><td height="20" width="10%" align="center">Delete</td>
<td>Messages</td></tr>
<br>
<br>
<br>
<br>
<?php
		mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error());

if(is_numeric($_GET['user'])){

$id = $_GET['user'];
}


 $friendq= "SELECT * FROM inbox WHERE recid = '$id' ORDER BY iid DESC";
$friendnames = mysql_query($friendq) or die(mysql_error());

while($friend = mysql_fetch_array($friendnames)) 
{ 
$friendid= "{$friend['sendid']}";
$friendusername= "{$friend['recusername']}";
	$sendingusername= "{$friend['sendusername']}";
$date= "{$friend['date']}";
$title= "{$friend['title']}";
	$msgid= "{$friend['iid']}";
 	$colorvalue= "{$friend['value']}"; 
$recievingid="{$friend['recid']}"; 

$bgcc=1;

	echo "<tr>";
	echo"<td><Input type = 'Checkbox' Name ='checkbox' value ='$msgid'></td>";
 echo "<td align='left' width='10%' height='50'>";
echo"<a href ='http://localhost/profile/index.php?user=$friendid' ><img src='http://localhost/image/imagereplace.php?id=$friendid'></a>";
  echo "</td>";
	if ($bgcc == $colorvalue){
	echo"<td width= '90%' align='center' bgcolor='#DEDAD7'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}else{
		echo"<td width= '90%' align='center' bgcolor='black'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}
	echo"<FONT FACE='ariel' SIZE='3' color='#0094f7'><b>$title<br><br></font></td></tr>";
	echo "<tr><td></td><td></td>";
	echo "<td align='right' bgcolor='#DEDAD7'><FONT FACE='ariel' SIZE='2' color='#0094f7'>Sent by <b>$sendingusername</b> on $date</font></a></td>";
echo "</tr>";
}

?>
<?php

// Post Edit: Might want to connect to mysql, you MUST be conected to mysql before you call mysql_escape_String or mysql_real_escape_String.
$ch = mysql_connect("localhost","root","");

// If there is a form being submitted?
if(isset($_POST['checkbox']) && isset($_POST['delete'])){

// Santize this client input?
$checkboxid = mysql_real_escape_string($_POST['checkbox']);

// Execute and store the mysql result resource
$result = mysql_query("DELETE FROM `inbox` WHERE `iid`='".$checkboxid."'") or die(mysql_error());

// Sanity Check? (Sanity check basicall means check if the values are what the should be).
if(is_numeric($_GET['user'])){
	$id = $_GET['user'];
}else{
	echo "no id";
}

// Select he mysql db. is this needed? u should only need one database.
mysql_select_db("registration") or die(mysql_error());

// Execute the mysql query and store the result resource
$result = mysql_query("SELECT `recid` FROM `inbox` WHERE `recid` = '".$id."'") or die(mysql_error());

// Loop each result row
while($row = mysql_fetch_array($result,MYSQL_BOTH)){
	$rep = $row['recid'];
}

// Create the URL string
$url = "http://localhost/inbox/index.php?user=".$rep; 

// Finall Echo the meta tag
echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">');
}
?>
<input type="submit" name="delete" value="delete">
</table>
</form>

Link to comment
Share on other sites

Your going to have to debug your code, it is quite simple and can be done relatively fast.

 

My best way of debuggig is outputting variables during the script execution, to make sure they are what they should be, and to make sure everything is normal, i do this with every script.

 

The first step in debugging is to trace the fault;

 

put a print_r on the while loop:

 

<?php

   // Loop each result row
   while($row = mysql_fetch_array($result,MYSQL_BOTH)){
      echo("<hr>DEBUG: "); print_r($row); // debug
      $rep = $row['recid'];
   }

?>

 

Look at the Source code of the output html, you should see the DEBUG: text followed by a representation of the array that is $row.

 

if you do not see DEBUG, then most likely the query has failed or returned no results, you can use mysql_num_rows($result); to check how many rows were returned by the query.

 

--

1 little tip; you only ever need to connect to mysql once in your script, unless you are connecting to different mysql servers with different usernames etc and you *have* to use mysql_close(). if you have 1 databse, you only need to connect, and select db, once :).

 

POST EDIT: Also, echoing the query ad putting it into phpmyadmin is always a good way to make sure the query should return results or not.

Link to comment
Share on other sites

Ok so progress :P, now you have the problem with the id, so you would use print_r on the $_GET variable:

 

print_r($_GET);

 

Then you get more information and you may have to go further.

 

BTW, remember _GET variables are passed via the URL, eg: http://localhost/?user=1234

and _POST variables are sent via a form.

 

Keep tracing the problem, skills like this will help you to no end in the future.

Link to comment
Share on other sites

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.