A little help debugging some small code (Php)

SpaceshipSpaceship
NamecheapNamecheap
Namecheap AuctionsNamecheap Auctions
Watch

edmarriner

Established Member
Impact
4
hi,

Just a simple bit of code but its a bit mucked up.
Im just getting a blank page - no errors.

PHP:
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body bgcolor="#00FF00">
<?php
$username="root";
$password="********";
$database="msn";

$firstn=$_POST['first'];
$lastn=$_POST['last'];
$msn=$_POST['msn'];
$class=$_POST['class'];

if($do == "insert"{

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO `addys` (`firstn`, `lastn`, `msn`, `class`) VALUES ('$firstn', '$lastn', '$email', '$class')";

$result=mysql_query($query);
if(!$result){
echo"error, data nt submitted";
}
mysql_close();
}elseif($do == "form"){
echo"<table width='100%' border='0' cellpadding='0' cellspacing='0'>
  <tr>
    <td><form id='form1' name='form1' method='post' action='index.php?do=insert'>

      <div align='right'>: first name : </div>
      <label>
      <div align='right'>
        <input type='text' name='firstn' />
      </div>
      </label>
      <div align='right'><br />
        : last name : </div>
      <label>
      <div align='right'>
        <input type='text' name='lastn' />
      </div>
      </label>
      <div align='right'><br />
        : msn address : </div>
      <label>
      <div align='right'>
        <input type='text' name='msn' />
      </div>
      </label>
      <div align='right'><br />
        : class  : </div>
      <label>
      <div align='right'>
        <input type='text' name='class' />
      </div>
      </label>
      <p align='right'>
        <label>
        <input type='submit' name='Submit' value='Submit' />
        </label>
      </p>
    </form></td>
  </tr>
</table>";
}else{

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM msn";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$firstname=mysql_result($result,$i,"first");
$lastname=mysql_result($result,$i,"last");
$email=mysql_result($result,$i,"msn");
$classname=mysql_result($result,$i,"class");

echo "<b>$firstname $lastname</b><br>addy: $msn<br>class: $classname<br><hr><br>";

$i++;
}
}
?></body>
</html>

Can anyone help?


cheers,

-ed
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
For starters, I'd say you need to fix:
if($do == "insert"{

Make it:
if($do == "insert"){

I would hazard a guess and say that you should have been getting errors... maybe error reporting is turned off?
 
1
Close
Hi,

Cheers TwistMyArm, i didnt see that , its all working now :)

thanks,

added rep;

-ed
 
0
Close
--

Could i ask for a little more help please with this search code

PHP:
if($searchresults){
				mysql_connect(localhost,$username,$password);
				@mysql_select_db($database) or die( "Unable to select database");
				$term = $_POST['term'];
				$search_term_esc = AddSlashes($term); 
			$query = "SELECT * FROM addys WHERE firstn, lastn, msn, class LIKE '%$search_term_esc%'";
				$result=mysql_query($query);
				
				$num=mysql_numrows($result);
				
				mysql_close();
				
				echo "<b><center>Search Results</center></b><br><br>";
				
				$i=0;
				while ($i < $num) {
				
				$one=mysql_result($result,$i,"firstn");
				$two=mysql_result($result,$i,"lastn");
				$three=mysql_result($result,$i,"msn");
				$four=mysql_result($result,$i,"class");
				
				echo "<b>$one $two</b><br>addy: $three<br>school: $four<br><hr><br>";
				
				$i++;
				echo"1";
				}
	}else{
	echo"<form id='form1' name='form1' method='post' action='index.php?do=search'>
  <label>
  <input type='text' name='term' />
  </label>
  <label>
  <input type='submit' name='searchresults' value='search' />
  </label>
</form>";
}
///////////////////////////////////////////////////////////////////////////////////////////////
}elseif($do .............

its not returning any results :td:

any ideas?

thanks,

-ed
 
0
Close
You need a query like this:
$query = "SELECT * FROM addys
WHERE firstn LIKE '%$search_term_esc%'
OR lastn LIKE '%$search_term_esc%'
OR msn LIKE '%$search_term_esc%'
OR class LIKE '%$search_term_esc%'
 
1
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back